update modules/ai: mod 12 files

This commit is contained in:
jack ning
2025-03-11 16:46:54 +08:00
parent 48ecac7355
commit d5ffa7feff
11 changed files with 150 additions and 132 deletions

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-06-12 07:17:13
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 16:08:20
* @LastEditTime: 2025-03-11 16:46:50
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -167,20 +167,20 @@ public class RobotEventListener {
//
if (robot.getLlm().getProvider().equals(LlmProviderConsts.OLLAMA)) {
springAIOllamaService
.ifPresent(service -> service.sendWsMessage(query, robot, message));
.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.DEEPSEEK)) {
springAIDeepseekService
.ifPresent(service -> service.sendWsMessage(query, robot, message));
.ifPresent(service -> service.sendLlmWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.DASHSCOPE)) {
springAIDashscopeService
.ifPresent(service -> service.sendWsMessage(query, robot, message));
.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.ZHIPU)) {
springAIZhipuaiService
.ifPresent(service -> service.sendWsMessage(query, robot, message));
.ifPresent(service -> service.sendLlmWebsocketMessage(query, robot, message));
} else {
// 默认使用智谱AI
springAIZhipuaiService
.ifPresent(service -> service.sendWsMessage(query, robot, message));
.ifPresent(service -> service.sendLlmWebsocketMessage(query, robot, message));
}
} else {
log.error("robot not found");
@@ -219,16 +219,16 @@ public class RobotEventListener {
messageSendService.sendProtobufMessage(clonedMessage);
//
if (robot.getLlm().getProvider().equals(LlmProviderConsts.OLLAMA)) {
springAIOllamaService.ifPresent(service -> service.sendWsKbMessage(query, robot, message));
springAIOllamaService.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.DEEPSEEK)) {
springAIDeepseekService.ifPresent(service -> service.sendWsKbMessage(query, robot, message));
springAIDeepseekService.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.DASHSCOPE)) {
springAIDashscopeService.ifPresent(service -> service.sendWsKbMessage(query, robot, message));
springAIDashscopeService.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else if (robot.getLlm().getProvider().equals(LlmProviderConsts.ZHIPU)) {
springAIZhipuaiService.ifPresent(service -> service.sendWsKbMessage(query, robot, message));
springAIZhipuaiService.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
} else {
// 默认使用智谱AI
springAIZhipuaiService.ifPresent(service -> service.sendWsKbMessage(query, robot, message));
springAIZhipuaiService.ifPresent(service -> service.sendWebsocketMessage(query, robot, message));
}
}
}

View File

@@ -34,7 +34,7 @@ public abstract class BaseSpringAIService implements SpringAIService {
}
@Override
public void sendWsKbMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf) {
public void sendWebsocketMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf) {
Assert.hasText(query, "Query must not be empty");
Assert.notNull(robot, "RobotEntity must not be null");
Assert.notNull(messageProtobuf, "MessageProtobuf must not be null");
@@ -51,16 +51,17 @@ public abstract class BaseSpringAIService implements SpringAIService {
}
@Override
public void sendWsMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf) {
Assert.hasText(query, "Query must not be empty");
Assert.notNull(robot, "Robot must not be null");
Assert.notNull(messageProtobuf, "MessageProtobuf must not be null");
public void sendKbaseSseMessage(String message, SseEmitter emitter) {
Assert.hasText(message, "Message must not be empty");
Assert.notNull(emitter, "SseEmitter must not be null");
String prompt = buildPrompt(robot.getLlm().getPrompt(), query);
List<Message> messages = buildMessages(robot.getLlm().getPrompt(), prompt);
Prompt aiPrompt = new Prompt(messages);
processPrompt(aiPrompt, messageProtobuf);
// MessageProtobuf messageProtobuf = new MessageProtobuf();
// messageProtobuf.setType(MessageProtobuf.MessageType.TEXT);
// String result = processPromptSync(message);
// messageProtobuf.setContent(result);
// messageSendService.sendProtobufMessage(messageProtobuf);
//
}
@Override
@@ -72,6 +73,39 @@ public abstract class BaseSpringAIService implements SpringAIService {
return generateFaqPairs(prompt);
}
// @Override
// public void sendLlmWebsocketMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf) {
// Assert.hasText(query, "Query must not be empty");
// Assert.notNull(robot, "Robot must not be null");
// Assert.notNull(messageProtobuf, "MessageProtobuf must not be null");
// String prompt = buildPrompt(robot.getLlm().getPrompt(), query);
// List<Message> messages = buildMessages(robot.getLlm().getPrompt(), prompt);
// Prompt aiPrompt = new Prompt(messages);
// processPrompt(aiPrompt, messageProtobuf);
// }
// @Override
// public void sendKbaseWebsocketAutoReply(String query, String kbUid, MessageProtobuf messageProtobuf) {
// Assert.hasText(query, "Query must not be empty");
// Assert.hasText(kbUid, "Knowledge base UID must not be empty");
// Assert.notNull(messageProtobuf, "MessageProtobuf must not be null");
// Assert.isTrue(springAIVectorService.isPresent(), "SpringAIVectorService must be present");
// List<String> contentList = springAIVectorService.get().searchText(query, kbUid);
// String context = String.join("\n", contentList);
// String prompt = RobotConsts.PROMPT_BLUEPRINT.replace("{context}", context).replace("{query}", query);
// List<Message> messages = buildMessages(prompt, prompt);
// Prompt aiPrompt = new Prompt(messages);
// processPrompt(aiPrompt, messageProtobuf);
// }
@Override
public void generateFaqPairsSync(String chunk) {
Assert.hasText(chunk, "Chunk must not be empty");
@@ -103,23 +137,6 @@ public abstract class BaseSpringAIService implements SpringAIService {
}
}
@Override
public void sendWsKbAutoReply(String query, String kbUid, MessageProtobuf messageProtobuf) {
Assert.hasText(query, "Query must not be empty");
Assert.hasText(kbUid, "Knowledge base UID must not be empty");
Assert.notNull(messageProtobuf, "MessageProtobuf must not be null");
Assert.isTrue(springAIVectorService.isPresent(), "SpringAIVectorService must be present");
List<String> contentList = springAIVectorService.get().searchText(query, kbUid);
String context = String.join("\n", contentList);
String prompt = RobotConsts.PROMPT_BLUEPRINT.replace("{context}", context).replace("{query}", query);
List<Message> messages = buildMessages(prompt, prompt);
Prompt aiPrompt = new Prompt(messages);
processPrompt(aiPrompt, messageProtobuf);
}
protected String buildKbPrompt(String systemPrompt, String query, String context) {
return systemPrompt + "\n" +
"用户查询: " + query + "\n" +
@@ -141,7 +158,7 @@ public abstract class BaseSpringAIService implements SpringAIService {
// 抽象方法,由具体实现类提供
protected abstract void processPrompt(Prompt prompt, MessageProtobuf messageProtobuf);
protected abstract String processPromptSync(String message);
protected abstract void processPromptSSE(String uid, String message, SseEmitter emitter);
protected abstract void processPromptSSE(String message, SseEmitter emitter);
// 抽象方法,由具体实现类提供
protected abstract String generateFaqPairs(String prompt);
}

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-17 11:39:17
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-09 22:25:42
* @LastEditTime: 2025-03-11 16:33:42
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -36,7 +36,6 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import com.bytedesk.core.annotation.UserIp;
import com.bytedesk.core.uid.UidUtils;
import com.bytedesk.core.utils.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
@@ -63,7 +62,7 @@ public class SpringAIDashscopeController {
private final DashScopeChatModel bytedeskDashScopeChatModel;
private final Optional<SpringAIDashscopeImageService> imageService;
private final ExecutorService executorService = Executors.newCachedThreadPool();
private final UidUtils uidUtils;
// private final UidUtils uidUtils;
@Qualifier("bytedeskDashScopeChatClient")
private final ChatClient bytedeskDashScopeChatClient;
@@ -108,7 +107,7 @@ public class SpringAIDashscopeController {
executorService.execute(() -> {
try {
springAIDashscopeService.processPromptSSE(uidUtils.getUid(), message, emitter);
springAIDashscopeService.processPromptSSE(message, emitter);
} catch (Exception e) {
log.error("Error processing SSE request", e);
emitter.completeWithError(e);

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-28 17:56:26
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-07 18:08:39
* @LastEditTime: 2025-03-11 16:46:11
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.alibaba.fastjson2.JSON;
import com.bytedesk.ai.springai.base.BaseSpringAIService;
import com.bytedesk.ai.springai.spring.SpringAIVectorService;
import com.bytedesk.core.message.IMessageSendService;
@@ -100,8 +101,6 @@ public class SpringAIDashscopeService extends BaseSpringAIService {
}
}
@Override
protected String generateFaqPairs(String prompt) {
return bytedeskDashScopeChatClient.prompt(prompt).call().content();
@@ -118,9 +117,12 @@ public class SpringAIDashscopeService extends BaseSpringAIService {
}
@Override
protected void processPromptSSE(String uid, String message, SseEmitter emitter) {
protected void processPromptSSE(String messageJson, SseEmitter emitter) {
MessageProtobuf messageProtobuf = JSON.parseObject(messageJson, MessageProtobuf.class);
try {
bytedeskDashScopeChatClient.prompt(message)
bytedeskDashScopeChatClient.prompt(messageProtobuf.getContent())
.stream()
.content()
.subscribe(
@@ -159,4 +161,6 @@ public class SpringAIDashscopeService extends BaseSpringAIService {
emitter.completeWithError(e);
}
}
}

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-13 13:41:56
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-07 16:05:58
* @LastEditTime: 2025-03-11 16:34:56
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.bytedesk.core.uid.UidUtils;
// import com.bytedesk.core.uid.UidUtils;
import com.bytedesk.core.utils.JsonResult;
import lombok.RequiredArgsConstructor;
@@ -47,7 +47,7 @@ import reactor.core.publisher.Flux;
public class SpringAIDeepseekController {
private final SpringAIDeepseekService springAIDeepseekService;
private final UidUtils uidUtils;
// private final UidUtils uidUtils;
private final ExecutorService executorService = Executors.newCachedThreadPool();
/**
@@ -86,7 +86,7 @@ public class SpringAIDeepseekController {
executorService.execute(() -> {
try {
springAIDeepseekService.processPromptSSE(uidUtils.getUid(), message, emitter);
springAIDeepseekService.processPromptSSE(message, emitter);
} catch (Exception e) {
log.error("Error processing SSE request", e);
emitter.completeWithError(e);

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-28 11:44:03
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 15:33:04
* @LastEditTime: 2025-03-11 16:34:49
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -91,7 +91,7 @@ public class SpringAIDeepseekService extends BaseSpringAIService {
}
@Override
protected void processPromptSSE(String uid, String message, SseEmitter emitter) {
protected void processPromptSSE(String message, SseEmitter emitter) {
deepSeekChatModel.ifPresentOrElse(
model -> {
Prompt prompt = new Prompt(message);

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2024-05-31 09:50:56
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 16:15:16
* @LastEditTime: 2025-03-11 16:34:08
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -29,7 +29,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.bytedesk.core.uid.UidUtils;
import com.bytedesk.core.utils.JsonResult;
import lombok.RequiredArgsConstructor;
@@ -48,7 +47,7 @@ public class SpringAIOllamaController {
private final SpringAIOllamaService springAIOllamaService;
private final ExecutorService executorService = Executors.newCachedThreadPool();
private final UidUtils uidUtils;
// private final UidUtils uidUtils;
// private final ThreadRestService threadRestService;
/**
@@ -81,17 +80,12 @@ public class SpringAIOllamaController {
*/
@GetMapping(value = "/chat/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter chatSSE(@RequestParam(value = "message") String message) {
//
// Optional<ThreadEntity> threadEntity = threadRestService.findByUid(threadUid);
// if (!threadEntity.isPresent()) {
// return null;
// }
SseEmitter emitter = new SseEmitter(180_000L); // 3分钟超时
executorService.execute(() -> {
try {
springAIOllamaService.processPromptSSE(uidUtils.getUid(), message, emitter);
springAIOllamaService.processPromptSSE(message, emitter);
} catch (Exception e) {
log.error("Error processing SSE request", e);
emitter.completeWithError(e);

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-26 16:59:14
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 15:30:53
* @LastEditTime: 2025-03-11 16:35:33
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -13,7 +13,6 @@
*/
package com.bytedesk.ai.springai.ollama;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@@ -29,14 +28,9 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.alibaba.fastjson2.JSON;
import com.bytedesk.ai.springai.base.BaseSpringAIService;
import com.bytedesk.ai.springai.spring.SpringAIVectorService;
import com.bytedesk.core.enums.ClientEnum;
import com.bytedesk.core.message.IMessageSendService;
import com.bytedesk.core.message.MessageProtobuf;
import com.bytedesk.core.message.MessageStatusEnum;
import com.bytedesk.core.message.MessageTypeEnum;
import com.bytedesk.core.rbac.user.UserProtobuf;
import com.bytedesk.core.thread.ThreadProtobuf;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@@ -106,34 +100,36 @@ public class SpringAIOllamaService extends BaseSpringAIService {
}
@Override
protected void processPromptSSE(String uid, String question, SseEmitter emitter) {
protected void processPromptSSE(String messageJson, SseEmitter emitter) {
//
ThreadProtobuf thread = ThreadProtobuf
.builder()
.uid(uid)
.build();
UserProtobuf user = UserProtobuf
.builder()
.uid(uid)
.nickname("ollama")
.avatar("")
.build();
MessageProtobuf messageProtobuf = JSON.parseObject(messageJson, MessageProtobuf.class);
//
MessageProtobuf messageProtobuf = MessageProtobuf
.builder()
.uid(uid)
// .content(textContent)
.type(MessageTypeEnum.STREAM)
.status(MessageStatusEnum.SUCCESS)
.client(ClientEnum.SYSTEM)
.createdAt(LocalDateTime.now())
.thread(thread)
.user(user)
.build();
// ThreadProtobuf thread = ThreadProtobuf
// .builder()
// .uid(uid)
// .build();
// UserProtobuf user = UserProtobuf
// .builder()
// .uid(uid)
// .nickname("ollama")
// .avatar("")
// .build();
// //
// MessageProtobuf messageProtobuf = MessageProtobuf
// .builder()
// .uid(uid)
// // .content(textContent)
// .type(MessageTypeEnum.STREAM)
// .status(MessageStatusEnum.SUCCESS)
// .client(ClientEnum.SYSTEM)
// .createdAt(LocalDateTime.now())
// .thread(thread)
// .user(user)
// .build();
bytedeskOllamaChatModel.ifPresentOrElse(
model -> {
Prompt prompt = new Prompt(question);
Prompt prompt = new Prompt(messageProtobuf.getContent());
model.stream(prompt).subscribe(
response -> {
try {

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-26 14:48:03
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 15:51:31
* @LastEditTime: 2025-03-11 16:45:31
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -13,6 +13,8 @@
*/
package com.bytedesk.ai.springai.spring;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.bytedesk.ai.robot.RobotEntity;
import com.bytedesk.core.message.MessageProtobuf;
@@ -28,7 +30,7 @@ public interface SpringAIService {
* @param robot 机器人实体
* @param messageProtobuf 消息协议
*/
void sendWsKbMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf);
void sendWebsocketMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf);
/**
* 发送普通消息
@@ -36,7 +38,7 @@ public interface SpringAIService {
* @param robot 机器人
* @param messageProtobuf 消息协议
*/
void sendWsMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf);
// void sendLlmWebsocketMessage(String query, RobotEntity robot, MessageProtobuf messageProtobuf);
/**
* 发送基于知识库的自动回复消息
@@ -44,7 +46,14 @@ public interface SpringAIService {
* @param kbUid 知识库ID
* @param messageProtobuf 消息协议
*/
void sendWsKbAutoReply(String query, String kbUid, MessageProtobuf messageProtobuf);
// void sendKbaseWebsocketAutoReply(String query, String kbUid, MessageProtobuf messageProtobuf);
/**
* 处理消息
* @param message 消息
* @param emitter SseEmitter
*/
void sendKbaseSseMessage(String message, SseEmitter emitter);
/**
* 异步生成FAQ对
@@ -58,4 +67,7 @@ public interface SpringAIService {
* @param chunk 文本块
*/
void generateFaqPairsSync(String chunk);
}

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-19 09:39:15
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 14:40:57
* @LastEditTime: 2025-03-11 16:34:00
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -36,7 +36,6 @@ import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import com.bytedesk.core.uid.UidUtils;
import com.bytedesk.core.utils.JsonResult;
import jakarta.servlet.ServletException;
@@ -63,7 +62,7 @@ public class SpringAIZhipuaiController {
private final ZhiPuAiChatModel bytedeskZhipuaiChatModel;
private final ZhiPuAiImageModel bytedeskZhipuaiImageModel;
private final ExecutorService executorService = Executors.newCachedThreadPool();
private final UidUtils uidUtils;
// private final UidUtils uidUtils;
/**
* 方式1同步调用
@@ -99,7 +98,7 @@ public class SpringAIZhipuaiController {
executorService.execute(() -> {
try {
springAIZhipuaiService.processPromptSSE(uidUtils.getUid(), message, emitter);
springAIZhipuaiService.processPromptSSE(message, emitter);
} catch (Exception e) {
log.error("Error processing SSE request", e);
emitter.completeWithError(e);

View File

@@ -2,7 +2,7 @@
* @Author: jackning 270580156@qq.com
* @Date: 2025-02-26 16:58:56
* @LastEditors: jackning 270580156@qq.com
* @LastEditTime: 2025-03-11 15:29:33
* @LastEditTime: 2025-03-11 16:35:47
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
* Please be aware of the BSL license restrictions before installing Bytedesk IM
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
@@ -13,7 +13,6 @@
*/
package com.bytedesk.ai.springai.zhipuai;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
@@ -27,16 +26,12 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.alibaba.fastjson2.JSON;
import com.bytedesk.ai.springai.base.BaseSpringAIService;
import com.bytedesk.ai.springai.spring.SpringAIVectorService;
import com.bytedesk.core.enums.ClientEnum;
import com.bytedesk.core.message.IMessageSendService;
import com.bytedesk.core.message.MessageProtobuf;
import com.bytedesk.core.message.MessageStatusEnum;
import com.bytedesk.core.message.MessageTypeEnum;
import com.bytedesk.core.rbac.user.UserProtobuf;
import com.bytedesk.core.thread.ThreadProtobuf;
import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
@@ -114,32 +109,34 @@ public class SpringAIZhipuaiService extends BaseSpringAIService {
* 方式3SSE方式调用
*/
@Override
public void processPromptSSE(String uid, String message, SseEmitter emitter) {
public void processPromptSSE(String messageJson, SseEmitter emitter) {
MessageProtobuf messageProtobuf = JSON.parseObject(messageJson, MessageProtobuf.class);
//
ThreadProtobuf thread = ThreadProtobuf
.builder()
.uid(uid)
.build();
UserProtobuf user = UserProtobuf
.builder()
.uid(uid)
.nickname("ollama")
.avatar("")
.build();
//
MessageProtobuf messageProtobuf = MessageProtobuf
.builder()
.uid(uid)
// .content(textContent)
.type(MessageTypeEnum.STREAM)
.status(MessageStatusEnum.SUCCESS)
.client(ClientEnum.SYSTEM)
.createdAt(LocalDateTime.now())
.thread(thread)
.user(user)
.build();
// ThreadProtobuf thread = ThreadProtobuf
// .builder()
// .uid(uid)
// .build();
// UserProtobuf user = UserProtobuf
// .builder()
// .uid(uid)
// .nickname("ollama")
// .avatar("")
// .build();
// //
// MessageProtobuf messageProtobuf = MessageProtobuf
// .builder()
// .uid(uid)
// // .content(textContent)
// .type(MessageTypeEnum.STREAM)
// .status(MessageStatusEnum.SUCCESS)
// .client(ClientEnum.SYSTEM)
// .createdAt(LocalDateTime.now())
// .thread(thread)
// .user(user)
// .build();
//
Prompt prompt = new Prompt(message);
Prompt prompt = new Prompt(messageProtobuf.getContent());
Flux<ChatResponse> responseFlux = bytedeskZhipuaiChatModel.stream(prompt);
responseFlux.subscribe(