Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model = AutoModelForCausalLM.from_pretrained(
6 "SK0988/phi3-hr-assistant",
7 torch_dtype=torch.float16,
8 device_map="auto",
9 trust_remote_code=True
10)
11tokenizer = AutoTokenizer.from_pretrained("SK0988/phi3-hr-assistant")
12
13# Generate HR response
14def ask_hr_question(question):
15 prompt = f'''You are the company's HR Helpdesk assistant. Answer HR policy questions accurately.
16
17### Human:
18{question}
19
20### Assistant:
21'''
22
23 inputs = tokenizer(prompt, return_tensors="pt")
24 with torch.no_grad():
25 outputs = model.generate(
26 **inputs,
27 max_new_tokens=200,
28 do_sample=False,
29 pad_token_id=tokenizer.eos_token_id
30 )
31
32 response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
33 return response.strip()
34
35# Example usage
36question = "What is the leave policy for permanent employees?"
37answer = ask_hr_question(question)
38print(answer)1# Using Hugging Face Inference API
2import requests
3
4API_URL = "https://api-inference.huggingface.co/models/SK0988/phi3-hr-assistant"
5headers = {"Authorization": "Bearer YOUR_HF_TOKEN"}
6
7def query(payload):
8 response = requests.post(API_URL, headers=headers, json=payload)
9 return response.json()
10
11# Ask HR question
12output = query({
13 "inputs": "What is the maternity leave policy?",
14 "parameters": {"max_new_tokens": 200}
15})
16print(output)@misc{phi3-hr-assistant,
title={Phi-3 HR Assistant},
author={SK0988},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/SK0988/phi3-hr-assistant}
}