Class AiRestController

java.lang.Object
com.bytedesk.ai.controller.AiRestController

@RestController @RequestMapping("/api/v1/ai") public class AiRestController extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private org.springframework.context.ApplicationContext
     
    private final ExecutorService
     
    private org.springframework.ai.openai.api.OpenAiApi
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<org.springframework.ai.chat.model.ChatResponse>
    chat(String content)
    传统的聊天接口,使用Spring AI的ChatResponse
    reactor.core.publisher.Flux<org.springframework.ai.chat.model.ChatResponse>
    chatStream(String content)
    流式聊天接口,使用Spring AI的ChatResponse
    org.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
     
    void
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • applicationContext

      @Autowired private org.springframework.context.ApplicationContext applicationContext
    • aiProperties

      @Autowired private AiProviderProperties aiProperties
    • selectedApi

      private org.springframework.ai.openai.api.OpenAiApi selectedApi
    • executorService

      private final ExecutorService 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()