agentscope.modelChatResponse
class ChatResponse(DictMixin)
agentscope/model/_model_response.py:32–317聊天模型的响应。位于 agentscope.model 包,继承自 DictMixin。核心成员包括 append_text、append_thinking、append_tool_call、append_data_block、append_chat_response。
The response of chat models. Declared in agentscope.model. Extends DictMixin.
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
content | List[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock] | 内容字段。 | — |
is_last | bool | 是最后字段。 | — |
id | str | 标识字段。 | field(default_factory=_generate_id) |
created_at | str | 已创建 at字段。 | field(default_factory=_generate_timestamp) |
type | Literal['chat_response'] | 类型字段。 | field(default_factory=lambda: 'chat_response') |
usage | ChatUsage | None | 用量字段。 | field(default_factory=lambda: None) |
finished_reason | FinishedReason | `finished_reason` 字段。 | field(default_factory=lambda: FinishedReason.COMPLETED) |
metadata | dict[str, JSONSerializableObject] | 元数据字段。 | field(default_factory=lambda: {}) |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def append_text(text: str, block_id: str | None = None) -> Self | 追加文本。 Append text to the current response. |
def append_thinking(thinking: str, block_id: str | None = None, **extra_fields: Any) -> Self | 追加 `append_thinking`。 Append thinking to the current response. |
def append_tool_call(block_id: str, name: str, input: str, **extra_fields: Any) -> Self | 追加工具调用。 Append tool call to the current response by tool call block ID. |
def append_data_block(block_id: str, data: bytes, media_type: str, name: str | None = None) -> Self | 追加数据块。 Append raw media bytes to the ``DataBlock`` with the given id. |
def append_chat_response(chat_response: Self) -> Self | 追加聊天响应。 Append chat response to the current response. |
属性详情Attribute Detail
content
List[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock]内容字段。声明为 List[TextBlock | ToolCallBlock | ThinkingBlock | DataBlock]。
The content field.
agentscope/model/_model_response.py:35is_last
bool是最后字段。声明为 bool。
The is last field.
agentscope/model/_model_response.py:39id
str = field(default_factory=_generate_id)标识字段。声明为 str。
The id field.
agentscope/model/_model_response.py:43created_at
str = field(default_factory=_generate_timestamp)已创建 at字段。声明为 str。
The created at field.
agentscope/model/_model_response.py:46type
Literal['chat_response'] = field(default_factory=lambda: 'chat_response')类型字段。声明为 Literal['chat_response']。
The type field.
agentscope/model/_model_response.py:49usage
ChatUsage | None = field(default_factory=lambda: None)用量字段。声明为 ChatUsage | None。
The usage field.
agentscope/model/_model_response.py:54finished_reason
FinishedReason = field(default_factory=lambda: FinishedReason.COMPLETED)finished_reason 字段。声明为 FinishedReason。
The finished reason field.
agentscope/model/_model_response.py:57metadata
dict[str, JSONSerializableObject] = field(default_factory=lambda: {})元数据字段。声明为 dict[str, JSONSerializableObject]。
The metadata field.
agentscope/model/_model_response.py:63方法详情Method Detail
append_text
def append_text(text: str, block_id: str | None = None) -> Self
追加文本。
Append text to the current response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
text | str | 文本(类型 `str`)。The text. |
block_id默认default None | str | None | 块标识(类型 `str | None`)。The block id. |
agentscope/model/_model_response.py:68–82append_thinking
def append_thinking(thinking: str, block_id: str | None = None, **extra_fields: Any) -> Self
追加 append_thinking。
Append thinking to the current response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
thinking | str | thinking(类型 `str`)。The thinking content to append. |
block_id默认default None | str | None | 块标识(类型 `str | None`)。The id of the `ThinkingBlock` to accumulate into. If no matching block exists in `content`, a new one is appended. |
extra_fields | Any | extra fields(类型 `Any`)。The extra fields. |
agentscope/model/_model_response.py:84–121append_tool_call
def append_tool_call(block_id: str, name: str, input: str, **extra_fields: Any) -> Self
追加工具调用。
Append tool call to the current response by tool call block ID.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
block_id | str | 块标识(类型 `str`)。The id of the `ToolCallBlock` to accumulate into. If no matching block exists in `content`, a new one is appended. |
name | str | 名称(类型 `str`)。The name of the tool being called. |
input | str | 输入消息(类型 `str`)。The incremental JSON string arguments to append. |
extra_fields | Any | extra fields(类型 `Any`)。The extra fields. |
agentscope/model/_model_response.py:123–164append_data_block
def append_data_block(block_id: str, data: bytes, media_type: str, name: str | None = None) -> Self
追加数据块。
The accumulated bytes are stored base64-encoded in DataBlock.source.data (via a :class:Base64Source).
说明Notes
- 注意:该行为受运行时配置或底层实现影响,建议结合对应源码与版本说明确认。Note: Byte-level delta accumulation only has a well-defined semantics for streaming media where chunks can be safely concatenated (currently `audio/*`). For non-streamable media types (e.g. `image/*`, `video/*`) each `DataBlock` should be treated as a complete file and passed atomically rather than accumulated through this method.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
block_id | str | 块标识(类型 `str`)。The id of the `DataBlock` to accumulate into. If no matching block exists in `content`, a new one is appended. |
data | bytes | 数据(类型 `bytes`)。The incremental raw media bytes to append. |
media_type | str | media 类型(类型 `str`)。The IANA media type of the raw bytes (e.g. `audio/pcm`, `audio/wav`). Used both to tag a newly-created block and to guard against accidentally mixing bytes from different media types under the same id. |
name默认default None | str | None | 名称(类型 `str | None`)。The optional `name` field used when a new `DataBlock` needs to be created. Ignored when an existing block with `block_id` is found. |
agentscope/model/_model_response.py:166–238append_chat_response
def append_chat_response(chat_response: Self) -> Self
追加聊天响应。
Append chat response to the current response.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
chat_response | Self | 聊天响应(类型 `Self`)。The chat response. |
agentscope/model/_model_response.py:240–317