Spaces:
Sleeping
Sleeping
Update app.py
Browse files45 unmodified lines464748495051525354555657585945 unmodified lines# single LLM call; enforce bare answerdef _llm(self, prompt: str) -> str:if self.cfg["provider"] == "hf":out = self.hf.text_generation(model=self.cfg["model"],prompt=prompt,max_new_tokens=128,temperature=0.2,)return out.strip()# Groq (chat.completions)res = requests.post("https://api.groq.com/openai/v1/chat/completions",45 unmodified lines464748495051525354555657585960616263646566676869707145 unmodified lines# single LLM call; enforce bare answerdef _llm(self, prompt: str) -> str:model = self.cfg["model"]if self.cfg["provider"] == "hf":try:# Try text-generation firstout = self.client.text_generation(model=model, prompt=prompt, max_new_tokens=128, temperature=0.2)return out.strip()except Exception as e:# If the backend says “Supported task: conversational”, retry with chatif "supported task: conversational" in str(e).lower():chat = self.client.chat_completion(model=model,messages=[{"role": "user", "content": prompt}],max_tokens=128,temperature=0.2,)return chat.choices[0].message["content"].strip()raise# Groq (chat.completions)res = requests.post("https://api.groq.com/openai/v1/chat/completions",
app.py+19-7