AS AgentScopeAPI 手册 / API Reference

ChatCompletionsRequest

public class ChatCompletionsRequest
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:58–114

用于聊天补全 HTTP API的请求负载。位于 io.agentscope.core.chat.completions.model 包。核心成员包括 getModel、setModel、getMessages、setMessages、getStream、setStream。

Request payload for the Chat Completions HTTP API.

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

Stateless Operation:

This API is fully stateless, just like OpenAI's standard API. The client is responsible for maintaining conversation history and sending the complete messages array with each request.

Example Request:

`{
"model": "gpt-4",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What's the weather in Hangzhou?"},
{"role": "assistant", "content": "Let me check...", "tool_calls": [...]},
{"role": "tool", "tool_call_id": "call_xxx", "content": "25°C sunny"},
{"role": "user", "content": "Thanks! And tomorrow?"}
],
"stream": false
}
`

Tool Call Flow:

When the assistant calls tools, the response includes tool_calls. The client should:

  • Append the assistant message (with tool_calls) to history

  • Append tool result messages for each tool call

  • Send the updated history in the next request

方法摘要Method Summary

方法Method说明Description
public String getModel()
获取模型。
Returns the model.
public void setModel(String model)
设置模型。
Sets the model.
public List<ChatMessage> getMessages()
获取消息。
Returns the messages.
public void setMessages(List<ChatMessage> messages)
设置消息。
Sets the messages.
public Boolean getStream()
获取流。
Returns the stream.
public void setStream(Boolean stream)
设置流。
Sets the stream.
public List<OpenAITool> getTools()
获取工具。
Returns the tools.
public void setTools(List<OpenAITool> tools)
设置工具。
Sets the tools.

方法详情Method Detail

getModel

public String getModel()

获取模型。

Returns the model.

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

setModel

public void setModel(String model)

设置模型。

Sets the model.

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

getMessages

public List<ChatMessage> getMessages()

获取消息。

Returns the messages.

返回Returns List<ChatMessage>
返回列出。Returns list.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:91–93

setMessages

public void setMessages(List<ChatMessage> messages)

设置消息。

Sets the messages.

参数Parameters
名称Name类型Type说明Description
messagesList<ChatMessage>消息列表(类型 `List`)。The messages.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:95–97

getStream

public Boolean getStream()

获取流。

Returns the stream.

返回Returns Boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:99–101

setStream

public void setStream(Boolean stream)

设置流。

Sets the stream.

参数Parameters
名称Name类型Type说明Description
streamBoolean流(类型 `Boolean`)。The stream.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:103–105

getTools

public List<OpenAITool> getTools()

获取工具。

Returns the tools.

返回Returns List<OpenAITool>
返回列出。Returns list.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:107–109

setTools

public void setTools(List<OpenAITool> tools)

设置工具。

Sets the tools.

参数Parameters
名称Name类型Type说明Description
toolsList<OpenAITool>工具列表(类型 `List`)。The tools.
源码Source io/agentscope/core/chat/completions/model/ChatCompletionsRequest.java:111–113
基于官方固定版本源码静态生成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.