Update app.py
Browse files
app.py
CHANGED
@@ -233,31 +233,50 @@ def ask_llama(conversation_history, category, is_final_guess=False):
|
|
233 |
return "Could not generate question"
|
234 |
|
235 |
# New function for the help AI assistant using the Hugging Face InferenceClient
|
236 |
-
|
237 |
def ask_help_agent(query):
|
238 |
try:
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
|
|
246 |
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
|
|
253 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
254 |
if response.status_code == 200:
|
255 |
-
|
|
|
256 |
else:
|
257 |
-
return f"Error: {response.text}"
|
258 |
-
|
259 |
except Exception as e:
|
260 |
-
return f"
|
|
|
261 |
|
262 |
# Main game logic with enhanced UI
|
263 |
def main():
|
|
|
233 |
return "Could not generate question"
|
234 |
|
235 |
# New function for the help AI assistant using the Hugging Face InferenceClient
|
236 |
+
MISTRAL_API_KEY = "wm5eLl09b9I9cOxR3E9n5rrRr1CRQQjn"
|
237 |
def ask_help_agent(query):
|
238 |
try:
|
239 |
+
# Prepare Mistral API request
|
240 |
+
url = "https://api.mistral.ai/v1/chat/completions"
|
241 |
+
headers = {
|
242 |
+
"Authorization": f"Bearer {MISTRAL_API_KEY}",
|
243 |
+
"Content-Type": "application/json"
|
244 |
+
}
|
245 |
+
|
246 |
+
system_message = "You are a friendly Chatbot."
|
247 |
|
248 |
+
# Build message history
|
249 |
+
messages = [{"role": "system", "content": system_message}]
|
250 |
+
if "help_conversation" in st.session_state:
|
251 |
+
for msg in st.session_state.help_conversation:
|
252 |
+
if msg.get("query"):
|
253 |
+
messages.append({"role": "user", "content": msg["query"]})
|
254 |
+
if msg.get("response"):
|
255 |
+
messages.append({"role": "assistant", "content": msg["response"]})
|
256 |
|
257 |
+
# Add current user query
|
258 |
+
messages.append({"role": "user", "content": query})
|
259 |
+
|
260 |
+
# API payload
|
261 |
+
payload = {
|
262 |
+
"model": "mistral-tiny",
|
263 |
+
"messages": messages,
|
264 |
+
"temperature": 0.7,
|
265 |
+
"top_p": 0.95
|
266 |
+
}
|
267 |
+
|
268 |
+
# Send POST request
|
269 |
+
response = requests.post(url, headers=headers, json=payload)
|
270 |
+
|
271 |
if response.status_code == 200:
|
272 |
+
result = response.json()
|
273 |
+
return result["choices"][0]["message"]["content"]
|
274 |
else:
|
275 |
+
return f"API Error {response.status_code}: {response.text}"
|
276 |
+
|
277 |
except Exception as e:
|
278 |
+
return f"Error in help agent: {str(e)}"
|
279 |
+
|
280 |
|
281 |
# Main game logic with enhanced UI
|
282 |
def main():
|