Commit a4583428 by Jony.L

ai问答添加智谱glm-4.0-flash接口

parent 0bdbd9b8
......@@ -3,18 +3,7 @@ package com.luhu.computility.module.external.controller.openapi;
import com.luhu.computility.framework.apilog.core.annotation.ApiAccessLog;
import com.luhu.computility.framework.common.pojo.CommonResult;
import com.luhu.computility.framework.signature.core.annotation.ApiSignature;
import com.luhu.computility.module.external.controller.openapi.dto.AIQAReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.AIQARespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.CeateVideoStreamReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.CeateVideoStreamRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ConversationReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ConversationRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.GenerateFaceSwapRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.MatchImageRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.UploadImageRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewImageReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewSourceRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewVideoReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.*;
import com.luhu.computility.module.external.controller.openapi.service.OpenApiService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
......@@ -170,4 +159,19 @@ public class OpenApiController {
return openApiService.aliyunStreamChat(aiqaReqDTO);
}
@ApiAccessLog
@PostMapping(value="/glm-stream-chat", produces=MediaType.TEXT_EVENT_STREAM_VALUE)
@Operation(summary = "智谱GLM流式-自定义messages", description = "调用方自定义messages数组")
@ApiSignature
public SseEmitter glmStreamChat(@RequestBody ZhipuChatReqDTO zhipuChatReqDTO) {
return openApiService.zhipuStreamChat(zhipuChatReqDTO);
}
@ApiAccessLog
@PostMapping(value="/glm-multi-stream-chat", produces=MediaType.TEXT_EVENT_STREAM_VALUE)
@Operation(summary = "智谱GLM多轮流式", description = "多轮对话,带历史记录存储")
public SseEmitter glmMultiStreamChat(@RequestBody ZhipuConversationReqDTO zhipuConversationReqDTO) {
return openApiService.zhipuMultiStreamChat(zhipuConversationReqDTO);
}
}
package com.luhu.computility.module.external.controller.openapi.dto;
import lombok.Data;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;
@Data
public class ZhipuChatReqDTO {
@NotEmpty(message = "messages不能为空")
@Valid
private List<MessageDTO> messages;
}
\ No newline at end of file
package com.luhu.computility.module.external.controller.openapi.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ZhipuConversationReqDTO {
@NotBlank(message = "content不能为空")
private String content;
private String conversationId;
private String systemPrompt;
}
\ No newline at end of file
......@@ -20,6 +20,8 @@ import com.luhu.computility.module.external.controller.openapi.dto.UploadImageRe
import com.luhu.computility.module.external.controller.openapi.dto.ViewImageReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewVideoReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewSourceRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ZhipuChatReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ZhipuConversationReqDTO;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
......@@ -55,6 +57,10 @@ public interface OpenApiService {
SseEmitter aliyunStreamChat(AIQAReqDTO aiqaReqDTO);
SseEmitter zhipuStreamChat(ZhipuChatReqDTO zhipuChatReqDTO);
SseEmitter zhipuMultiStreamChat(ZhipuConversationReqDTO zhipuConversationReqDTO);
String getSourceUrl(String promptId, Integer type);
......
......@@ -41,6 +41,8 @@ import com.luhu.computility.module.external.controller.openapi.dto.UploadImageRe
import com.luhu.computility.module.external.controller.openapi.dto.ViewImageReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewSourceRespDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ViewVideoReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ZhipuChatReqDTO;
import com.luhu.computility.module.external.controller.openapi.dto.ZhipuConversationReqDTO;
import com.luhu.computility.module.external.controller.service.SSEService;
import com.luhu.computility.module.external.dal.dataobject.file.AiGeneratedFileDO;
import com.luhu.computility.module.external.enums.CityEnum;
......@@ -119,6 +121,12 @@ public class OpenApiServiceImpl implements OpenApiService {
@Value("${swap-face.aliyun-stream-chat}")
private String aliyunStreamchat;
@Value("${swap-face.glm-stream-chat}")
private String zhipuStreamChat;
@Value("${swap-face.glm-multi-stream-chat}")
private String zhipuMultiStreamChat;
@Autowired
private SSEService sseService;
......@@ -585,4 +593,54 @@ public class OpenApiServiceImpl implements OpenApiService {
}
}
@Override
public SseEmitter zhipuStreamChat(ZhipuChatReqDTO zhipuChatReqDTO) {
SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
try {
sseService.receiveSSEStreamForward(zhipuStreamChat, zhipuChatReqDTO)
.subscribe(message -> {
try {
emitter.send(SseEmitter.event().data(message));
} catch (IOException e) {
log.error("智谱GLM流式异常" + e.toString());
emitter.completeWithError(e);
}
},
error -> emitter.completeWithError(error),
() -> emitter.complete()
);
} catch (Exception e) {
emitter.completeWithError(e);
}
});
return emitter;
}
@Override
public SseEmitter zhipuMultiStreamChat(ZhipuConversationReqDTO zhipuConversationReqDTO) {
SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
try {
sseService.receiveSSEStreamForward(zhipuMultiStreamChat, zhipuConversationReqDTO)
.subscribe(message -> {
try {
emitter.send(SseEmitter.event().data(message));
} catch (IOException e) {
log.error("智谱GLM多轮流式异常" + e.toString());
emitter.completeWithError(e);
}
},
error -> emitter.completeWithError(error),
() -> emitter.complete()
);
} catch (Exception e) {
emitter.completeWithError(e);
}
});
return emitter;
}
}
\ No newline at end of file
......@@ -70,6 +70,18 @@ public class SSEService {
});
}
/**
* 通用SSE流式转发方法
*/
public Flux<String> receiveSSEStreamForward(String url, Object requestBody) {
return webClient.post()
.uri(url)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(requestBody)
.retrieve()
.bodyToFlux(String.class);
}
//备用方法
public String backUp(String response) {
String[] lines = response.split("\n");
......
......@@ -394,7 +394,7 @@ similar-image:
match-mage: ${similar-image.base-url}/matchImage
swap-face:
base-url: https://218.77.58.42:18088/
base-url: http://218.77.58.42:18088/
upload-image: ${swap-face.base-url}/uploadFaceSwapImage
create-video-stream: ${swap-face.base-url}/reActorFaceSwap
view-video: ${swap-face.base-url}/viewVideo
......@@ -404,6 +404,8 @@ swap-face:
AIQA-chat: ${swap-face.base-url}/v1/AIQA-chat
AIQA-stream-chat: ${swap-face.base-url}/v1/AIQA-stream-chat
aliyun-stream-chat: ${swap-face.base-url}/v1/aliyun-ai-chat
glm-stream-chat: ${swap-face.base-url}/chat/stream
glm-multi-stream-chat: ${swap-face.base-url}/chat/multi-stream
new-aigc:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment