parent
5814569607
commit
1a07e3e4ee
@ -0,0 +1,85 @@
|
||||
package xyz.wbsite.achat;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
|
||||
import xyz.wbsite.achat.core.chat.CompletionRequest;
|
||||
import xyz.wbsite.achat.core.chat.CompletionResponse;
|
||||
import xyz.wbsite.achat.core.model.ModelListResponse;
|
||||
import xyz.wbsite.achat.core.service.ChatService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* AI会话接口.
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/v1")
|
||||
public class OpenAiController {
|
||||
|
||||
// @Resource
|
||||
// private SessionService sessionService;
|
||||
@Resource
|
||||
private ChatService chatService;
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@RequestMapping()
|
||||
public String info() {
|
||||
return "OpenAI API is support";
|
||||
}
|
||||
|
||||
/**
|
||||
* 列出可用模型
|
||||
* GET /v1/models
|
||||
*/
|
||||
@GetMapping("/models")
|
||||
public ModelListResponse models() {
|
||||
// 实现获取模型列表的逻辑
|
||||
// 这里返回一个示例响应,实际应用中应从服务层获取数据
|
||||
ModelListResponse response = new ModelListResponse();
|
||||
response.setObject("list");
|
||||
// response.setData(/* 实际模型列表 */);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模型详情
|
||||
* GET /v1/models/{model}
|
||||
*/
|
||||
@GetMapping("/models/{model}")
|
||||
public Object getModel(@PathVariable String model) {
|
||||
// 实现获取模型详情的逻辑
|
||||
// 这里返回一个示例响应,实际应用中应从服务层获取数据
|
||||
return null; // 替换为实际的模型对象
|
||||
}
|
||||
|
||||
@RequestMapping("/completions")
|
||||
public CompletionResponse completions(@RequestBody CompletionRequest request) {
|
||||
return chatService.prompt(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建聊天完成
|
||||
* POST /v1/chat/completions
|
||||
*/
|
||||
@PostMapping("/chat/completions")
|
||||
public Object createChatCompletion(@RequestBody ChatCompletionRequest request) {
|
||||
if (Boolean.TRUE.equals(request.getStream())) {
|
||||
// 流式响应处理
|
||||
return chatService.streamChat(request);
|
||||
} else {
|
||||
// 非流式响应处理
|
||||
return chatService.chat(request);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
//package xyz.wbsite.achat.core;
|
||||
//
|
||||
///**
|
||||
// * 服务器推送事件
|
||||
// *
|
||||
// * @author wangbing
|
||||
// * @version 0.0.1
|
||||
// * @since 1.8
|
||||
// */
|
||||
//public class Event {
|
||||
//
|
||||
// private String id;
|
||||
//
|
||||
// private String object;
|
||||
//
|
||||
// private String model;
|
||||
//
|
||||
// private Long created;
|
||||
//
|
||||
// private String sid;
|
||||
//
|
||||
// private String uid;
|
||||
//
|
||||
// public Event() {
|
||||
// this.created = System.currentTimeMillis();
|
||||
// }
|
||||
//
|
||||
// public String getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void setId(String id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public String getObject() {
|
||||
// return object;
|
||||
// }
|
||||
//
|
||||
// public void setObject(String object) {
|
||||
// this.object = object;
|
||||
// }
|
||||
//
|
||||
// public String getModel() {
|
||||
// return model;
|
||||
// }
|
||||
//
|
||||
// public void setModel(String model) {
|
||||
// this.model = model;
|
||||
// }
|
||||
//
|
||||
// public Long getCreated() {
|
||||
// return created;
|
||||
// }
|
||||
//
|
||||
// public void setCreated(Long created) {
|
||||
// this.created = created;
|
||||
// }
|
||||
//
|
||||
// public String getSid() {
|
||||
// return sid;
|
||||
// }
|
||||
//
|
||||
// public void setSid(String sid) {
|
||||
// this.sid = sid;
|
||||
// }
|
||||
//
|
||||
// public String getUid() {
|
||||
// return uid;
|
||||
// }
|
||||
//
|
||||
// public void setUid(String uid) {
|
||||
// this.uid = uid;
|
||||
// }
|
||||
//}
|
@ -1,59 +0,0 @@
|
||||
package xyz.wbsite.achat.core.base;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 服务器推送事件
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
public class Event {
|
||||
|
||||
private String sid;
|
||||
|
||||
private Date time;
|
||||
|
||||
private String text;
|
||||
|
||||
private String type;
|
||||
|
||||
public Event(String sid) {
|
||||
this.sid = sid;
|
||||
this.time = new Date();
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public Date getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Date time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package xyz.wbsite.achat.core.base;
|
||||
|
||||
import xyz.wbsite.achat.enums.Role;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
public class Message {
|
||||
|
||||
/**
|
||||
* 角色
|
||||
*/
|
||||
private Role role;
|
||||
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
private String sid;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
*/
|
||||
private String content;
|
||||
|
||||
public Role getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Role role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getSid() {
|
||||
return sid;
|
||||
}
|
||||
|
||||
public void setSid(String sid) {
|
||||
this.sid = sid;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
package xyz.wbsite.achat.core.message;
|
||||
|
||||
|
||||
import xyz.wbsite.achat.core.base.Message;
|
||||
|
||||
/**
|
||||
* 用户消息
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
public class AiMessage extends Message {
|
||||
|
||||
}
|
||||
//package xyz.wbsite.achat.core.message;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 用户消息
|
||||
// *
|
||||
// * @author wangbing
|
||||
// * @version 0.0.1
|
||||
// * @since 1.8
|
||||
// */
|
||||
//public class AiMessage extends Message {
|
||||
//
|
||||
//}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.wbsite.achat.enums;
|
||||
package xyz.wbsite.achat.core.message;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package xyz.wbsite.achat.enums;
|
||||
package xyz.wbsite.achat.core.message;
|
||||
|
||||
/**
|
||||
* 消息状态枚举
|
@ -1,42 +1,41 @@
|
||||
package xyz.wbsite.achat.core.message;
|
||||
|
||||
import xyz.wbsite.achat.core.base.Attachment;
|
||||
import xyz.wbsite.achat.core.base.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户消息
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
public class UserMessage extends Message {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String uid;
|
||||
|
||||
/**
|
||||
* 附件
|
||||
*/
|
||||
private List<Attachment> attachments;
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public List<Attachment> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
public void setAttachments(List<Attachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
}
|
||||
//package xyz.wbsite.achat.core.message;
|
||||
//
|
||||
//import xyz.wbsite.achat.core.Attachment;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 用户消息
|
||||
// *
|
||||
// * @author wangbing
|
||||
// * @version 0.0.1
|
||||
// * @since 1.8
|
||||
// */
|
||||
//public class UserMessage extends Message {
|
||||
//
|
||||
// /**
|
||||
// * 用户ID
|
||||
// */
|
||||
// private String uid;
|
||||
//
|
||||
// /**
|
||||
// * 附件
|
||||
// */
|
||||
// private List<Attachment> attachments;
|
||||
//
|
||||
// public String getUid() {
|
||||
// return uid;
|
||||
// }
|
||||
//
|
||||
// public void setUid(String uid) {
|
||||
// this.uid = uid;
|
||||
// }
|
||||
//
|
||||
// public List<Attachment> getAttachments() {
|
||||
// return attachments;
|
||||
// }
|
||||
//
|
||||
// public void setAttachments(List<Attachment> attachments) {
|
||||
// this.attachments = attachments;
|
||||
// }
|
||||
//}
|
||||
|
@ -1,106 +1,105 @@
|
||||
package xyz.wbsite.achat.core.prompt;
|
||||
|
||||
import xyz.wbsite.achat.core.base.Message;
|
||||
import xyz.wbsite.achat.core.base.Prompt;
|
||||
import xyz.wbsite.achat.core.message.UserMessage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessagePrompt extends Prompt {
|
||||
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 消息列表
|
||||
*/
|
||||
private List<Message> messages;
|
||||
|
||||
/**
|
||||
* 是否流式返回
|
||||
*/
|
||||
private Boolean stream;
|
||||
|
||||
/**
|
||||
* 最大token数
|
||||
*/
|
||||
private Integer maxTokens;
|
||||
|
||||
/**
|
||||
* 温度参
|
||||
*/
|
||||
private Double temperature;
|
||||
|
||||
/**
|
||||
* 额外参数
|
||||
*/
|
||||
private Map<String, Object> extraParams;
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public List<Message> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public void setMessages(List<Message> messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
public Boolean getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
public void setStream(Boolean stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public Integer getMaxTokens() {
|
||||
return maxTokens;
|
||||
}
|
||||
|
||||
public void setMaxTokens(Integer maxTokens) {
|
||||
this.maxTokens = maxTokens;
|
||||
}
|
||||
|
||||
public Double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public Map<String, Object> getExtraParams() {
|
||||
return extraParams;
|
||||
}
|
||||
|
||||
public void setExtraParams(Map<String, Object> extraParams) {
|
||||
this.extraParams = extraParams;
|
||||
}
|
||||
|
||||
|
||||
public UserMessage getLastUserMessage() {
|
||||
List<Message> messageList = messages.stream().filter(message -> message instanceof UserMessage).collect(Collectors.toList());
|
||||
UserMessage userMessage = (UserMessage)messageList.get(messageList.size() - 1);
|
||||
return userMessage;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return getLastUserMessage().getUid();
|
||||
}
|
||||
|
||||
public String getSid(){
|
||||
return getLastUserMessage().getSid();
|
||||
}
|
||||
|
||||
}
|
||||
//package xyz.wbsite.achat.core.prompt;
|
||||
//
|
||||
//import xyz.wbsite.achat.core.message.Message;
|
||||
//import xyz.wbsite.achat.core.Prompt;
|
||||
//import xyz.wbsite.achat.core.message.UserMessage;
|
||||
//
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
//public class MessagePrompt extends Prompt {
|
||||
//
|
||||
// /**
|
||||
// * 模型
|
||||
// */
|
||||
// private String model;
|
||||
//
|
||||
// /**
|
||||
// * 消息列表
|
||||
// */
|
||||
// private List<Message> messages;
|
||||
//
|
||||
// /**
|
||||
// * 是否流式返回
|
||||
// */
|
||||
// private Boolean stream;
|
||||
//
|
||||
// /**
|
||||
// * 最大token数
|
||||
// */
|
||||
// private Integer maxTokens;
|
||||
//
|
||||
// /**
|
||||
// * 温度参
|
||||
// */
|
||||
// private Double temperature;
|
||||
//
|
||||
// /**
|
||||
// * 额外参数
|
||||
// */
|
||||
// private Map<String, Object> extraParams;
|
||||
//
|
||||
// public String getModel() {
|
||||
// return model;
|
||||
// }
|
||||
//
|
||||
// public void setModel(String model) {
|
||||
// this.model = model;
|
||||
// }
|
||||
//
|
||||
// public List<Message> getMessages() {
|
||||
// return messages;
|
||||
// }
|
||||
//
|
||||
// public void setMessages(List<Message> messages) {
|
||||
// this.messages = messages;
|
||||
// }
|
||||
//
|
||||
// public Boolean getStream() {
|
||||
// return stream;
|
||||
// }
|
||||
//
|
||||
// public void setStream(Boolean stream) {
|
||||
// this.stream = stream;
|
||||
// }
|
||||
//
|
||||
// public Integer getMaxTokens() {
|
||||
// return maxTokens;
|
||||
// }
|
||||
//
|
||||
// public void setMaxTokens(Integer maxTokens) {
|
||||
// this.maxTokens = maxTokens;
|
||||
// }
|
||||
//
|
||||
// public Double getTemperature() {
|
||||
// return temperature;
|
||||
// }
|
||||
//
|
||||
// public void setTemperature(Double temperature) {
|
||||
// this.temperature = temperature;
|
||||
// }
|
||||
//
|
||||
// public Map<String, Object> getExtraParams() {
|
||||
// return extraParams;
|
||||
// }
|
||||
//
|
||||
// public void setExtraParams(Map<String, Object> extraParams) {
|
||||
// this.extraParams = extraParams;
|
||||
// }
|
||||
//
|
||||
// public UserMessage getLastUserMessage() {
|
||||
// List<Message> messageList = messages.stream().filter(message -> message instanceof UserMessage).collect(Collectors.toList());
|
||||
// UserMessage userMessage = (UserMessage)messageList.get(messageList.size() - 1);
|
||||
// return userMessage;
|
||||
// }
|
||||
//
|
||||
// public String getUid() {
|
||||
// return getLastUserMessage().getUid();
|
||||
// }
|
||||
//
|
||||
// public String getSid(){
|
||||
// return getLastUserMessage().getSid();
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,122 +1,121 @@
|
||||
package xyz.wbsite.achat.core.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import xyz.wbsite.achat.core.message.MessageSseEmitter;
|
||||
import xyz.wbsite.achat.core.base.Message;
|
||||
import xyz.wbsite.achat.core.base.Result;
|
||||
import xyz.wbsite.achat.core.base.Session;
|
||||
import xyz.wbsite.achat.core.message.UserMessage;
|
||||
import xyz.wbsite.achat.core.prompt.MessagePrompt;
|
||||
import xyz.wbsite.achat.core.service.SessionService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 会话管理服务实现类
|
||||
* 实现会话的创建、删除、查询、消息收发等功能
|
||||
*
|
||||
* @author wangbing
|
||||
* @version 0.0.1
|
||||
* @since 1.8
|
||||
*/
|
||||
@Service
|
||||
public class SessionServiceMemoryImpl implements SessionService {
|
||||
|
||||
private final Map<String, Session> sessionStore = new HashMap<>();
|
||||
|
||||
private final List<Message> messageStore = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 创建新会话
|
||||
*/
|
||||
@Override
|
||||
public Result<Session> createSession(String uid) {
|
||||
Session session = new Session();
|
||||
session.setId(String.valueOf(UUID.randomUUID().toString()));
|
||||
session.setUid(uid);
|
||||
session.setTitle("新对话");
|
||||
sessionStore.put(session.getId(), session);
|
||||
return Result.success(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会话
|
||||
*/
|
||||
@Override
|
||||
public Result<Void> deleteSession(String sid) {
|
||||
sessionStore.remove(sid);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询会话列表
|
||||
*/
|
||||
@Override
|
||||
public Result<List<Session>> listSessions(String uid) {
|
||||
List<Session> collect = sessionStore.values()
|
||||
.stream()
|
||||
.filter(item -> item.getUid().equals(uid))
|
||||
.collect(Collectors.toList());
|
||||
return Result.success(collect);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会话详情
|
||||
*/
|
||||
@Override
|
||||
public Result<Session> getSession(String sid) {
|
||||
Session session = sessionStore.get(sid);
|
||||
if (session == null) {
|
||||
return Result.error("会话不存在");
|
||||
}
|
||||
return Result.success(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息并获取流式响应
|
||||
*/
|
||||
@Override
|
||||
public SseEmitter sendMessage(MessagePrompt message) {
|
||||
// 创建VChatSseEmitter来处理流式响应
|
||||
return new MessageSseEmitter(message, (emitter, message1) -> {
|
||||
// 这边模拟LLM复述一遍用户问题
|
||||
String text = message1.getContent();
|
||||
for (char c : text.toCharArray()) {
|
||||
if (emitter.isComplete()) {
|
||||
return;
|
||||
}
|
||||
emitter.onPartialResponse(String.valueOf(c));
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
emitter.onCompleteResponse(null);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> stopSession(String sid) {
|
||||
// todo
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<List<Message>> listMessage(String sid) {
|
||||
List<Message> messages = messageStore.stream().filter(item -> item.getSid().equals(sid)).collect(Collectors.toList());
|
||||
return Result.success(messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Void> deleteMessage(String sid) {
|
||||
messageStore.forEach(item -> messageStore.remove(item));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//package xyz.wbsite.achat.core.service.impl;
|
||||
//
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
//import xyz.wbsite.achat.core.message.MessageSseEmitter;
|
||||
//import xyz.wbsite.achat.core.message.Message;
|
||||
//import xyz.wbsite.achat.core.Result;
|
||||
//import xyz.wbsite.achat.core.Session;
|
||||
//import xyz.wbsite.achat.core.prompt.MessagePrompt;
|
||||
//import xyz.wbsite.achat.core.service.SessionService;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.UUID;
|
||||
//import java.util.stream.Collectors;
|
||||
//
|
||||
///**
|
||||
// * 会话管理服务实现类
|
||||
// * 实现会话的创建、删除、查询、消息收发等功能
|
||||
// *
|
||||
// * @author wangbing
|
||||
// * @version 0.0.1
|
||||
// * @since 1.8
|
||||
// */
|
||||
//@Service
|
||||
//public class SessionServiceMemoryImpl implements SessionService {
|
||||
//
|
||||
// private final Map<String, Session> sessionStore = new HashMap<>();
|
||||
//
|
||||
// private final List<Message> messageStore = new ArrayList<>();
|
||||
//
|
||||
// /**
|
||||
// * 创建新会话
|
||||
// */
|
||||
// @Override
|
||||
// public Result<Session> createSession(String uid) {
|
||||
// Session session = new Session();
|
||||
// session.setId(String.valueOf(UUID.randomUUID().toString()));
|
||||
// session.setUid(uid);
|
||||
// session.setTitle("新对话");
|
||||
// sessionStore.put(session.getId(), session);
|
||||
// return Result.success(session);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 删除会话
|
||||
// */
|
||||
// @Override
|
||||
// public Result<Void> deleteSession(String sid) {
|
||||
// sessionStore.remove(sid);
|
||||
// return Result.success();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 查询会话列表
|
||||
// */
|
||||
// @Override
|
||||
// public Result<List<Session>> listSessions(String uid) {
|
||||
// List<Session> collect = sessionStore.values()
|
||||
// .stream()
|
||||
// .filter(item -> item.getUid().equals(uid))
|
||||
// .collect(Collectors.toList());
|
||||
// return Result.success(collect);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取会话详情
|
||||
// */
|
||||
// @Override
|
||||
// public Result<Session> getSession(String sid) {
|
||||
// Session session = sessionStore.get(sid);
|
||||
// if (session == null) {
|
||||
// return Result.error("会话不存在");
|
||||
// }
|
||||
// return Result.success(session);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 发送消息并获取流式响应
|
||||
// */
|
||||
// @Override
|
||||
// public SseEmitter sendMessage(MessagePrompt message) {
|
||||
// // 创建VChatSseEmitter来处理流式响应
|
||||
// return new MessageSseEmitter(message, (emitter, message1) -> {
|
||||
// // 这边模拟LLM复述一遍用户问题
|
||||
// String text = message1.getContent();
|
||||
// for (char c : text.toCharArray()) {
|
||||
// if (emitter.isComplete()) {
|
||||
// return;
|
||||
// }
|
||||
// emitter.onPartialResponse(String.valueOf(c));
|
||||
// try {
|
||||
// Thread.sleep(100);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// emitter.onCompleteResponse(null);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Result<Void> stopSession(String sid) {
|
||||
// // todo
|
||||
// return Result.success();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Result<List<Message>> listMessage(String sid) {
|
||||
// List<Message> messages = messageStore.stream().filter(item -> item.getSid().equals(sid)).collect(Collectors.toList());
|
||||
// return Result.success(messages);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Result<Void> deleteMessage(String sid) {
|
||||
// messageStore.forEach(item -> messageStore.remove(item));
|
||||
// return null;
|
||||
// }
|
||||
//}
|
Loading…
Reference in new issue