Skip to content

Commit

Permalink
error_type: propagate it to the sse (#24)
Browse files Browse the repository at this point in the history
Co-authored-by: Brendan Graham <[email protected]>
  • Loading branch information
BrendanGraham14 and BrendanGraham14 authored Sep 28, 2023
1 parent 6accef6 commit 4e88577
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/fastapi_poe/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,16 @@ def meta_event(

@staticmethod
def error_event(
text: Optional[str] = None, *, allow_retry: bool = True
text: Optional[str] = None,
*,
allow_retry: bool = True,
error_type: Optional[str] = None,
) -> ServerSentEvent:
data: Dict[str, Union[bool, str]] = {"allow_retry": allow_retry}
if text is not None:
data["text"] = text
if error_type is not None:
data["error_type"] = error_type
return ServerSentEvent(data=json.dumps(data), event="error")

# Internal handlers
Expand All @@ -175,7 +180,11 @@ async def handle_query(self, query: QueryRequest) -> AsyncIterable[ServerSentEve
if isinstance(event, ServerSentEvent):
yield event
elif isinstance(event, ErrorResponse):
yield self.error_event(event.text, allow_retry=event.allow_retry)
yield self.error_event(
event.text,
allow_retry=event.allow_retry,
error_type=event.error_type,
)
elif isinstance(event, MetaResponse):
yield self.meta_event(
content_type=event.content_type,
Expand Down

0 comments on commit 4e88577

Please sign in to comment.