Spaces:
Running
Running
Updated app.py
Browse files
app.py
CHANGED
|
@@ -764,6 +764,9 @@ def build_onyx_payload(messages, model_provider, model_version, temperature, cha
|
|
| 764 |
"include_citations": False
|
| 765 |
}
|
| 766 |
|
|
|
|
|
|
|
|
|
|
| 767 |
return payload
|
| 768 |
|
| 769 |
|
|
@@ -858,6 +861,9 @@ def build_anthropic_payload_from_messages(messages, system_prompt, model_provide
|
|
| 858 |
"include_citations": False
|
| 859 |
}
|
| 860 |
|
|
|
|
|
|
|
|
|
|
| 861 |
return payload
|
| 862 |
|
| 863 |
|
|
@@ -1011,7 +1017,7 @@ def stream_onyx_response(payload, model, session_key, has_tools=False):
|
|
| 1011 |
if msg_id:
|
| 1012 |
last_message_id = msg_id
|
| 1013 |
|
| 1014 |
-
if content and packet_type in ['content', 'legacy', 'raw']:
|
| 1015 |
if has_tools:
|
| 1016 |
# Buffer content for tool call detection
|
| 1017 |
full_content_buffer += content
|
|
@@ -1093,14 +1099,8 @@ def collect_full_response(payload, model, session_key, has_tools=False):
|
|
| 1093 |
|
| 1094 |
if response.status_code != 200:
|
| 1095 |
error_text = response.text
|
| 1096 |
-
print(f"Error response: {error_text}")
|
| 1097 |
-
|
| 1098 |
-
"error": {
|
| 1099 |
-
"message": f"Onyx API error {response.status_code}: {error_text}",
|
| 1100 |
-
"type": "api_error",
|
| 1101 |
-
"code": response.status_code
|
| 1102 |
-
}
|
| 1103 |
-
}, response.status_code
|
| 1104 |
|
| 1105 |
if not is_streaming_request:
|
| 1106 |
try:
|
|
@@ -1401,13 +1401,8 @@ def collect_anthropic_full_response(payload, model, session_key, has_tools=False
|
|
| 1401 |
continue
|
| 1402 |
|
| 1403 |
if response.status_code != 200:
|
| 1404 |
-
|
| 1405 |
-
|
| 1406 |
-
"error": {
|
| 1407 |
-
"type": "api_error",
|
| 1408 |
-
"message": f"Onyx API error {response.status_code}: {response.text}"
|
| 1409 |
-
}
|
| 1410 |
-
}, response.status_code
|
| 1411 |
|
| 1412 |
if not is_streaming_request:
|
| 1413 |
try:
|
|
|
|
| 764 |
"include_citations": False
|
| 765 |
}
|
| 766 |
|
| 767 |
+
# Remove keys with None values — Onyx rejects/errors on null parent_message_id
|
| 768 |
+
payload = {k: v for k, v in payload.items() if v is not None}
|
| 769 |
+
|
| 770 |
return payload
|
| 771 |
|
| 772 |
|
|
|
|
| 861 |
"include_citations": False
|
| 862 |
}
|
| 863 |
|
| 864 |
+
# Remove keys with None values — Onyx rejects/errors on null parent_message_id
|
| 865 |
+
payload = {k: v for k, v in payload.items() if v is not None}
|
| 866 |
+
|
| 867 |
return payload
|
| 868 |
|
| 869 |
|
|
|
|
| 1017 |
if msg_id:
|
| 1018 |
last_message_id = msg_id
|
| 1019 |
|
| 1020 |
+
if content and packet_type in ['content', 'legacy', 'raw', 'error']:
|
| 1021 |
if has_tools:
|
| 1022 |
# Buffer content for tool call detection
|
| 1023 |
full_content_buffer += content
|
|
|
|
| 1099 |
|
| 1100 |
if response.status_code != 200:
|
| 1101 |
error_text = response.text
|
| 1102 |
+
print(f"Error response from {url}: {response.status_code} - {error_text}")
|
| 1103 |
+
continue # Try next endpoint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
|
| 1105 |
if not is_streaming_request:
|
| 1106 |
try:
|
|
|
|
| 1401 |
continue
|
| 1402 |
|
| 1403 |
if response.status_code != 200:
|
| 1404 |
+
print(f"Error response from {url}: {response.status_code} - {response.text}")
|
| 1405 |
+
continue # Try next endpoint
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1406 |
|
| 1407 |
if not is_streaming_request:
|
| 1408 |
try:
|