Skip to content

Commit 0c4f4d2

Browse files
authored
handle stream errors (#63)
* handle stream errors * adjust tests * update version
1 parent 99267c8 commit 0c4f4d2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "weaviate-agents"
3-
version = "0.12.0"
3+
version = "0.12.1"
44
description = "The official sub-package for the Weaviate Agents project."
55
readme = "README.md"
66
requires-python = ">=3.9"

test/query_agent/test_query_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ async def test_async_run_success(monkeypatch):
370370

371371

372372
class MockIterSSESuccess:
373+
response = FakeResponse(200, {})
374+
373375
def iter_sse(self):
374376
yield ServerSentEvent(
375377
event="progress_message",
@@ -514,6 +516,8 @@ async def test_async_run_failure(monkeypatch):
514516

515517

516518
class MockIterSSEFailure:
519+
response = FakeResponse(200, {})
520+
517521
def iter_sse(self):
518522
yield ServerSentEvent(
519523
event="progress_message",

weaviate_agents/query/query_agent.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def stream(
287287
headers=self._headers,
288288
timeout=self._timeout,
289289
) as events:
290+
if events.response.is_error:
291+
events.response.read()
292+
raise Exception(events.response.text)
293+
290294
for sse in events.iter_sse():
291295
output = _parse_sse(sse)
292296
if isinstance(output, ProgressMessage):
@@ -403,6 +407,10 @@ async def stream(
403407
headers=self._headers,
404408
timeout=self._timeout,
405409
) as events:
410+
if events.response.is_error:
411+
events.response.read()
412+
raise Exception(events.response.text)
413+
406414
async for sse in events.aiter_sse():
407415
output = _parse_sse(sse)
408416
if isinstance(output, ProgressMessage):

0 commit comments

Comments
 (0)