|
@@ -373,7 +373,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
public ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser chatgptUser) {
|
|
public ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser chatgptUser) {
|
|
|
ConversationLimitResponse conversationLimitResponse = new ConversationLimitResponse();
|
|
ConversationLimitResponse conversationLimitResponse = new ConversationLimitResponse();
|
|
|
conversationLimitResponse.setLimited(false);
|
|
conversationLimitResponse.setLimited(false);
|
|
|
- if ("gpt-4".equals(model)) {
|
|
|
|
|
|
|
+ if (!"text-davinci-002-render-sha".equals(model)) {
|
|
|
//如果不为车队 直接返回
|
|
//如果不为车队 直接返回
|
|
|
if (!chatgptUser.getIsCar()) {
|
|
if (!chatgptUser.getIsCar()) {
|
|
|
return conversationLimitResponse;
|
|
return conversationLimitResponse;
|
|
@@ -500,8 +500,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
|
|
|
|
|
private Long carOaiLimit(String carId) {
|
|
private Long carOaiLimit(String carId) {
|
|
|
- if (redisService.hasKey("clears_in:" + carId)) {
|
|
|
|
|
- return redisService.getExpire("clears_in:" + carId);
|
|
|
|
|
|
|
+ if (redisService.hasKey("chatgpt:clears_in:" + carId)) {
|
|
|
|
|
+ return redisService.getExpire("chatgpt:clears_in:" + carId);
|
|
|
}
|
|
}
|
|
|
return 0L;
|
|
return 0L;
|
|
|
}
|
|
}
|
|
@@ -542,19 +542,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
SearchResult<ChatGptUserConversationRecordHistoryView> search = beanSearcher.search(ChatGptUserConversationRecordHistoryView.class, MapUtils.builder().field("userToken", userToken).limit(0, 2).build());
|
|
SearchResult<ChatGptUserConversationRecordHistoryView> search = beanSearcher.search(ChatGptUserConversationRecordHistoryView.class, MapUtils.builder().field("userToken", userToken).limit(0, 2).build());
|
|
|
Set<ChatgptCarInfoView> res = search.getDataList().stream()
|
|
Set<ChatgptCarInfoView> res = search.getDataList().stream()
|
|
|
.map((historyView) -> {
|
|
.map((historyView) -> {
|
|
|
- ChatgptCarInfoView chatgptCarInfoView = buildChatgptCarInfoView(historyView.getCarId(), redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
|
|
|
|
|
|
|
+ ChatgptCarInfoView chatgptCarInfoView = buildChatgptCarInfoView(historyView.getCarId(), historyView.getCarName(), historyView.getIsPLus(), redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
|
|
|
chatgptCarInfoView.setIsHistory(true);
|
|
chatgptCarInfoView.setIsHistory(true);
|
|
|
chatgptCarInfoView.setScore(redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
|
|
chatgptCarInfoView.setScore(redisService.zScore(RedisService.key.CHATGPT_CAR_SCORES.getName(), historyView.getCarId()));
|
|
|
- String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + historyView.getCarId());
|
|
|
|
|
- if (JSONUtil.isJson(sessionVar)) {
|
|
|
|
|
- JSONObject sessionJson = new JSONObject(sessionVar);
|
|
|
|
|
- JSONArray models = sessionJson.getJSONArray("models");
|
|
|
|
|
- if (models.size() > 1) {
|
|
|
|
|
- chatgptCarInfoView.setType("plus");
|
|
|
|
|
- } else {
|
|
|
|
|
- chatgptCarInfoView.setType("3.5");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
return chatgptCarInfoView;
|
|
return chatgptCarInfoView;
|
|
|
}).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
}).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
@@ -621,15 +611,10 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
initFleets(false);
|
|
initFleets(false);
|
|
|
}
|
|
}
|
|
|
lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, count - 1);
|
|
lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, count - 1);
|
|
|
-
|
|
|
|
|
- return lowestScorecarIds.stream()
|
|
|
|
|
- .map(typedTuple -> {
|
|
|
|
|
- String value = StringUtil.getString(typedTuple.getValue());
|
|
|
|
|
- Double score = typedTuple.getScore(); // 获取分数
|
|
|
|
|
- // 根据需要处理value和score
|
|
|
|
|
- return buildChatgptCarInfoView(value, score); // 假设这个方法现在也接收分数
|
|
|
|
|
- })
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
|
|
+ Map<Object, Double> collect = lowestScorecarIds.stream().collect(Collectors.toMap(ZSetOperations.TypedTuple::getValue, ZSetOperations.TypedTuple::getScore));
|
|
|
|
|
+ List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(Wrappers.lambdaQuery(ChatgptSession.class).in(ChatgptSession::getCarId, collect.keySet()));
|
|
|
|
|
+ return chatgptSessions.stream().map((chatgptSession)-> buildChatgptCarInfoView(chatgptSession.getCarId(),chatgptSession.getCarName(), chatgptSession.getIsPlus(), collect.get(chatgptSession.getCarId())))
|
|
|
|
|
+ .sorted(Comparator.comparing(ChatgptCarInfoView::getScore)).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void initFleets(Boolean flag) {
|
|
public void initFleets(Boolean flag) {
|
|
@@ -652,22 +637,15 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建ChatgptCarInfoView对象
|
|
// 构建ChatgptCarInfoView对象
|
|
|
- private ChatgptCarInfoView buildChatgptCarInfoView(String carId, Double score) {
|
|
|
|
|
|
|
+ private ChatgptCarInfoView buildChatgptCarInfoView(String carId, String carName, Integer isPlus, Double score) {
|
|
|
// 在这里根据carId获取相关信息并填充到ChatgptCarInfoView对象中
|
|
// 在这里根据carId获取相关信息并填充到ChatgptCarInfoView对象中
|
|
|
ChatgptCarInfoView view = new ChatgptCarInfoView();
|
|
ChatgptCarInfoView view = new ChatgptCarInfoView();
|
|
|
view.setCarId(carId);
|
|
view.setCarId(carId);
|
|
|
// 假设以下方法从Redis或其他服务获取数据
|
|
// 假设以下方法从Redis或其他服务获取数据
|
|
|
view.setScore(score);
|
|
view.setScore(score);
|
|
|
view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
|
|
view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
|
|
|
- String sessionVar = redisService.getStr(RedisService.key.CHATGPT_CAR_SEESSION.getName() + carId);
|
|
|
|
|
- if (JSONUtil.isJson(sessionVar)) {
|
|
|
|
|
- JSONArray models = new JSONObject(sessionVar).getJSONArray("models");
|
|
|
|
|
- if (models != null && models.size() > 1) {
|
|
|
|
|
- view.setType("plus");
|
|
|
|
|
- } else {
|
|
|
|
|
- view.setType("3.5");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ view.setType(isPlus == 1 ? "plus" : "3.5");
|
|
|
view.setGptLimit(40); // 假设值
|
|
view.setGptLimit(40); // 假设值
|
|
|
int use = getCarConversationCount(carId, 3L).intValue();
|
|
int use = getCarConversationCount(carId, 3L).intValue();
|
|
|
view.setUse(Math.min(use, 40));
|
|
view.setUse(Math.min(use, 40));
|
|
@@ -676,7 +654,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
view.setStatus("停运");
|
|
view.setStatus("停运");
|
|
|
view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
|
|
view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
|
|
|
}
|
|
}
|
|
|
- // 设置其他必要的属性...
|
|
|
|
|
|
|
+ view.setCarName(carName);
|
|
|
return view;
|
|
return view;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -713,6 +691,11 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void carLimited(String carId, Integer expTime) {
|
|
|
|
|
+ redisService.set("chatgpt:clears_in:" + carId, expTime);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void init() {
|
|
public void init() {
|
|
|
//如果存在未存在redis中的车辆则同步进 chatgpt:car:scores
|
|
//如果存在未存在redis中的车辆则同步进 chatgpt:car:scores
|