Skip to content
Snippets Groups Projects
Unverified Commit 2ba13544 authored by Andrei Fajardo's avatar Andrei Fajardo Committed by GitHub
Browse files

FIX - Streaming generators get consumed by SynthesisEndEvent (#12092)

* define __post_init_post_parse__ in PydanticResponse

* bring back test

* skip tests
parent 85f9070a
No related branches found
No related tags found
No related merge requests found
......@@ -66,6 +66,24 @@ class PydanticResponse:
else:
return None
def __post_init_post_parse__(self) -> None:
"""This method is required.
According to the Pydantic docs, if a stdlib dataclass (which this class
is one) gets mixed with a BaseModel (in the sense that this gets used as a
Field in another BaseModel), then this stdlib dataclass will automatically
get converted to a pydantic.v1.dataclass.
However, it appears that in that automatic conversion, this method
is left as NoneType, which raises an error. To safeguard against that,
we are expilcitly defining this method as something that can be called.
Sources:
- https://docs.pydantic.dev/1.10/usage/dataclasses/#use-of-stdlib-dataclasses-with-basemodel
- https://docs.pydantic.dev/1.10/usage/dataclasses/#initialize-hooks
"""
return
def get_formatted_sources(self, length: int = 100) -> str:
"""Get formatted sources text."""
texts = []
......
from llama_index.core.instrumentation.events.base import BaseEvent
from llama_index.core.base.response.schema import RESPONSE_TYPE
from llama_index.core.schema import QueryType
......@@ -13,7 +14,7 @@ class SynthesizeStartEvent(BaseEvent):
class SynthesizeEndEvent(BaseEvent):
query: QueryType
response: str
response: RESPONSE_TYPE
@classmethod
def class_name(cls):
......
......@@ -209,13 +209,13 @@ class BaseSynthesizer(ChainableMixin, PromptMixin):
response_gen=empty_response_generator()
)
dispatcher.event(
SynthesizeEndEvent(query=query, response=str(empty_response))
SynthesizeEndEvent(query=query, response=empty_response)
)
return empty_response
else:
empty_response = Response("Empty Response")
dispatcher.event(
SynthesizeEndEvent(query=query, response=str(empty_response))
SynthesizeEndEvent(query=query, response=empty_response)
)
return empty_response
......@@ -240,7 +240,7 @@ class BaseSynthesizer(ChainableMixin, PromptMixin):
event.on_end(payload={EventPayload.RESPONSE: response})
dispatcher.event(SynthesizeEndEvent(query=query, response=str(response)))
dispatcher.event(SynthesizeEndEvent(query=query, response=response))
return response
@dispatcher.span
......@@ -258,13 +258,13 @@ class BaseSynthesizer(ChainableMixin, PromptMixin):
response_gen=empty_response_agenerator()
)
dispatcher.event(
SynthesizeEndEvent(query=query, response=str(empty_response))
SynthesizeEndEvent(query=query, response=empty_response)
)
return empty_response
else:
empty_response = Response("Empty Response")
dispatcher.event(
SynthesizeEndEvent(query=query, response=str(empty_response))
SynthesizeEndEvent(query=query, response=empty_response)
)
return empty_response
......@@ -289,7 +289,7 @@ class BaseSynthesizer(ChainableMixin, PromptMixin):
event.on_end(payload={EventPayload.RESPONSE: response})
dispatcher.event(SynthesizeEndEvent(query=query, response=str(response)))
dispatcher.event(SynthesizeEndEvent(query=query, response=response))
return response
def _as_query_component(self, **kwargs: Any) -> QueryComponent:
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment