feat(chat): 重构 LLM 流式输出并扩展 ChatSaveReq 字段
- 将原始整段 chunk 拆分为 3 字批次推送,降低前端卡顿 - ChatSaveReq 新增 userId、lang、liked 等 8 个字段并补充 Swagger 注解 - QdrantVectorService 改用 Map<String,JsonWithInt.Value> 载荷,新增 QdrantPayloadMapper 统一转换
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.yolo.keyborad.mapper;
|
||||
|
||||
|
||||
|
||||
import com.yolo.keyborad.model.dto.chat.ChatSaveReq;
|
||||
import io.qdrant.client.grpc.JsonWithInt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QdrantPayloadMapper {
|
||||
|
||||
public static Map<String, JsonWithInt.Value> toQdrantPayload(ChatSaveReq p) {
|
||||
Map<String, JsonWithInt.Value> map = new HashMap<>();
|
||||
|
||||
if (p.getUserId() != null)
|
||||
map.put("userId", longValue(p.getUserId()));
|
||||
|
||||
if (p.getUserText() != null)
|
||||
map.put("userText", stringValue(p.getUserText()));
|
||||
|
||||
if (p.getReplyText() != null)
|
||||
map.put("replyText", stringValue(p.getReplyText()));
|
||||
|
||||
if (p.getCharacterId() != null)
|
||||
map.put("characterId", intValue(p.getCharacterId()));
|
||||
|
||||
if (p.getLang() != null)
|
||||
map.put("lang", stringValue(p.getLang()));
|
||||
|
||||
if (p.getLiked() != null)
|
||||
map.put("liked", boolValue(p.getLiked()));
|
||||
|
||||
if (p.getCreatedAt() != null)
|
||||
map.put("createdAt", longValue(p.getCreatedAt()));
|
||||
|
||||
if (p.getSource() != null)
|
||||
map.put("source", stringValue(p.getSource()));
|
||||
|
||||
if (p.getAppVersion() != null)
|
||||
map.put("appVersion", stringValue(p.getAppVersion()));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static JsonWithInt.Value stringValue(String v) {
|
||||
return JsonWithInt.Value.newBuilder().setStringValue(v).build();
|
||||
}
|
||||
|
||||
private static JsonWithInt.Value intValue(Integer v) {
|
||||
return JsonWithInt.Value.newBuilder().setIntegerValue(v).build();
|
||||
}
|
||||
|
||||
private static JsonWithInt.Value longValue(Long v) {
|
||||
return JsonWithInt.Value.newBuilder().setIntegerValue(v).build();
|
||||
}
|
||||
|
||||
private static JsonWithInt.Value boolValue(Boolean v) {
|
||||
return JsonWithInt.Value.newBuilder().setBoolValue(v).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user