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;
|
//package xyz.wbsite.achat.core.message;
|
||||||
|
//
|
||||||
|
//
|
||||||
import xyz.wbsite.achat.core.base.Message;
|
///**
|
||||||
|
// * 用户消息
|
||||||
/**
|
// *
|
||||||
* 用户消息
|
// * @author wangbing
|
||||||
*
|
// * @version 0.0.1
|
||||||
* @author wangbing
|
// * @since 1.8
|
||||||
* @version 0.0.1
|
// */
|
||||||
* @since 1.8
|
//public class AiMessage extends Message {
|
||||||
*/
|
//
|
||||||
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;
|
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;
|
//package xyz.wbsite.achat.core.message;
|
||||||
|
//
|
||||||
import xyz.wbsite.achat.core.base.Attachment;
|
//import xyz.wbsite.achat.core.Attachment;
|
||||||
import xyz.wbsite.achat.core.base.Message;
|
//
|
||||||
|
//import java.util.List;
|
||||||
import java.util.List;
|
//
|
||||||
|
///**
|
||||||
/**
|
// * 用户消息
|
||||||
* 用户消息
|
// *
|
||||||
*
|
// * @author wangbing
|
||||||
* @author wangbing
|
// * @version 0.0.1
|
||||||
* @version 0.0.1
|
// * @since 1.8
|
||||||
* @since 1.8
|
// */
|
||||||
*/
|
//public class UserMessage extends Message {
|
||||||
public class UserMessage extends Message {
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 用户ID
|
||||||
* 用户ID
|
// */
|
||||||
*/
|
// private String uid;
|
||||||
private String uid;
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 附件
|
||||||
* 附件
|
// */
|
||||||
*/
|
// private List<Attachment> attachments;
|
||||||
private List<Attachment> attachments;
|
//
|
||||||
|
// public String getUid() {
|
||||||
public String getUid() {
|
// return uid;
|
||||||
return uid;
|
// }
|
||||||
}
|
//
|
||||||
|
// public void setUid(String uid) {
|
||||||
public void setUid(String uid) {
|
// this.uid = uid;
|
||||||
this.uid = uid;
|
// }
|
||||||
}
|
//
|
||||||
|
// public List<Attachment> getAttachments() {
|
||||||
public List<Attachment> getAttachments() {
|
// return attachments;
|
||||||
return attachments;
|
// }
|
||||||
}
|
//
|
||||||
|
// public void setAttachments(List<Attachment> attachments) {
|
||||||
public void setAttachments(List<Attachment> attachments) {
|
// this.attachments = attachments;
|
||||||
this.attachments = attachments;
|
// }
|
||||||
}
|
//}
|
||||||
}
|
|
||||||
|
@ -1,106 +1,105 @@
|
|||||||
package xyz.wbsite.achat.core.prompt;
|
//package xyz.wbsite.achat.core.prompt;
|
||||||
|
//
|
||||||
import xyz.wbsite.achat.core.base.Message;
|
//import xyz.wbsite.achat.core.message.Message;
|
||||||
import xyz.wbsite.achat.core.base.Prompt;
|
//import xyz.wbsite.achat.core.Prompt;
|
||||||
import xyz.wbsite.achat.core.message.UserMessage;
|
//import xyz.wbsite.achat.core.message.UserMessage;
|
||||||
|
//
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
//import java.util.stream.Collectors;
|
||||||
|
//
|
||||||
public class MessagePrompt extends Prompt {
|
//public class MessagePrompt extends Prompt {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 模型
|
// * 模型
|
||||||
*/
|
// */
|
||||||
private String model;
|
// private String model;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 消息列表
|
// * 消息列表
|
||||||
*/
|
// */
|
||||||
private List<Message> messages;
|
// private List<Message> messages;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 是否流式返回
|
// * 是否流式返回
|
||||||
*/
|
// */
|
||||||
private Boolean stream;
|
// private Boolean stream;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 最大token数
|
// * 最大token数
|
||||||
*/
|
// */
|
||||||
private Integer maxTokens;
|
// private Integer maxTokens;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 温度参
|
// * 温度参
|
||||||
*/
|
// */
|
||||||
private Double temperature;
|
// private Double temperature;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 额外参数
|
// * 额外参数
|
||||||
*/
|
// */
|
||||||
private Map<String, Object> extraParams;
|
// private Map<String, Object> extraParams;
|
||||||
|
//
|
||||||
public String getModel() {
|
// public String getModel() {
|
||||||
return model;
|
// return model;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setModel(String model) {
|
// public void setModel(String model) {
|
||||||
this.model = model;
|
// this.model = model;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public List<Message> getMessages() {
|
// public List<Message> getMessages() {
|
||||||
return messages;
|
// return messages;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setMessages(List<Message> messages) {
|
// public void setMessages(List<Message> messages) {
|
||||||
this.messages = messages;
|
// this.messages = messages;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Boolean getStream() {
|
// public Boolean getStream() {
|
||||||
return stream;
|
// return stream;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setStream(Boolean stream) {
|
// public void setStream(Boolean stream) {
|
||||||
this.stream = stream;
|
// this.stream = stream;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Integer getMaxTokens() {
|
// public Integer getMaxTokens() {
|
||||||
return maxTokens;
|
// return maxTokens;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setMaxTokens(Integer maxTokens) {
|
// public void setMaxTokens(Integer maxTokens) {
|
||||||
this.maxTokens = maxTokens;
|
// this.maxTokens = maxTokens;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Double getTemperature() {
|
// public Double getTemperature() {
|
||||||
return temperature;
|
// return temperature;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setTemperature(Double temperature) {
|
// public void setTemperature(Double temperature) {
|
||||||
this.temperature = temperature;
|
// this.temperature = temperature;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public Map<String, Object> getExtraParams() {
|
// public Map<String, Object> getExtraParams() {
|
||||||
return extraParams;
|
// return extraParams;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setExtraParams(Map<String, Object> extraParams) {
|
// public void setExtraParams(Map<String, Object> extraParams) {
|
||||||
this.extraParams = extraParams;
|
// this.extraParams = extraParams;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// public UserMessage getLastUserMessage() {
|
||||||
public UserMessage getLastUserMessage() {
|
// List<Message> messageList = messages.stream().filter(message -> message instanceof UserMessage).collect(Collectors.toList());
|
||||||
List<Message> messageList = messages.stream().filter(message -> message instanceof UserMessage).collect(Collectors.toList());
|
// UserMessage userMessage = (UserMessage)messageList.get(messageList.size() - 1);
|
||||||
UserMessage userMessage = (UserMessage)messageList.get(messageList.size() - 1);
|
// return userMessage;
|
||||||
return userMessage;
|
// }
|
||||||
}
|
//
|
||||||
|
// public String getUid() {
|
||||||
public String getUid() {
|
// return getLastUserMessage().getUid();
|
||||||
return getLastUserMessage().getUid();
|
// }
|
||||||
}
|
//
|
||||||
|
// public String getSid(){
|
||||||
public String getSid(){
|
// return getLastUserMessage().getSid();
|
||||||
return getLastUserMessage().getSid();
|
// }
|
||||||
}
|
//
|
||||||
|
//}
|
||||||
}
|
|
||||||
|
@ -1,122 +1,121 @@
|
|||||||
package xyz.wbsite.achat.core.service.impl;
|
//package xyz.wbsite.achat.core.service.impl;
|
||||||
|
//
|
||||||
import org.springframework.stereotype.Service;
|
//import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
import xyz.wbsite.achat.core.message.MessageSseEmitter;
|
//import xyz.wbsite.achat.core.message.MessageSseEmitter;
|
||||||
import xyz.wbsite.achat.core.base.Message;
|
//import xyz.wbsite.achat.core.message.Message;
|
||||||
import xyz.wbsite.achat.core.base.Result;
|
//import xyz.wbsite.achat.core.Result;
|
||||||
import xyz.wbsite.achat.core.base.Session;
|
//import xyz.wbsite.achat.core.Session;
|
||||||
import xyz.wbsite.achat.core.message.UserMessage;
|
//import xyz.wbsite.achat.core.prompt.MessagePrompt;
|
||||||
import xyz.wbsite.achat.core.prompt.MessagePrompt;
|
//import xyz.wbsite.achat.core.service.SessionService;
|
||||||
import xyz.wbsite.achat.core.service.SessionService;
|
//
|
||||||
|
//import java.util.ArrayList;
|
||||||
import java.util.ArrayList;
|
//import java.util.HashMap;
|
||||||
import java.util.HashMap;
|
//import java.util.List;
|
||||||
import java.util.List;
|
//import java.util.Map;
|
||||||
import java.util.Map;
|
//import java.util.UUID;
|
||||||
import java.util.UUID;
|
//import java.util.stream.Collectors;
|
||||||
import java.util.stream.Collectors;
|
//
|
||||||
|
///**
|
||||||
/**
|
// * 会话管理服务实现类
|
||||||
* 会话管理服务实现类
|
// * 实现会话的创建、删除、查询、消息收发等功能
|
||||||
* 实现会话的创建、删除、查询、消息收发等功能
|
// *
|
||||||
*
|
// * @author wangbing
|
||||||
* @author wangbing
|
// * @version 0.0.1
|
||||||
* @version 0.0.1
|
// * @since 1.8
|
||||||
* @since 1.8
|
// */
|
||||||
*/
|
//@Service
|
||||||
@Service
|
//public class SessionServiceMemoryImpl implements SessionService {
|
||||||
public class SessionServiceMemoryImpl implements SessionService {
|
//
|
||||||
|
// private final Map<String, Session> sessionStore = new HashMap<>();
|
||||||
private final Map<String, Session> sessionStore = new HashMap<>();
|
//
|
||||||
|
// private final List<Message> messageStore = new ArrayList<>();
|
||||||
private final List<Message> messageStore = new ArrayList<>();
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 创建新会话
|
||||||
* 创建新会话
|
// */
|
||||||
*/
|
// @Override
|
||||||
@Override
|
// public Result<Session> createSession(String uid) {
|
||||||
public Result<Session> createSession(String uid) {
|
// Session session = new Session();
|
||||||
Session session = new Session();
|
// session.setId(String.valueOf(UUID.randomUUID().toString()));
|
||||||
session.setId(String.valueOf(UUID.randomUUID().toString()));
|
// session.setUid(uid);
|
||||||
session.setUid(uid);
|
// session.setTitle("新对话");
|
||||||
session.setTitle("新对话");
|
// sessionStore.put(session.getId(), session);
|
||||||
sessionStore.put(session.getId(), session);
|
// return Result.success(session);
|
||||||
return Result.success(session);
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 删除会话
|
||||||
* 删除会话
|
// */
|
||||||
*/
|
// @Override
|
||||||
@Override
|
// public Result<Void> deleteSession(String sid) {
|
||||||
public Result<Void> deleteSession(String sid) {
|
// sessionStore.remove(sid);
|
||||||
sessionStore.remove(sid);
|
// return Result.success();
|
||||||
return Result.success();
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 查询会话列表
|
||||||
* 查询会话列表
|
// */
|
||||||
*/
|
// @Override
|
||||||
@Override
|
// public Result<List<Session>> listSessions(String uid) {
|
||||||
public Result<List<Session>> listSessions(String uid) {
|
// List<Session> collect = sessionStore.values()
|
||||||
List<Session> collect = sessionStore.values()
|
// .stream()
|
||||||
.stream()
|
// .filter(item -> item.getUid().equals(uid))
|
||||||
.filter(item -> item.getUid().equals(uid))
|
// .collect(Collectors.toList());
|
||||||
.collect(Collectors.toList());
|
// return Result.success(collect);
|
||||||
return Result.success(collect);
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 获取会话详情
|
||||||
* 获取会话详情
|
// */
|
||||||
*/
|
// @Override
|
||||||
@Override
|
// public Result<Session> getSession(String sid) {
|
||||||
public Result<Session> getSession(String sid) {
|
// Session session = sessionStore.get(sid);
|
||||||
Session session = sessionStore.get(sid);
|
// if (session == null) {
|
||||||
if (session == null) {
|
// return Result.error("会话不存在");
|
||||||
return Result.error("会话不存在");
|
// }
|
||||||
}
|
// return Result.success(session);
|
||||||
return Result.success(session);
|
// }
|
||||||
}
|
//
|
||||||
|
// /**
|
||||||
/**
|
// * 发送消息并获取流式响应
|
||||||
* 发送消息并获取流式响应
|
// */
|
||||||
*/
|
// @Override
|
||||||
@Override
|
// public SseEmitter sendMessage(MessagePrompt message) {
|
||||||
public SseEmitter sendMessage(MessagePrompt message) {
|
// // 创建VChatSseEmitter来处理流式响应
|
||||||
// 创建VChatSseEmitter来处理流式响应
|
// return new MessageSseEmitter(message, (emitter, message1) -> {
|
||||||
return new MessageSseEmitter(message, (emitter, message1) -> {
|
// // 这边模拟LLM复述一遍用户问题
|
||||||
// 这边模拟LLM复述一遍用户问题
|
// String text = message1.getContent();
|
||||||
String text = message1.getContent();
|
// for (char c : text.toCharArray()) {
|
||||||
for (char c : text.toCharArray()) {
|
// if (emitter.isComplete()) {
|
||||||
if (emitter.isComplete()) {
|
// return;
|
||||||
return;
|
// }
|
||||||
}
|
// emitter.onPartialResponse(String.valueOf(c));
|
||||||
emitter.onPartialResponse(String.valueOf(c));
|
// try {
|
||||||
try {
|
// Thread.sleep(100);
|
||||||
Thread.sleep(100);
|
// } catch (InterruptedException e) {
|
||||||
} catch (InterruptedException e) {
|
// throw new RuntimeException(e);
|
||||||
throw new RuntimeException(e);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// emitter.onCompleteResponse(null);
|
||||||
emitter.onCompleteResponse(null);
|
// });
|
||||||
});
|
// }
|
||||||
}
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public Result<Void> stopSession(String sid) {
|
||||||
public Result<Void> stopSession(String sid) {
|
// // todo
|
||||||
// todo
|
// return Result.success();
|
||||||
return Result.success();
|
// }
|
||||||
}
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public Result<List<Message>> listMessage(String sid) {
|
||||||
public Result<List<Message>> listMessage(String sid) {
|
// List<Message> messages = messageStore.stream().filter(item -> item.getSid().equals(sid)).collect(Collectors.toList());
|
||||||
List<Message> messages = messageStore.stream().filter(item -> item.getSid().equals(sid)).collect(Collectors.toList());
|
// return Result.success(messages);
|
||||||
return Result.success(messages);
|
// }
|
||||||
}
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public Result<Void> deleteMessage(String sid) {
|
||||||
public Result<Void> deleteMessage(String sid) {
|
// messageStore.forEach(item -> messageStore.remove(item));
|
||||||
messageStore.forEach(item -> messageStore.remove(item));
|
// return null;
|
||||||
return null;
|
// }
|
||||||
}
|
//}
|
||||||
}
|
|
Loading…
Reference in new issue