Package com.bytedesk.ai.controller
Class AiRestController
java.lang.Object
com.bytedesk.ai.controller.AiRestController
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AiProviderProperties
private org.springframework.context.ApplicationContext
private final ExecutorService
private org.springframework.ai.openai.api.OpenAiApi
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<org.springframework.ai.chat.model.ChatResponse>
传统的聊天接口,使用Spring AI的ChatResponsereactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse>
chatStream
(String content) 流式聊天接口,使用Spring AI的ChatResponseorg.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.ChatCompletion>
createChatCompletion
(org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 聊天对话接口 类似OpenAI的chat/completions接口reactor.core.publisher.Flux<org.springframework.ai.openai.api.OpenAiApi.ChatCompletionChunk>
createChatCompletionStream
(org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 聊天对话流式接口 类似OpenAI的chat/completions流式接口org.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.ChatCompletion>
createCompletion
(org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 文本补全接口 类似OpenAI的completions接口org.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.EmbeddingList<org.springframework.ai.openai.api.OpenAiApi.Embedding>>
createEmbedding
(org.springframework.ai.openai.api.OpenAiApi.EmbeddingRequest<String> request) 嵌入向量接口 类似OpenAI的embeddings接口org.springframework.web.servlet.mvc.method.annotation.SseEmitter
createEmbeddingStream
(org.springframework.ai.openai.api.OpenAiApi.EmbeddingRequest<String> request) 使用SSE的嵌入向量接口void
destroy()
void
init()
-
Field Details
-
applicationContext
@Autowired private org.springframework.context.ApplicationContext applicationContext -
aiProperties
-
selectedApi
private org.springframework.ai.openai.api.OpenAiApi selectedApi -
executorService
-
-
Constructor Details
-
AiRestController
public AiRestController()
-
-
Method Details
-
init
@PostConstruct public void init() -
createCompletion
@PostMapping("/completions") public org.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.ChatCompletion> createCompletion(@RequestBody org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 文本补全接口 类似OpenAI的completions接口- Parameters:
request
- 补全请求- Returns:
- 补全响应
-
createChatCompletion
@PostMapping("/chat/completions") public org.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.ChatCompletion> createChatCompletion(@RequestBody org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 聊天对话接口 类似OpenAI的chat/completions接口- Parameters:
request
- 聊天请求- Returns:
- 聊天响应
-
createChatCompletionStream
@PostMapping(path="/chat/completions/stream", produces="text/event-stream") public reactor.core.publisher.Flux<org.springframework.ai.openai.api.OpenAiApi.ChatCompletionChunk> createChatCompletionStream(@RequestBody org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest request) 聊天对话流式接口 类似OpenAI的chat/completions流式接口- Parameters:
request
- 聊天请求- Returns:
- SSE流
-
createEmbedding
@PostMapping("/embeddings") public org.springframework.http.ResponseEntity<org.springframework.ai.openai.api.OpenAiApi.EmbeddingList<org.springframework.ai.openai.api.OpenAiApi.Embedding>> createEmbedding(@RequestBody org.springframework.ai.openai.api.OpenAiApi.EmbeddingRequest<String> request) 嵌入向量接口 类似OpenAI的embeddings接口- Parameters:
request
- 嵌入请求- Returns:
- 嵌入响应
-
createEmbeddingStream
@PostMapping(path="/embeddings/stream", produces="text/event-stream") public org.springframework.web.servlet.mvc.method.annotation.SseEmitter createEmbeddingStream(@RequestBody org.springframework.ai.openai.api.OpenAiApi.EmbeddingRequest<String> request) 使用SSE的嵌入向量接口- Parameters:
request
- 嵌入请求- Returns:
- SSE流
-
chat
@PostMapping("/chat") public org.springframework.http.ResponseEntity<org.springframework.ai.chat.model.ChatResponse> chat(@RequestBody String content) 传统的聊天接口,使用Spring AI的ChatResponse- Parameters:
content
- 聊天内容- Returns:
- ChatResponse
-
chatStream
@PostMapping(path="/chat/stream", produces="application/x-ndjson") public reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse> chatStream(@RequestBody String content) 流式聊天接口,使用Spring AI的ChatResponse- Parameters:
content
- 聊天内容- Returns:
- Flux
-
destroy
@PreDestroy public void destroy()
-