Update app.py
Browse files
app.py
CHANGED
@@ -174,34 +174,38 @@ def openai_chat_avatar(text_prompt):
|
|
174 |
|
175 |
def ryzedb_chat_avatar(question, app_id):
|
176 |
url = "https://inference.dev.ryzeai.ai/v2/chat/stream"
|
177 |
-
|
178 |
-
#
|
179 |
-
|
|
|
180 |
"input": {
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
},
|
185 |
"config": {
|
186 |
"thread_id": "123456"
|
187 |
-
}
|
|
|
188 |
headers = {
|
189 |
'Content-Type': 'application/json'
|
190 |
}
|
191 |
-
|
192 |
try:
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
response.raise_for_status()
|
198 |
-
|
199 |
-
# Return the response JSON
|
200 |
-
return response.text
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
|
206 |
|
207 |
def custom_cleanup(temp_dir, exclude_dir):
|
|
|
174 |
|
175 |
def ryzedb_chat_avatar(question, app_id):
|
176 |
url = "https://inference.dev.ryzeai.ai/v2/chat/stream"
|
177 |
+
print("ryze db question",question)
|
178 |
+
# thread_id = str(random.randint(1000, 99999))
|
179 |
+
# print("Generated thread_id:", thread_id)
|
180 |
+
payload = {
|
181 |
"input": {
|
182 |
+
"app_id": app_id,
|
183 |
+
"query": question,
|
184 |
+
"chat_history": []
|
185 |
},
|
186 |
"config": {
|
187 |
"thread_id": "123456"
|
188 |
+
}}
|
189 |
+
|
190 |
headers = {
|
191 |
'Content-Type': 'application/json'
|
192 |
}
|
193 |
+
response = requests.post(url, json=payload, headers=headers, stream=True)
|
194 |
try:
|
195 |
+
raw_text = response.text.strip()
|
196 |
+
|
197 |
+
if raw_text.startswith("data:"):
|
198 |
+
raw_text = raw_text[len("data:"):].strip()
|
|
|
|
|
|
|
|
|
199 |
|
200 |
+
json_data = json.loads(raw_text)
|
201 |
+
|
202 |
+
response = json_data.get("content", "")
|
203 |
+
return response
|
204 |
+
|
205 |
+
except Exception as e:
|
206 |
+
print("Error parsing response:", e)
|
207 |
+
return ""
|
208 |
+
|
209 |
|
210 |
|
211 |
def custom_cleanup(temp_dir, exclude_dir):
|