srbhavya01 commited on
Commit
f12b2b4
·
verified ·
1 Parent(s): 3ce2666

Update model_api.py

Browse files
Files changed (1) hide show
  1. model_api.py +17 -17
model_api.py CHANGED
@@ -1,25 +1,25 @@
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
 
8
- client = InferenceClient(
9
- model="meta-llama/Llama-3.2-3B-Instruct",
10
- token=HF_TOKEN
11
- )
12
 
13
- response = client.chat_completion(
14
- messages=[
15
- {"role": "system", "content": "You are a certified professional fitness trainer."},
16
- {"role": "user", "content": prompt}
17
- ],
18
- max_tokens=2000,
19
- temperature=0.7
20
- )
21
 
22
- return response.choices[0].message.content
 
 
 
 
 
 
 
23
 
24
- except Exception as e:
25
- return f"Error: {str(e)}"
 
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