ChatCompletionsChunk
@JsonInclude(JsonInclude.Include.NON_NULL) public class ChatCompletionsChunk
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:67–259用于聊天补全 API的流式分块。位于 io.agentscope.core.chat.completions.model 包。核心成员包括 textChunk、toolCallChunk、toolResultChunk、finishChunk、getId、setId。
Streaming chunk for Chat Completions API.
This follows OpenAI's streaming response format for chat completions. Each chunk contains a delta with partial content.
Example streaming chunk:
{
"id": "chatcmpl-xxx",
"object": "chat.completion.chunk",
"created": 1234567890,
"model": "gpt-4",
"choices": [{
"index": 0,
"delta": {"content": "Hello"},
"finish_reason": null
}]
}
Tool call streaming chunk:
{
"id": "chatcmpl-xxx",
"object": "chat.completion.chunk",
"created": 1234567890,
"model": "gpt-4",
"choices": [{
"index": 0,
"delta": {
"tool_calls": [{
"index": 0,
"id": "call_abc",
"type": "function",
"function": {"name": "get_weather", "arguments": "{...}"}
}]
},
"finish_reason": null
}]
}
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public ChatCompletionsChunk() | 初始化 `ChatCompletionsChunk` 实例。 Default constructor. |
public ChatCompletionsChunk(String id, String model) | 创建分块使用基础信息。 Create a chunk with basic info. |
方法摘要Method Summary
构造器详情Constructor Detail
ChatCompletionsChunk
public ChatCompletionsChunk()
初始化 ChatCompletionsChunk 实例。
Default constructor.
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:81–83ChatCompletionsChunk
public ChatCompletionsChunk(String id, String model)
创建分块使用基础信息。
Create a chunk with basic info.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Request ID |
model | String | 模型实例(类型 `String`)。Model name |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:91–95方法详情Method Detail
textChunk
public static ChatCompletionsChunk textChunk(String id, String model, String content)
创建文本内容分块。
Create a text content chunk.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Request ID |
model | String | 模型实例(类型 `String`)。Model name |
content | String | 内容(类型 `String`)。Text content delta |
ChatCompletionsChunkio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:105–118toolCallChunk
public static ChatCompletionsChunk toolCallChunk(String id, String model, List<ToolCall> toolCalls)
创建工具调用分块。
Create a tool call chunk.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Request ID |
model | String | 模型实例(类型 `String`)。Model name |
toolCalls | List<ToolCall> | 工具调用(类型 `List`)。Tool calls to include |
ChatCompletionsChunkio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:128–142toolResultChunk
public static ChatCompletionsChunk toolResultChunk(String id, String model, String toolCallId, String toolName, String content)
创建工具结果分块。
Create a tool result chunk.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Request ID |
model | String | 模型实例(类型 `String`)。Model name |
toolCallId | String | 工具调用标识(类型 `String`)。The ID of the tool call this result corresponds to (currently unused in streaming) |
toolName | String | 工具名称(类型 `String`)。The name of the tool that was executed |
content | String | 工具执行结果内容。The tool execution result content |
ChatCompletionsChunkio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:180–196finishChunk
public static ChatCompletionsChunk finishChunk(String id, String model, String finishReason)
执行 finishChunk 方法。
Create a finish chunk.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。Request ID |
model | String | 模型实例(类型 `String`)。Model name |
finishReason | String | finish 推理(类型 `String`)。The finish reason (stop, tool_calls, etc.) |
ChatCompletionsChunkio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:206–218getId
public String getId()
获取标识。
Returns the id.
Stringio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:220–222setId
public void setId(String id)
设置标识。
Sets the id.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
id | String | 标识(类型 `String`)。The id. |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:224–226getObject
public String getObject()
获取对象。
Returns the object.
Stringio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:228–230setObject
public void setObject(String object)
设置对象。
Sets the object.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
object | String | 对象(类型 `String`)。The object. |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:232–234getCreated
public long getCreated()
获取已创建。
Returns the created.
longio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:236–238setCreated
public void setCreated(long created)
设置已创建。
Sets the created.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
created | long | 已创建(类型 `long`)。The created. |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:240–242getModel
public String getModel()
获取模型。
Returns the model.
Stringio/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:244–246setModel
public void setModel(String model)
设置模型。
Sets the model.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
model | String | 模型实例(类型 `String`)。The model. |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:248–250getChoices
public List<ChatChoice> getChoices()
获取 getChoices。
Returns the choices.
List<ChatChoice>io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:252–254setChoices
public void setChoices(List<ChatChoice> choices)
设置 setChoices。
Sets the choices.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
choices | List<ChatChoice> | choices(类型 `List`)。The choices. |
io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:256–258