AS AgentScopeAPI 手册 / API Reference

ChatCompletionsChunk

@JsonInclude(JsonInclude.Include.NON_NULL) public class ChatCompletionsChunk
源码Source 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

方法Method说明Description
public static ChatCompletionsChunk textChunk(String id, String model, String content)
static
创建文本内容分块。
Create a text content chunk.
public static ChatCompletionsChunk toolCallChunk(String id, String model, List<ToolCall> toolCalls)
static
创建工具调用分块。
Create a tool call chunk.
public static ChatCompletionsChunk toolResultChunk(String id, String model, String toolCallId, String toolName, String content)
static
创建工具结果分块。
Create a tool result chunk.
public static ChatCompletionsChunk finishChunk(String id, String model, String finishReason)
static
执行 `finishChunk` 方法。
Create a finish chunk.
public String getId()
获取标识。
Returns the id.
public void setId(String id)
设置标识。
Sets the id.
public String getObject()
获取对象。
Returns the object.
public void setObject(String object)
设置对象。
Sets the object.
public long getCreated()
获取已创建。
Returns the created.
public void setCreated(long created)
设置已创建。
Sets the created.
public String getModel()
获取模型。
Returns the model.
public void setModel(String model)
设置模型。
Sets the model.
public List<ChatChoice> getChoices()
获取 `getChoices`。
Returns the choices.
public void setChoices(List<ChatChoice> choices)
设置 `setChoices`。
Sets the choices.

构造器详情Constructor Detail

ChatCompletionsChunk

public ChatCompletionsChunk()

初始化 ChatCompletionsChunk 实例。

Default constructor.

源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:81–83

ChatCompletionsChunk

public ChatCompletionsChunk(String id, String model)

创建分块使用基础信息。

Create a chunk with basic info.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Request ID
modelString模型实例(类型 `String`)。Model name
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:91–95

方法详情Method Detail

textChunk

public static ChatCompletionsChunk textChunk(String id, String model, String content)
static

创建文本内容分块。

Create a text content chunk.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Request ID
modelString模型实例(类型 `String`)。Model name
contentString内容(类型 `String`)。Text content delta
返回Returns ChatCompletionsChunk
返回ChatCompletionsChunk。ChatCompletionsChunk with text delta
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:105–118

toolCallChunk

public static ChatCompletionsChunk toolCallChunk(String id, String model, List<ToolCall> toolCalls)
static

创建工具调用分块。

Create a tool call chunk.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Request ID
modelString模型实例(类型 `String`)。Model name
toolCallsList<ToolCall>工具调用(类型 `List`)。Tool calls to include
返回Returns ChatCompletionsChunk
返回ChatCompletionsChunk。ChatCompletionsChunk with tool calls
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:128–142

toolResultChunk

public static ChatCompletionsChunk toolResultChunk(String id, String model, String toolCallId, String toolName, String content)
static

创建工具结果分块。

Create a tool result chunk.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Request ID
modelString模型实例(类型 `String`)。Model name
toolCallIdString工具调用标识(类型 `String`)。The ID of the tool call this result corresponds to (currently unused in streaming)
toolNameString工具名称(类型 `String`)。The name of the tool that was executed
contentString工具执行结果内容。The tool execution result content
返回Returns ChatCompletionsChunk
返回ChatCompletionsChunk。ChatCompletionsChunk with tool result formatted as assistant content
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:180–196

finishChunk

public static ChatCompletionsChunk finishChunk(String id, String model, String finishReason)
static

执行 finishChunk 方法。

Create a finish chunk.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。Request ID
modelString模型实例(类型 `String`)。Model name
finishReasonStringfinish 推理(类型 `String`)。The finish reason (stop, tool_calls, etc.)
返回Returns ChatCompletionsChunk
返回ChatCompletionsChunk。ChatCompletionsChunk with finish_reason
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:206–218

getId

public String getId()

获取标识。

Returns the id.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:220–222

setId

public void setId(String id)

设置标识。

Sets the id.

参数Parameters
名称Name类型Type说明Description
idString标识(类型 `String`)。The id.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:224–226

getObject

public String getObject()

获取对象。

Returns the object.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:228–230

setObject

public void setObject(String object)

设置对象。

Sets the object.

参数Parameters
名称Name类型Type说明Description
objectString对象(类型 `String`)。The object.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:232–234

getCreated

public long getCreated()

获取已创建。

Returns the created.

返回Returns long
返回数值结果。Returns a numeric result.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:236–238

setCreated

public void setCreated(long created)

设置已创建。

Sets the created.

参数Parameters
名称Name类型Type说明Description
createdlong已创建(类型 `long`)。The created.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:240–242

getModel

public String getModel()

获取模型。

Returns the model.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:244–246

setModel

public void setModel(String model)

设置模型。

Sets the model.

参数Parameters
名称Name类型Type说明Description
modelString模型实例(类型 `String`)。The model.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:248–250

getChoices

public List<ChatChoice> getChoices()

获取 getChoices。

Returns the choices.

返回Returns List<ChatChoice>
返回列出。Returns list.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:252–254

setChoices

public void setChoices(List<ChatChoice> choices)

设置 setChoices。

Sets the choices.

参数Parameters
名称Name类型Type说明Description
choicesList<ChatChoice>choices(类型 `List`)。The choices.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsChunk.java:256–258
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.