agentscope.models.response module

Parser for model response.

class agentscope.models.response.ModelResponse(text: str | None = None, embedding: Sequence | None = None, image_urls: Sequence[str] | None = None, raw: Any | None = None, parsed: Any | None = None, stream: Generator[str, None, None] | None = None)[source]

Bases: object

Encapsulation of data returned by the model.

The main purpose of this class is to align the return formats of different models and act as a bridge between models and agents.

__init__(text: str | None = None, embedding: Sequence | None = None, image_urls: Sequence[str] | None = None, raw: Any | None = None, parsed: Any | None = None, stream: Generator[str, None, None] | None = None) None[source]

Initialize the model response.

Parameters:
  • text (str, optional) – The text field.

  • embedding (Sequence, optional) – The embedding returned by the model.

  • image_urls (Sequence[str], optional) – The image URLs returned by the model.

  • raw (Any, optional) – The raw data returned by the model.

  • parsed (Any, optional) – The parsed data returned by the model.

  • stream (Generator, optional) – The stream data returned by the model.

property text: str

Return the text field. If the stream field is available, the text field will be updated accordingly.

property stream: None | Generator[Tuple[bool, str], None, None]

Return the stream generator if it exists.

property is_stream_exhausted: bool

Whether the stream has been processed already.