Package com.bytedesk.ai.zhipuai
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final BytedeskProperties
private final ExecutorService
private final ZhipuaiChatService
private final ZhipuaiService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<JsonResult<?>>
异步聊天 POST http://127.0.0.1:9003/zhipuai/asyncorg.springframework.web.servlet.mvc.method.annotation.SseEmitter
SSE调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/sse?reactor.core.publisher.Flux<String>
chatStream
(String message) 流式调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/stream?org.springframework.http.ResponseEntity<JsonResult<?>>
同步调用 - 使用新的统一接口 GET http://127.0.0.1:9003/zhipuai/sync?org.springframework.http.ResponseEntity<JsonResult<?>>
chatWithVoice
(Map<String, String> request) 语音模型聊天 POST http://127.0.0.1:9003/zhipuai/voiceorg.springframework.http.ResponseEntity<JsonResult<?>>
chatWithWebSearch
(Map<String, String> request) 带Web搜索的聊天 POST http://127.0.0.1:9003/zhipuai/websearchorg.springframework.http.ResponseEntity<JsonResult<?>>
createFineTuningJob
(Map<String, String> request) 创建微调任务 POST http://127.0.0.1:9003/zhipuai/finetune/createprivate com.zhipu.oapi.service.v4.model.ChatFunctionParameters
createFunctionParameters
(Map<String, Object> paramsData) 创建函数参数void
destroy()
在 Bean 销毁时关闭线程池org.springframework.http.ResponseEntity<JsonResult<?>>
downloadFile
(Map<String, String> request) 下载文件 POST http://127.0.0.1:9003/zhipuai/file/downloadorg.springframework.http.ResponseEntity<JsonResult<?>>
flightFunctionCall
(String from, String to) 示例:查询航班信息的 Function Calling GET http://127.0.0.1:9003/zhipuai/flight?org.springframework.http.ResponseEntity<JsonResult<?>>
functionCallingChat
(Map<String, Object> request) Function Calling 同步调用 POST http://127.0.0.1:9003/zhipuai/function-callreactor.core.publisher.Flux<String>
functionCallingChatStream
(Map<String, Object> request) Function Calling 流式调用 POST http://127.0.0.1:9003/zhipuai/function-call/streamorg.springframework.http.ResponseEntity<JsonResult<?>>
generateCustomSpeech
(Map<String, Object> request) 自定义语音合成 POST http://127.0.0.1:9003/zhipuai/voice/customorg.springframework.http.ResponseEntity<JsonResult<?>>
generateImage
(Map<String, String> request) 图像生成 POST http://127.0.0.1:9003/zhipuai/imageorg.springframework.http.ResponseEntity<JsonResult<?>>
generateSpeech
(Map<String, String> request) 语音合成 POST http://127.0.0.1:9003/zhipuai/speechorg.springframework.http.ResponseEntity<JsonResult<?>>
getEmbedding
(Map<String, String> request) 向量嵌入 POST http://127.0.0.1:9003/zhipuai/embeddingorg.springframework.http.ResponseEntity<JsonResult<?>>
getEmbeddings
(Map<String, Object> request) 批量向量嵌入 POST http://127.0.0.1:9003/zhipuai/embeddingsgetListSafely
(Map<String, Object> data, String key) 安全地获取List类型的数据getMapSafely
(Map<String, Object> data, String key) 安全地获取Map类型的数据org.springframework.http.ResponseEntity<JsonResult<?>>
health()
健康检查org.springframework.http.ResponseEntity<JsonResult<?>>
查询文件列表 GET http://127.0.0.1:9003/zhipuai/filesorg.springframework.http.ResponseEntity<JsonResult<?>>
queryFineTuningJob
(String jobId) 查询微调任务 GET http://127.0.0.1:9003/zhipuai/finetune/{jobId}org.springframework.http.ResponseEntity<JsonResult<?>>
角色扮演 GET http://127.0.0.1:9003/zhipuai/roleplay?org.springframework.http.ResponseEntity<JsonResult<?>>
uploadFile
(Map<String, String> request) 文件上传 POST http://127.0.0.1:9003/zhipuai/file/uploadorg.springframework.http.ResponseEntity<JsonResult<?>>
weatherFunctionCall
(String city) 示例:查询天气的 Function Calling GET http://127.0.0.1:9003/zhipuai/weather?
-
Field Details
-
bytedeskProperties
-
zhipuaiService
-
zhipuaiChatService
-
executorService
-
-
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;userInfo=...&botInfo=...&botName=...&userName=... -
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
安全地获取Map类型的数据 -
getListSafely
安全地获取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;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
查询文件列表 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 销毁时关闭线程池
-