Upload agent.py

#421
by kpalatel - opened
Files changed (1) hide show
  1. agent.py +29 -0
agent.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # Load token from Hugging Face Space Secrets
5
+ HF_TOKEN = os.getenv("HF_TOKEN")
6
+
7
+ if not HF_TOKEN:
8
+ raise ValueError("HF_TOKEN is missing in Space Secrets")
9
+
10
+ # Direct inference client (NO router, NO provider)
11
+ client = InferenceClient(
12
+ model="Qwen/Qwen2.5-7B-Instruct",
13
+ token=HF_TOKEN
14
+ )
15
+
16
+
17
+ def agent(query: str) -> str:
18
+ """
19
+ Simple stable agent function (no smolagents, no wrappers).
20
+ """
21
+ response = client.chat_completion(
22
+ messages=[
23
+ {"role": "user", "content": query}
24
+ ],
25
+ max_tokens=512,
26
+ temperature=0.1
27
+ )
28
+
29
+ return response.choices[0].message.content