AS AgentScopeAPI 手册 / API Reference

ChatCompletionsResponse

@JsonInclude(JsonInclude.Include.NON_NULL) public class ChatCompletionsResponse
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsResponse.java:86–207

用于聊天补全 HTTP API的响应负载。位于 io.agentscope.core.chat.completions.model 包。核心成员包括 getId、setId、getObject、setObject、getCreated、setCreated。

Response payload for the Chat Completions HTTP API.

This response is 100% compatible with OpenAI's Chat Completions API format. All fields follow the official OpenAI specification exactly.

Standard Response:

`{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1234567890,
"model": "gpt-4",
"choices": [
{
"index": 0,
"message": {"role": "assistant", "content": "Hello!"},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}
`

Response with Tool Calls:

When the assistant calls tools:

`{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_abc",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Hangzhou\"}"}
}]
},
"finish_reason": "tool_calls"
}],
"usage": {...}
}
`

Stateless Client Responsibility:

The client must:

  • Append the assistant message from response to their conversation history

  • If tool_calls present, execute tools and append tool result messages

  • Send the complete history in the next request

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
Usage类class
用量,与模型服务通信并返回生成或向量化结果。
Token usage statistics following OpenAI's format.

方法摘要Method Summary

方法Method说明Description
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.
public Usage getUsage()
获取用量。
Returns the usage.
public void setUsage(Usage usage)
设置用量。
Sets the usage.

方法详情Method Detail

getId

public String getId()

获取标识。

Returns the id.

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

setId

public void setId(String id)

设置标识。

Sets the id.

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

getObject

public String getObject()

获取对象。

Returns the object.

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

setObject

public void setObject(String object)

设置对象。

Sets the object.

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

getCreated

public long getCreated()

获取已创建。

Returns the created.

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

setCreated

public void setCreated(long created)

设置已创建。

Sets the created.

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

getModel

public String getModel()

获取模型。

Returns the model.

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

setModel

public void setModel(String model)

设置模型。

Sets the model.

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

getChoices

public List<ChatChoice> getChoices()

获取 getChoices。

Returns the choices.

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

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/ChatCompletionsResponse.java:143–145

getUsage

public Usage getUsage()

获取用量。

Returns the usage.

返回Returns Usage
返回用量。Returns usage.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsResponse.java:147–149

setUsage

public void setUsage(Usage usage)

设置用量。

Sets the usage.

参数Parameters
名称Name类型Type说明Description
usageUsage用量(类型 `Usage`)。The usage.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsResponse.java:151–153

嵌套类详情Nested Class Detail

Usage

@JsonInclude(JsonInclude.Include.NON_NULL) public static class Usage

用量,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.chat.completions.model 包。核心成员包括 getPromptTokens、setPromptTokens、getCompletionTokens、setCompletionTokens、getTotalTokens、setTotalTokens。

Token usage statistics following OpenAI's format.

All fields use snake_case per OpenAI specification.

基于官方固定版本源码静态生成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.