|
|
@@ -13,6 +13,7 @@ import com.cyksj.model.response.ConversationLimitResponse;
|
|
|
import com.cyksj.model.views.ChatGptUserConversationRecordHistoryView;
|
|
|
import com.cyksj.model.views.ChatGptUserView;
|
|
|
import com.cyksj.model.views.ChatgptCarInfoView;
|
|
|
+import com.cyksj.model.views.ChatgptConversionLimitView;
|
|
|
import com.cyksj.service.chatgpt.ChatGptAccountService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -126,7 +127,7 @@ public class MirrorController {
|
|
|
* 会话限制
|
|
|
*/
|
|
|
@RequestMapping("/gpt/conversation/limit")
|
|
|
- public void conversationLimit(@RequestParam(value = "isCar", defaultValue = "false") Boolean isCar, @RequestBody ConversationRequest conversationRequest) {
|
|
|
+ public ChatgptConversionLimitView conversationLimit(@RequestParam(value = "isCar", defaultValue = "false") Boolean isCar, @RequestBody ConversationRequest conversationRequest) {
|
|
|
//1.从request获取请求头Authorization 并取 值内 'Bearer ' 后的值为usertoken
|
|
|
String authorization = request.getHeader("Authorization");
|
|
|
String carid = request.getHeader("Carid");
|
|
|
@@ -143,34 +144,30 @@ public class MirrorController {
|
|
|
//text-davinci-002-render-sha 3.5
|
|
|
ConversationLimitResponse conversationLimitResponse = chatGptAccountService.conversationLimit(userToken, conversationRequest.getModel(), conversationRequest.getCarId(), user, isCar);
|
|
|
|
|
|
- OutputStream out = null;
|
|
|
- String messgae = "";
|
|
|
+
|
|
|
if (conversationLimitResponse.isLimited()) {
|
|
|
response.setStatus(429);
|
|
|
- String json = "{\"detail\":{\"message\":\"您的账号已达到GPT-4的使用上限。您现在可以继续使用默认模型,或者重试在\",\"code\":\"model_cap_exceeded\",\"clears_in\":2687}}";
|
|
|
- JSONObject res = new JSONObject(json);
|
|
|
- res.putOpt("clears_in", conversationLimitResponse.getNextAvailableTime() / 1000);
|
|
|
- messgae = res.toString();
|
|
|
+ //String json = "{\"detail\":{\"message\":\"您的账号已达到GPT-4的使用上限。您现在可以继续使用默认模型,或者重试在\",\"code\":\"model_cap_exceeded\",\"clears_in\":2687}}";
|
|
|
+ ChatgptConversionLimitView chatgptConversionLimitView = new ChatgptConversionLimitView();
|
|
|
+ ChatgptConversionLimitView.Detail detail = new ChatgptConversionLimitView.Detail();
|
|
|
+ detail.setMessage("您目前的套餐已达到GPT-4的使用上限。您现在可以继续使用默认模型,或者重试在");
|
|
|
+ detail.setCode("model_cap_exceeded");
|
|
|
+ detail.setClears_in(conversationLimitResponse.getNextAvailableTime() / 1000);
|
|
|
+ chatgptConversionLimitView.setDetail(detail);
|
|
|
+ return chatgptConversionLimitView;
|
|
|
} else {
|
|
|
response.setStatus(200);
|
|
|
}
|
|
|
//5.获取 conversationRequest 中的model 字段,判断是否为 gpt-4 如果为gpt-4 执行 查看是否达到限制方法
|
|
|
//6.如果达到限制,返回状态码 429 并返回文本 xxx
|
|
|
- try {
|
|
|
- out = response.getOutputStream();
|
|
|
- IoKit.write(messgae, out);
|
|
|
- } catch (Throwable e) {
|
|
|
- log.error("conversationLimit write response error", e);
|
|
|
- } finally {
|
|
|
- IoKit.close(out);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//记录提问时间,车次,标题和模型
|
|
|
TASK_EXECUTOR.execute(() -> {
|
|
|
chatGptAccountService.saveConversationRecord(userToken, conversationRequest);
|
|
|
});
|
|
|
- response.setStatus(200);
|
|
|
+
|
|
|
+ return new ChatgptConversionLimitView();
|
|
|
}
|
|
|
|
|
|
|