kpalatel's picture
Create agent.py
b2d0e90 verified
Raw
History Blame
677 Bytes
import os
from huggingface_hub import InferenceClient
# Load token from Hugging Face Space Secrets
HF_TOKEN = os.getenv("HF_TOKEN")
if not HF_TOKEN:
raise ValueError("HF_TOKEN is missing in Space Secrets")
# Direct inference client (NO router, NO provider)
client = InferenceClient(
model="Qwen/Qwen2.5-7B-Instruct",
token=HF_TOKEN
)
def agent(query: str) -> str:
"""
Simple stable agent function (no smolagents, no wrappers).
"""
response = client.chat_completion(
messages=[
{"role": "user", "content": query}
],
max_tokens=512,
temperature=0.1
)
return response.choices[0].message.content