ChatCompletionsController
@RestController @RequestMapping public class ChatCompletionsController
io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:77–293聊天补全控制器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.spring.boot.chat.web 包。核心成员包括 createCompletion、createCompletionStream、ChatCompletionsController。
HTTP controller exposing a Chat Completions API compatible with OpenAI's standard.
This controller implements a 100% stateless API, fully compatible with OpenAI's Chat Completions API. Each request is independent, and the client is responsible for managing conversation history.
How It Works:
-
Client sends complete conversation history in
messages -
Server creates a fresh agent instance, loads the messages
-
Agent processes and returns a response
-
Client appends the assistant message to their history for next request
Tool Calls:
When the assistant uses tools, the response includes tool_calls in the assistant
message. The client should:
-
Append the assistant message (with tool_calls) to history
-
Execute the tools and create tool result messages
-
Send the updated history in the next request
Features:
-
Non-streaming JSON response (default)
-
SSE streaming when Accept: text/event-stream
-
Full OpenAI compatibility
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public Object createCompletion(ChatCompletionsRequest request) | 创建补全。 Non-streaming chat completion endpoint. |
public Flux<ServerSentEvent<String>> createCompletionStream(ChatCompletionsRequest request) | 创建补全流。 Streaming chat completion endpoint. |
构造器详情Constructor Detail
ChatCompletionsController
public ChatCompletionsController(ObjectProvider<ReActAgent> agentProvider, ChatMessageConverter messageConverter, ChatCompletionsResponseBuilder responseBuilder, ChatCompletionsStreamingService streamingService, OpenAIToolConverter toolConverter)
初始化 ChatCompletionsController 实例。
Constructs a new ChatCompletionsController.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
agentProvider | ObjectProvider<ReActAgent> | 智能体提供者(类型 `ObjectProvider`)。Provider for creating prototype-scoped agent instances |
messageConverter | ChatMessageConverter | 消息转换器(类型 `ChatMessageConverter`)。Converter for HTTP DTOs to framework messages |
responseBuilder | ChatCompletionsResponseBuilder | 响应构建器(类型 `ChatCompletionsResponseBuilder`)。Builder for response objects |
streamingService | ChatCompletionsStreamingService | 流式服务(类型 `ChatCompletionsStreamingService`)。Service for streaming responses |
toolConverter | OpenAIToolConverter | 用于OpenAI 工具到 ToolSchema的转换器。Converter for OpenAI tools to ToolSchema |
io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:98–109方法详情Method Detail
createCompletion
public Object createCompletion(ChatCompletionsRequest request)
创建补全。
Non-streaming chat completion endpoint.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | ChatCompletionsRequest | 请求(类型 `ChatCompletionsRequest`)。The chat completion request containing the full message history |
Objectio/agentscope/spring/boot/chat/web/ChatCompletionsController.java:123–202createCompletionStream
public Flux<ServerSentEvent<String>> createCompletionStream(ChatCompletionsRequest request)
创建补全流。
Streaming chat completion endpoint.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | ChatCompletionsRequest | 请求(类型 `ChatCompletionsRequest`)。The chat completion request containing the full message history |
Flux<ServerSentEvent<String>>io/agentscope/spring/boot/chat/web/ChatCompletionsController.java:213–292