修改多模他请求参数
This commit is contained in:
parent
77277b3797
commit
0322cdfa8f
@ -24,6 +24,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
@ -260,6 +261,12 @@ public class BaseModelTaskService {
|
||||
BaseModelDO baseModelDO = new BaseModelDO();
|
||||
baseModelDO.setModelName(remoteModelName);
|
||||
baseModelDO.setAigcModelName(remoteModelName);
|
||||
String[] split = remoteModelName.split("-" + active);
|
||||
String oldbasemodelname=split[0];
|
||||
BaseModelDO oldbasemodel = baseModelMapper.selectOne(Wrappers.<BaseModelDO>lambdaQuery().eq(BaseModelDO::getModelName, oldbasemodelname));
|
||||
if(oldbasemodel!=null){
|
||||
baseModelDO.setModelType(oldbasemodel.getModelType());
|
||||
}
|
||||
// 模型类型
|
||||
// 微调状态
|
||||
boolean b = replaceActiveGroups(remoteModelName, active);
|
||||
|
@ -684,11 +684,13 @@ public class ConversationServiceImpl implements ConversationService {
|
||||
ModelCompletionsModalReqVO.ModelCompletionsMessageModal modelCompletionsMessage = JsonUtils.parseObject(messageHistory, ModelCompletionsModalReqVO.ModelCompletionsMessageModal.class);
|
||||
if ("system".equals(modelCompletionsMessage.getRole())) {
|
||||
com.alibaba.fastjson.JSONArray jsonarray=new com.alibaba.fastjson.JSONArray();
|
||||
jsonarray.add(mess);
|
||||
JSONObject contentjson=new JSONObject(true);
|
||||
contentjson.put("text",mess);
|
||||
jsonarray.add(contentjson);
|
||||
modelCompletionsMessage.setContent(jsonarray);
|
||||
stringRedisTemplate.opsForList().set(CHAT_HIStORY_REDIS_KEY + ":" + chatReqVO.getUuid(), 0, JsonUtils.toJsonString(modelCompletionsMessage));
|
||||
}
|
||||
// messages.add(modelCompletionsMessage);
|
||||
messages.add(modelCompletionsMessage);
|
||||
}
|
||||
}
|
||||
// else {
|
||||
@ -745,9 +747,14 @@ public class ConversationServiceImpl implements ConversationService {
|
||||
}
|
||||
// 将用户消息存入缓存
|
||||
stringRedisTemplate.opsForList().rightPush(CHAT_HIStORY_REDIS_KEY + ":" + chatReqVO.getUuid(), JsonUtils.toJsonString(message));
|
||||
ModelCompletionsReqVO.ModelCompletionsMessage responseMessage = new ModelCompletionsReqVO.ModelCompletionsMessage();
|
||||
ModelCompletionsModalReqVO.ModelCompletionsMessageModal responseMessage = new ModelCompletionsModalReqVO.ModelCompletionsMessageModal();
|
||||
responseMessage.setRole("assistant");
|
||||
responseMessage.setContent(modelCompletionsRespVO.getAnswer());
|
||||
com.alibaba.fastjson.JSONArray contentjsonarray=new com.alibaba.fastjson.JSONArray();
|
||||
JSONObject answerjson=new JSONObject(true);
|
||||
answerjson.put("text",modelCompletionsRespVO.getAnswer());
|
||||
answerjson.put("type","text");
|
||||
contentjsonarray.add(answerjson);
|
||||
responseMessage.setContent(contentjsonarray);
|
||||
stringRedisTemplate.opsForList().rightPush(CHAT_HIStORY_REDIS_KEY + ":" + chatReqVO.getUuid(), JsonUtils.toJsonString(responseMessage));
|
||||
// 保存数据回流信息
|
||||
DataRefluxDataSaveReqVO dataRefluxDataSaveReqVO = new DataRefluxDataSaveReqVO();
|
||||
|
@ -244,39 +244,67 @@ public class ModelService {
|
||||
|
||||
JSONArray messageJsonArray = new JSONArray();
|
||||
List<ModelCompletionsModalReqVO.ModelCompletionsMessageModal> messages = req.getMessages();
|
||||
ModelCompletionsModalReqVO.ModelCompletionsMessageModal modelCompletionsMessageModal = messages.get(0);
|
||||
for(int i=0;i<messages.size();i++){
|
||||
ModelCompletionsModalReqVO.ModelCompletionsMessageModal modelCompletionsMessageModal = messages.get(i);
|
||||
JSONObject messagesjson=new JSONObject(true);
|
||||
messagesjson.put("role",modelCompletionsMessageModal.getRole());
|
||||
JSONArray contentjsonarray = new JSONArray();
|
||||
JSONArray contentJsonArray = modelCompletionsMessageModal.getContent();
|
||||
for (int j = 0; j < contentJsonArray.size(); j++) {
|
||||
JSONObject jsonObject = contentJsonArray.getJSONObject(j);
|
||||
|
||||
JSONObject messagejson = new JSONObject(true);
|
||||
messagejson.put("role", modelCompletionsMessageModal.getRole());
|
||||
// 用 LinkedHashMap 保证字段顺序
|
||||
Map<String, Object> orderedContent = new LinkedHashMap<>();
|
||||
|
||||
// content 保持字段顺序:type > text > image_url
|
||||
JSONArray contentjsonarray = new JSONArray();
|
||||
JSONArray contentJsonArray = modelCompletionsMessageModal.getContent();
|
||||
|
||||
for (int i = 0; i < contentJsonArray.size(); i++) {
|
||||
JSONObject jsonObject = contentJsonArray.getJSONObject(i);
|
||||
|
||||
// 用 LinkedHashMap 保证字段顺序
|
||||
Map<String, Object> orderedContent = new LinkedHashMap<>();
|
||||
|
||||
if (jsonObject.containsKey("type")) {
|
||||
orderedContent.put("type", jsonObject.getString("type"));
|
||||
if (jsonObject.containsKey("type")) {
|
||||
orderedContent.put("type", jsonObject.getString("type"));
|
||||
}
|
||||
if (jsonObject.containsKey("text")) {
|
||||
orderedContent.put("text", jsonObject.getString("text"));
|
||||
}
|
||||
if (jsonObject.containsKey("image_url")) {
|
||||
JSONObject imageUrl = jsonObject.getJSONObject("image_url");
|
||||
orderedContent.put("image_url", imageUrl);
|
||||
}
|
||||
// 创建顺序保留的 JSONObject
|
||||
JSONObject orderedJsonObject = new JSONObject(orderedContent);
|
||||
contentjsonarray.add(orderedJsonObject);
|
||||
}
|
||||
if (jsonObject.containsKey("text")) {
|
||||
orderedContent.put("text", jsonObject.getString("text"));
|
||||
}
|
||||
if (jsonObject.containsKey("image_url")) {
|
||||
JSONObject imageUrl = jsonObject.getJSONObject("image_url");
|
||||
orderedContent.put("image_url", imageUrl);
|
||||
}
|
||||
|
||||
// 创建顺序保留的 JSONObject
|
||||
JSONObject orderedJsonObject = new JSONObject(orderedContent);
|
||||
contentjsonarray.add(orderedJsonObject);
|
||||
messagesjson.put("content", contentjsonarray);
|
||||
messageJsonArray.add(messagesjson);
|
||||
}
|
||||
// ModelCompletionsModalReqVO.ModelCompletionsMessageModal modelCompletionsMessageModal = messages.get(0);
|
||||
|
||||
// JSONObject messagejson = new JSONObject(true);
|
||||
// messagejson.put("role", modelCompletionsMessageModal.getRole());
|
||||
//
|
||||
//// content 保持字段顺序:type > text > image_url
|
||||
// JSONArray contentjsonarray = new JSONArray();
|
||||
// JSONArray contentJsonArray = modelCompletionsMessageModal.getContent();
|
||||
//
|
||||
// for (int i = 0; i < contentJsonArray.size(); i++) {
|
||||
// JSONObject jsonObject = contentJsonArray.getJSONObject(i);
|
||||
//
|
||||
// // 用 LinkedHashMap 保证字段顺序
|
||||
// Map<String, Object> orderedContent = new LinkedHashMap<>();
|
||||
//
|
||||
// if (jsonObject.containsKey("type")) {
|
||||
// orderedContent.put("type", jsonObject.getString("type"));
|
||||
// }
|
||||
// if (jsonObject.containsKey("text")) {
|
||||
// orderedContent.put("text", jsonObject.getString("text"));
|
||||
// }
|
||||
// if (jsonObject.containsKey("image_url")) {
|
||||
// JSONObject imageUrl = jsonObject.getJSONObject("image_url");
|
||||
// orderedContent.put("image_url", imageUrl);
|
||||
// }
|
||||
//
|
||||
// // 创建顺序保留的 JSONObject
|
||||
// JSONObject orderedJsonObject = new JSONObject(orderedContent);
|
||||
// contentjsonarray.add(orderedJsonObject);
|
||||
// }
|
||||
|
||||
|
||||
messagejson.put("content", contentjsonarray);
|
||||
messageJsonArray.add(messagejson);
|
||||
|
||||
reqjson.put("messages", messageJsonArray);
|
||||
reqjson.put("max_tokens", req.getMax_tokens());
|
||||
|
Loading…
x
Reference in New Issue
Block a user