Spanicin commited on
Commit
89001df
·
verified ·
1 Parent(s): 29ea655

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -19
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
- # question = question + ". Summarize the answer in one line."
178
- # print("question",question)
179
- payload = json.dumps({
 
180
  "input": {
181
- "chat_history": [],
182
- "app_id": app_id,
183
- "question": question
184
  },
185
  "config": {
186
  "thread_id": "123456"
187
- })
 
188
  headers = {
189
  'Content-Type': 'application/json'
190
  }
191
-
192
  try:
193
- # Send the POST request
194
- response = requests.request("POST", url, headers=headers, data=payload)
195
-
196
- # Check for successful request
197
- response.raise_for_status()
198
-
199
- # Return the response JSON
200
- return response.text
201
 
202
- except requests.exceptions.RequestException as e:
203
- print(f"An error occurred: {e}")
204
- return None
 
 
 
 
 
 
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):