Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, send_file
|
| 2 |
-
import ollama
|
| 3 |
import json
|
| 4 |
import re
|
| 5 |
from duckduckgo_search import DDGS
|
|
@@ -112,18 +111,25 @@ Return the results in JSON format with no additional text:
|
|
| 112 |
"""
|
| 113 |
|
| 114 |
|
| 115 |
-
def ask_ollama(user_message, model='
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
print(f"AI REPLY json:\n{ai_reply}")
|
| 128 |
|
| 129 |
# Process the response to ensure we return valid JSON
|
|
@@ -131,7 +137,7 @@ def ask_ollama(user_message, model='gemma3:1b', system_prompt=search_prompt):
|
|
| 131 |
# First, try to parse it directly in case it's already valid JSON
|
| 132 |
print(f"AI REPLY:\n{ai_reply}")
|
| 133 |
return ast.literal_eval(ai_reply.replace('json\n', '').replace('```', ''))
|
| 134 |
-
except:
|
| 135 |
print(f"ERROR:\n{e}")
|
| 136 |
# If it's not valid JSON, try to extract JSON from the text
|
| 137 |
return {
|
|
|
|
| 1 |
from flask import Flask, render_template, request, jsonify, send_file
|
|
|
|
| 2 |
import json
|
| 3 |
import re
|
| 4 |
from duckduckgo_search import DDGS
|
|
|
|
| 111 |
"""
|
| 112 |
|
| 113 |
|
| 114 |
+
def ask_ollama(user_message, model='llama-3.3-70b-versatile', system_prompt=search_prompt):
|
| 115 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 116 |
+
|
| 117 |
+
response = client.chat.completions.create(
|
| 118 |
+
model=model,
|
| 119 |
+
messages=[
|
| 120 |
+
{
|
| 121 |
+
"role": "system",
|
| 122 |
+
"content": system_prompt
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"role": "user",
|
| 126 |
+
"content": user_message
|
| 127 |
+
}
|
| 128 |
+
],
|
| 129 |
+
stream=False,
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
ai_reply = response.choices[0].message.content
|
| 133 |
print(f"AI REPLY json:\n{ai_reply}")
|
| 134 |
|
| 135 |
# Process the response to ensure we return valid JSON
|
|
|
|
| 137 |
# First, try to parse it directly in case it's already valid JSON
|
| 138 |
print(f"AI REPLY:\n{ai_reply}")
|
| 139 |
return ast.literal_eval(ai_reply.replace('json\n', '').replace('```', ''))
|
| 140 |
+
except Exception as e:
|
| 141 |
print(f"ERROR:\n{e}")
|
| 142 |
# If it's not valid JSON, try to extract JSON from the text
|
| 143 |
return {
|