Class ZhipuaiController

java.lang.Object
com.bytedesk.ai.zhipuai.ZhipuaiController

@RestController @RequestMapping("/zhipuai") @ConditionalOnProperty(prefix="spring.ai.zhipuai.chat", name="enabled", havingValue="true", matchIfMissing=false) public class ZhipuaiController extends Object
智谱AI接口 - 使用 oapi-java-sdk https://open.bigmodel.cn/dev/api#sdk_install https://github.com/MetaGLM/zhipuai-sdk-java-v4
  • Field Details

  • Constructor Details

    • ZhipuaiController

      public ZhipuaiController()
  • Method Details

    • chatSync

      @GetMapping("/sync") public org.springframework.http.ResponseEntity<JsonResult<?>> chatSync(@RequestParam("message") String message)
      同步调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/sync?message=hello
    • chatStream

      @GetMapping(value="/stream", produces="text/event-stream") public reactor.core.publisher.Flux<String> chatStream(@RequestParam("message") String message)
      流式调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/stream?message=hello
    • chatSse

      @GetMapping(value="/sse", produces="text/event-stream") public org.springframework.web.servlet.mvc.method.annotation.SseEmitter chatSse(@RequestParam("message") String message)
      SSE调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/sse?message=hello
    • rolePlayChat

      @GetMapping("/roleplay") public org.springframework.http.ResponseEntity<JsonResult<?>> rolePlayChat(@RequestParam("message") String message, @RequestParam("userInfo") String userInfo, @RequestParam("botInfo") String botInfo, @RequestParam("botName") String botName, @RequestParam("userName") String userName)
      角色扮演 GET http://127.0.0.1:9003/zhipuai/roleplay?message=hello&amp;amp;userInfo=...&botInfo=...&botName=...&userName=...
    • health

      @GetMapping("/health") public org.springframework.http.ResponseEntity<JsonResult<?>> health()
      健康检查
    • functionCallingChat

      @PostMapping("/function-call") public org.springframework.http.ResponseEntity<JsonResult<?>> functionCallingChat(@RequestBody Map<String,Object> request)
      Function Calling 同步调用 POST http://127.0.0.1:9003/zhipuai/function-call
    • functionCallingChatStream

      @PostMapping(value="/function-call/stream", produces="text/event-stream") public reactor.core.publisher.Flux<String> functionCallingChatStream(@RequestBody Map<String,Object> request)
      Function Calling 流式调用 POST http://127.0.0.1:9003/zhipuai/function-call/stream
    • createFunctionParameters

      private com.zhipu.oapi.service.v4.model.ChatFunctionParameters createFunctionParameters(Map<String,Object> paramsData)
      创建函数参数
    • getMapSafely

      private Map<String,Object> getMapSafely(Map<String,Object> data, String key)
      安全地获取Map类型的数据
    • getListSafely

      private List<String> getListSafely(Map<String,Object> data, String key)
      安全地获取List类型的数据
    • weatherFunctionCall

      @GetMapping("/weather") public org.springframework.http.ResponseEntity<JsonResult<?>> weatherFunctionCall(@RequestParam("city") String city)
      示例:查询天气的 Function Calling GET http://127.0.0.1:9003/zhipuai/weather?city=北京
    • flightFunctionCall

      @GetMapping("/flight") public org.springframework.http.ResponseEntity<JsonResult<?>> flightFunctionCall(@RequestParam("from") String from, @RequestParam("to") String to)
      示例:查询航班信息的 Function Calling GET http://127.0.0.1:9003/zhipuai/flight?from=成都&amp;amp;to=北京
    • generateImage

      @PostMapping("/image") public org.springframework.http.ResponseEntity<JsonResult<?>> generateImage(@RequestBody Map<String,String> request)
      图像生成 POST http://127.0.0.1:9003/zhipuai/image
    • getEmbedding

      @PostMapping("/embedding") public org.springframework.http.ResponseEntity<JsonResult<?>> getEmbedding(@RequestBody Map<String,String> request)
      向量嵌入 POST http://127.0.0.1:9003/zhipuai/embedding
    • getEmbeddings

      @PostMapping("/embeddings") public org.springframework.http.ResponseEntity<JsonResult<?>> getEmbeddings(@RequestBody Map<String,Object> request)
      批量向量嵌入 POST http://127.0.0.1:9003/zhipuai/embeddings
    • generateSpeech

      @PostMapping("/speech") public org.springframework.http.ResponseEntity<JsonResult<?>> generateSpeech(@RequestBody Map<String,String> request)
      语音合成 POST http://127.0.0.1:9003/zhipuai/speech
    • generateCustomSpeech

      @PostMapping("/voice/custom") public org.springframework.http.ResponseEntity<JsonResult<?>> generateCustomSpeech(@RequestBody Map<String,Object> request)
      自定义语音合成 POST http://127.0.0.1:9003/zhipuai/voice/custom
    • uploadFile

      @PostMapping("/file/upload") public org.springframework.http.ResponseEntity<JsonResult<?>> uploadFile(@RequestBody Map<String,String> request)
      文件上传 POST http://127.0.0.1:9003/zhipuai/file/upload
    • queryFiles

      @GetMapping("/files") public org.springframework.http.ResponseEntity<JsonResult<?>> queryFiles()
      查询文件列表 GET http://127.0.0.1:9003/zhipuai/files
    • downloadFile

      @PostMapping("/file/download") public org.springframework.http.ResponseEntity<JsonResult<?>> downloadFile(@RequestBody Map<String,String> request)
      下载文件 POST http://127.0.0.1:9003/zhipuai/file/download
    • createFineTuningJob

      @PostMapping("/finetune/create") public org.springframework.http.ResponseEntity<JsonResult<?>> createFineTuningJob(@RequestBody Map<String,String> request)
      创建微调任务 POST http://127.0.0.1:9003/zhipuai/finetune/create
    • queryFineTuningJob

      @GetMapping("/finetune/{jobId}") public org.springframework.http.ResponseEntity<JsonResult<?>> queryFineTuningJob(@PathVariable String jobId)
      查询微调任务 GET http://127.0.0.1:9003/zhipuai/finetune/{jobId}
    • chatAsync

      @PostMapping("/async") public org.springframework.http.ResponseEntity<JsonResult<?>> chatAsync(@RequestBody Map<String,String> request)
      异步聊天 POST http://127.0.0.1:9003/zhipuai/async
    • chatWithWebSearch

      @PostMapping("/websearch") public org.springframework.http.ResponseEntity<JsonResult<?>> chatWithWebSearch(@RequestBody Map<String,String> request)
      带Web搜索的聊天 POST http://127.0.0.1:9003/zhipuai/websearch
    • chatWithVoice

      @PostMapping("/voice") public org.springframework.http.ResponseEntity<JsonResult<?>> chatWithVoice(@RequestBody Map<String,String> request)
      语音模型聊天 POST http://127.0.0.1:9003/zhipuai/voice
    • destroy

      public void destroy()
      在 Bean 销毁时关闭线程池