|
@@ -211,6 +211,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
|
|
|
ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
|
|
ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
|
|
|
|
|
+ if(214610L == relationId){
|
|
|
|
|
+ return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
|
|
|
|
|
+ }
|
|
|
return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
|
|
return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
|
|
|
} else {
|
|
} else {
|
|
|
throw BusinessRuntimeException.getInstance("服务器出了点问题");
|
|
throw BusinessRuntimeException.getInstance("服务器出了点问题");
|
|
@@ -396,8 +399,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
chatgptUserConversationRecord.setModel(conversationRequest.getModel());
|
|
chatgptUserConversationRecord.setModel(conversationRequest.getModel());
|
|
|
chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
|
|
chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
|
|
|
|
|
|
|
|
- if(StringUtils.isNotBlank(conversationRequest.getCarId())){
|
|
|
|
|
- updateExperienceAndScore(conversationRequest.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
|
|
|
|
|
|
|
+ if(StringUtils.isNotBlank(chatgptSession.getCarId())){
|
|
|
|
|
+ updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -412,21 +415,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
if (chatgptUser.getIsCar()) {
|
|
if (chatgptUser.getIsCar()) {
|
|
|
conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
|
|
conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
|
|
|
}
|
|
}
|
|
|
- if(carId == null){
|
|
|
|
|
- if (StringUtils.isNotBlank(userToken)) {
|
|
|
|
|
- if (chatgptUser.getSessionId() != null) {
|
|
|
|
|
- ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
|
|
|
|
|
- if(chatgptSession != null){
|
|
|
|
|
- carId = chatgptSession.getCarId();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //车队次数记录
|
|
|
|
|
- String finalCarId = carId;
|
|
|
|
|
- TASK_EXECUTOR.execute(() -> {
|
|
|
|
|
- cardConversationRecord(finalCarId);
|
|
|
|
|
- });
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return conversationLimitResponse;
|
|
return conversationLimitResponse;
|
|
@@ -470,29 +458,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 记录车队的提问次数
|
|
|
|
|
- */
|
|
|
|
|
- public boolean cardConversationRecord(String carid) {
|
|
|
|
|
- String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carid;
|
|
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
- long windowStartMillis = currentTimeMillis - (WINDOW_SIZE) * 1000;
|
|
|
|
|
-
|
|
|
|
|
- // 清除时间窗口之前的请求记录
|
|
|
|
|
- redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|
|
|
|
|
-
|
|
|
|
|
- Long currentSize = redisService.zCard(key);
|
|
|
|
|
- if (currentSize != null && currentSize >= MAX_REQUESTS) {
|
|
|
|
|
- // 如果当前请求次数超过限制,则拒绝请求
|
|
|
|
|
- return false;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 如果未超过限制,记录当前请求的时间戳
|
|
|
|
|
- redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
|
|
|
|
|
- // 设置ZSet的过期时间,窗口大小加上一段冗余时间
|
|
|
|
|
- redisService.expire(key, (WINDOW_SIZE * 60 * 60) + 20);
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取指定用户ID在滑动窗口内的提问次数
|
|
* 获取指定用户ID在滑动窗口内的提问次数
|
|
@@ -521,9 +486,11 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
* @return 滑动窗口内的请求次数
|
|
* @return 滑动窗口内的请求次数
|
|
|
*/
|
|
*/
|
|
|
private Long getCarConversationCount(String carId, Long limitTime) {
|
|
private Long getCarConversationCount(String carId, Long limitTime) {
|
|
|
- String key = RedisService.key.CHATGPT_CAR_CONVERSATION_LIMIT.getName() + ":" + carId;
|
|
|
|
|
- long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
- long windowStartMillis = currentTimeMillis - (limitTime * 60 * 60) * 1000;
|
|
|
|
|
|
|
+ // 定义键名
|
|
|
|
|
+ String key = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
|
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ long windowStartMillis = timestamp - (limitTime * 60 * 60 * 1000);
|
|
|
|
|
|
|
|
// 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
|
|
// 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
|
|
|
redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|
|
redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|