Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,7 @@ async def send_chat_message(LLM_URL, LLM_API, category, file_id):
|
|
| 24 |
payload = {
|
| 25 |
"inputs": {},
|
| 26 |
"query": category,
|
| 27 |
-
"response_mode": "
|
| 28 |
"conversation_id": "",
|
| 29 |
"user": USER_ID,
|
| 30 |
"files": [
|
|
@@ -45,26 +45,17 @@ async def send_chat_message(LLM_URL, LLM_API, category, file_id):
|
|
| 45 |
) as response:
|
| 46 |
|
| 47 |
if response.status != 200:
|
| 48 |
-
|
| 49 |
-
return f"Error: Server returned status {response.status}
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
data = json.loads(json_part.decode("utf-8"))
|
| 58 |
-
if data.get("event") == "agent_thought":
|
| 59 |
-
last_thought = data.get("thought")
|
| 60 |
-
except Exception as e:
|
| 61 |
-
print(f"[stream error] {e} line={line}")
|
| 62 |
-
continue
|
| 63 |
-
return last_thought.strip() if last_thought else "Error: No thought found in response"
|
| 64 |
-
except aiohttp.ClientPayloadError as e:
|
| 65 |
-
return f"Error: Incomplete response stream ({str(e)})"
|
| 66 |
except Exception as e:
|
| 67 |
-
return f"Error: Unexpected exception - {
|
| 68 |
|
| 69 |
async def upload_file(LLM_URL, LLM_API, file_path, user_id):
|
| 70 |
if not os.path.exists(file_path):
|
|
|
|
| 24 |
payload = {
|
| 25 |
"inputs": {},
|
| 26 |
"query": category,
|
| 27 |
+
"response_mode": "blocking", # ⬅️ 改這裡
|
| 28 |
"conversation_id": "",
|
| 29 |
"user": USER_ID,
|
| 30 |
"files": [
|
|
|
|
| 45 |
) as response:
|
| 46 |
|
| 47 |
if response.status != 200:
|
| 48 |
+
error_text = await response.text()
|
| 49 |
+
return f"Error: Server returned status {response.status} - {error_text}"
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
data = await response.json()
|
| 53 |
+
return data.get("thought", "Error: No thought in response")
|
| 54 |
+
except Exception as e:
|
| 55 |
+
return f"Error: Failed to parse JSON - {e}"
|
| 56 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
+
return f"Error: Unexpected exception - {e}"
|
| 59 |
|
| 60 |
async def upload_file(LLM_URL, LLM_API, file_path, user_id):
|
| 61 |
if not os.path.exists(file_path):
|