Spaces:
Paused
Paused
Fix upstream delta text parsing
Browse files- response_cache.py +1 -0
- upstream.py +9 -2
response_cache.py
CHANGED
|
@@ -258,6 +258,7 @@ class InFlightRegistry:
|
|
| 258 |
future = self._futures.pop(key, None)
|
| 259 |
if future is not None and not future.done():
|
| 260 |
future.set_exception(exc)
|
|
|
|
| 261 |
|
| 262 |
|
| 263 |
class ResponseCacheService:
|
|
|
|
| 258 |
future = self._futures.pop(key, None)
|
| 259 |
if future is not None and not future.done():
|
| 260 |
future.set_exception(exc)
|
| 261 |
+
future.add_done_callback(lambda f: f.exception())
|
| 262 |
|
| 263 |
|
| 264 |
class ResponseCacheService:
|
upstream.py
CHANGED
|
@@ -127,8 +127,15 @@ async def iter_upstream_events(payload: dict) -> AsyncIterator[tuple[str, dict]]
|
|
| 127 |
skipped_lines += 1
|
| 128 |
continue
|
| 129 |
if t == "delta" and "text" in obj and "index" not in obj:
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
event_counts[t] = event_counts.get(t, 0) + 1
|
| 133 |
yield (t, obj)
|
| 134 |
|
|
|
|
| 127 |
skipped_lines += 1
|
| 128 |
continue
|
| 129 |
if t == "delta" and "text" in obj and "index" not in obj:
|
| 130 |
+
obj = {
|
| 131 |
+
"type": "content_block_delta",
|
| 132 |
+
"index": 0,
|
| 133 |
+
"delta": {"type": "text_delta", "text": obj.get("text", "")},
|
| 134 |
+
}
|
| 135 |
+
t = "content_block_delta"
|
| 136 |
+
if t == "error":
|
| 137 |
+
yield ("error", {"status_code": 502, "body": obj.get("message") or json.dumps(obj, ensure_ascii=False)})
|
| 138 |
+
return
|
| 139 |
event_counts[t] = event_counts.get(t, 0) + 1
|
| 140 |
yield (t, obj)
|
| 141 |
|