srbhavya01 commited on
Commit
c06dc28
·
verified ·
1 Parent(s): 963ebeb

Update model_api.py

Browse files
Files changed (1) hide show
  1. model_api.py +17 -21
model_api.py CHANGED
@@ -1,25 +1,21 @@
1
  from huggingface_hub import InferenceClient
2
  import os
3
- from dotenv import load_dotenv
4
-
5
- load_dotenv()
6
 
7
  def query_model(prompt):
8
-
9
- HF_TOKEN = os.getenv("HF_TOKEN")
10
-
11
- client = InferenceClient(
12
- model="meta-llama/Llama-3.2-3B-Instruct",
13
- token=HF_TOKEN
14
- )
15
-
16
- response = client.chat_completion(
17
- messages=[
18
- {"role": "system", "content": "You are a professional fitness trainer."},
19
- {"role": "user", "content": prompt}
20
- ],
21
- max_tokens=800,
22
- temperature=0.7
23
- )
24
-
25
- return response.choices[0].message.content
 
1
  from huggingface_hub import InferenceClient
2
  import os
 
 
 
3
 
4
  def query_model(prompt):
5
+ try:
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+ # You can also set provider at the client level
8
+ client = InferenceClient(api_key=HF_TOKEN, provider="auto")
9
+
10
+ response = client.chat.completions.create(
11
+ model="Qwen/Qwen2.5-7B-Instruct",
12
+ messages=[
13
+ {"role": "system", "content": "You are a professional fitness trainer."},
14
+ {"role": "user", "content": prompt}
15
+ ],
16
+ max_tokens=1500,
17
+ temperature=0.7
18
+ )
19
+ return response.choices[0].message.content
20
+ except Exception as e:
21
+ return f"Error: {str(e)}"