olcapone commited on
Commit
dc6d7f6
·
verified ·
1 Parent(s): 86f7dae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -46,14 +46,26 @@ class BasicAgent:
46
 
47
  # single LLM call; enforce bare answer
48
  def _llm(self, prompt: str) -> str:
 
49
  if self.cfg["provider"] == "hf":
50
- out = self.hf.text_generation(
51
- model=self.cfg["model"],
52
- prompt=prompt,
53
- max_new_tokens=128,
54
- temperature=0.2,
55
- )
56
- return out.strip()
 
 
 
 
 
 
 
 
 
 
 
57
  # Groq (chat.completions)
58
  res = requests.post(
59
  "https://api.groq.com/openai/v1/chat/completions",
 
46
 
47
  # single LLM call; enforce bare answer
48
  def _llm(self, prompt: str) -> str:
49
+ model = self.cfg["model"]
50
  if self.cfg["provider"] == "hf":
51
+ try:
52
+ # Try text-generation first
53
+ out = self.client.text_generation(
54
+ model=model, prompt=prompt, max_new_tokens=128, temperature=0.2
55
+ )
56
+ return out.strip()
57
+ except Exception as e:
58
+ # If the backend says “Supported task: conversational”, retry with chat
59
+ if "supported task: conversational" in str(e).lower():
60
+ chat = self.client.chat_completion(
61
+ model=model,
62
+ messages=[{"role": "user", "content": prompt}],
63
+ max_tokens=128,
64
+ temperature=0.2,
65
+ )
66
+ return chat.choices[0].message["content"].strip()
67
+ raise
68
+
69
  # Groq (chat.completions)
70
  res = requests.post(
71
  "https://api.groq.com/openai/v1/chat/completions",