Skip to content

Response synthesizer

Defines a base class for response synthesizers used in Gen AI applications.

Authors

Henry Wicaksono (henry.wicaksono@gdplabs.id)

References

NONE

BaseResponseSynthesizer(streamable=True)

Bases: Component, ABC

An abstract base class for the response synthesizers used in Gen AI applications.

The BaseResponseSynthesizer class provides a framework for synthesizing responses based on input queries. Subclasses must implement the synthesize_response method to define how the response is generated.

Attributes:

Name Type Description
streamable bool

A flag to indicate whether the synthesized response will be streamed if an event emitter is provided.

Initializes a new instance of the BaseResponseSynthesizer class.

Parameters:

Name Type Description Default
streamable bool

A flag to indicate whether the synthesized response will be streamed if an event emitter is provided. Defaults to True.

True

synthesize_response(query=None, state_variables=None, history=None, extra_contents=None, attachments=None, hyperparameters=None, event_emitter=None, system_multimodal_contents=None, user_multimodal_contents=None) abstractmethod async

Synthesizes a response based on the provided query.

This abstract method must be implemented by subclasses to define the logic for generating a response. It may optionally take an input query, some other input variables passed through state_variables, and an event_emitter. It returns the synthesized response as a string.

Parameters:

Name Type Description Default
query str | None

The input query used to synthesize the response. Defaults to None.

None
state_variables dict[str, Any] | None

Additional state variables to assist in generating the response. Defaults to None.

None
history list[tuple[PromptRole, str | list[Any]]] | None

The chat history of the conversation to be considered in generating the response. Defaults to None.

None
extra_contents list[MultimodalContent] | None

A list of extra contents to be included when generating the response. Defaults to None.

None
attachments list[Attachment] | None

Deprecated parameter to handle attachments. Will be removed in v0.5.0. Defaults to None.

None
hyperparameters dict[str, Any] | None

The hyperparameters to be passed to the language model. Defaults to None.

None
event_emitter EventEmitter | None

The event emitter for handling events during response synthesis. Defaults to None.

None
system_multimodal_contents list[Any] | None

Deprecated parameter to handle attachments. Will be removed in v0.5.0. Defaults to None.

None
user_multimodal_contents list[Any] | None

Deprecated parameter to handle attachments. Will be removed in v0.5.0. Defaults to None.

None

Returns:

Name Type Description
Any Any

The synthesized response.

Raises:

Type Description
NotImplementedError

If the method is not implemented in a subclass.