正在显示
13 个修改的文件
包含
154 行增加
和
78 行删除
| @@ -7,8 +7,8 @@ import org.springframework.context.annotation.ComponentScan; | @@ -7,8 +7,8 @@ import org.springframework.context.annotation.ComponentScan; | ||
| 7 | 7 | ||
| 8 | @ComponentScan(basePackages = { | 8 | @ComponentScan(basePackages = { |
| 9 | "com.zhonglai.luhui.config", | 9 | "com.zhonglai.luhui.config", |
| 10 | + "com.zhonglai.luhui.controller", | ||
| 10 | } | 11 | } |
| 11 | - | ||
| 12 | ) | 12 | ) |
| 13 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | 13 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) |
| 14 | public class ChatgptApplication { | 14 | public class ChatgptApplication { |
| 1 | package com.zhonglai.luhui.controller; | 1 | package com.zhonglai.luhui.controller; |
| 2 | 2 | ||
| 3 | +import cn.hutool.http.HttpRequest; | ||
| 3 | import cn.hutool.http.HttpUtil; | 4 | import cn.hutool.http.HttpUtil; |
| 5 | +import cn.hutool.json.JSONUtil; | ||
| 4 | import com.alibaba.fastjson.JSONObject; | 6 | import com.alibaba.fastjson.JSONObject; |
| 5 | -import com.zhonglai.luhui.dto.ChatGPTApiDto; | ||
| 6 | -import com.zhonglai.luhui.dto.ChatRoomMessages; | ||
| 7 | -import com.zhonglai.luhui.dto.CompletionResult3_5; | 7 | +import com.zhonglai.luhui.dto.*; |
| 8 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
| 9 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
| 10 | import org.apache.commons.lang3.StringUtils; | 10 | import org.apache.commons.lang3.StringUtils; |
| 11 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
| 12 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
| 13 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 14 | -import org.springframework.web.bind.annotation.RequestBody; | ||
| 15 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | -import org.springframework.web.bind.annotation.RestController; | 13 | +import org.springframework.web.bind.annotation.*; |
| 17 | 14 | ||
| 18 | import javax.servlet.http.HttpServletResponse; | 15 | import javax.servlet.http.HttpServletResponse; |
| 19 | import java.io.IOException; | 16 | import java.io.IOException; |
| 20 | import java.io.PrintWriter; | 17 | import java.io.PrintWriter; |
| 18 | +import java.util.HashMap; | ||
| 21 | import java.util.List; | 19 | import java.util.List; |
| 20 | +import java.util.Map; | ||
| 22 | 21 | ||
| 23 | @Api(tags = "chatGPT接口") | 22 | @Api(tags = "chatGPT接口") |
| 24 | @RestController | 23 | @RestController |
| @@ -28,29 +27,72 @@ public class ChatGPTApiController { | @@ -28,29 +27,72 @@ public class ChatGPTApiController { | ||
| 28 | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | 27 | protected final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 29 | 28 | ||
| 30 | @ApiOperation(value = "测试") | 29 | @ApiOperation(value = "测试") |
| 31 | - @GetMapping("/sendMessage") | ||
| 32 | - public void sendMessage(HttpServletResponse response, @RequestBody ChatGPTApiDto chatGPTApiDto) | 30 | + @PostMapping("/sendMessage") |
| 31 | + public String sendMessage(HttpServletResponse response, @RequestBody ChatGPTApiDto chatGPTApiDto) | ||
| 33 | { | 32 | { |
| 33 | + int timeout = 3000000; | ||
| 34 | // 设置响应内容类型和编码 | 34 | // 设置响应内容类型和编码 |
| 35 | response.setContentType("text/html;charset=UTF-8"); | 35 | response.setContentType("text/html;charset=UTF-8"); |
| 36 | + JSONObject jsonObject = new JSONObject(); | ||
| 37 | + jsonObject.put("model","gpt-3.5-turbo-0301"); | ||
| 38 | + jsonObject.put("messages",chatGPTApiDto.getMessageList()); | ||
| 39 | + | ||
| 40 | +// String domainName = "api.openai.com"; | ||
| 41 | +// String apiDomain = "openai.yu2le.com/api"; | ||
| 42 | + String domainName = "chatgpt.njlaikun.com"; | ||
| 43 | + String apiDomain = "localhost:8082"; | ||
| 36 | 44 | ||
| 37 | - String str = ""; | 45 | + Map<String,String> map = new HashMap<>(); |
| 46 | + if(chatGPTApiDto.getIsfree()) | ||
| 47 | + { | ||
| 48 | + map.put("Authorization","Bearer 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"); | ||
| 49 | + }else{ | ||
| 50 | + map.put("Authorization","Bearer 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"); | ||
| 51 | + } | ||
| 52 | + map.put("Content-Type","application/json"); | ||
| 53 | + String str = HttpRequest.post("https://"+domainName+"/v1/chat/completions").setReadTimeout(timeout).timeout(timeout).addHeaders(map).body(jsonObject.toString()).execute().body(); | ||
| 54 | + logger.info("返回的数据:{}",str); | ||
| 55 | + if(JSONUtil.isTypeJSONObject(str)) | ||
| 56 | + { | ||
| 57 | + CompletionResult3_5 completionResult = JSONObject.parseObject(str, CompletionResult3_5.class); | ||
| 58 | + List<CompletionChoice3_5> list = completionResult.getChoices(); | ||
| 59 | + if(null != list && list.size() != 0) | ||
| 60 | + { | ||
| 61 | + StringBuffer stringBuffer = new StringBuffer(); | ||
| 62 | + for (CompletionChoice3_5 completionChoice3_5:list) | ||
| 63 | + { | ||
| 64 | + stringBuffer.append(completionChoice3_5.getMessage().getContent()); | ||
| 65 | + completionChoice3_5.getMessage().setContent(null); | ||
| 66 | + } | ||
| 67 | + completionResult.setContentLength( stringBuffer.length()); | ||
| 68 | + completionResult.setRoom_id(chatGPTApiDto.getRoom_id()); | ||
| 69 | + completionResult.setGptMessage_id(chatGPTApiDto.getGptMessage_id()); | ||
| 70 | + completionResult.setUser_id(chatGPTApiDto.getUser_id()); | ||
| 71 | + //通知更新用户信息 | ||
| 72 | + String noticestr = JSONObject.toJSONString(completionResult); | ||
| 73 | + String rstr = HttpUtil.post("http://"+apiDomain+"/chatGPTStream/upUserFlowPacketRemain",noticestr); | ||
| 74 | + logger.info("修改返回的数据:{}",rstr); | ||
| 75 | + //返回结果字符串 | ||
| 76 | + return stringBuffer.toString(); | ||
| 77 | +// writeMessage(stringBuffer,response); | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + return str; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + private void writeMessage(StringBuffer stringBuffer,HttpServletResponse response) | ||
| 84 | + { | ||
| 38 | PrintWriter out = null; | 85 | PrintWriter out = null; |
| 39 | try { | 86 | try { |
| 40 | out = response.getWriter(); | 87 | out = response.getWriter(); |
| 41 | //验证验证码 | 88 | //验证验证码 |
| 42 | - if(StringUtils.isNotEmpty(str)) | 89 | + if(StringUtils.isNotEmpty(stringBuffer)) |
| 43 | { | 90 | { |
| 44 | - for(int i=0;i<str.length();i++) | 91 | + for(int i=0;i<stringBuffer.length();i++) |
| 45 | { | 92 | { |
| 46 | - char c = str.charAt(i); | 93 | + char c = stringBuffer.charAt(i); |
| 47 | out.write(c); | 94 | out.write(c); |
| 48 | out.flush(); // 立即将字符输出到客户端 | 95 | out.flush(); // 立即将字符输出到客户端 |
| 49 | - try { | ||
| 50 | - Thread.sleep(1000); | ||
| 51 | - } catch (InterruptedException e) { | ||
| 52 | - throw new RuntimeException(e); | ||
| 53 | - } | ||
| 54 | } | 96 | } |
| 55 | } | 97 | } |
| 56 | } catch (IOException e) { | 98 | } catch (IOException e) { |
| @@ -63,33 +105,4 @@ public class ChatGPTApiController { | @@ -63,33 +105,4 @@ public class ChatGPTApiController { | ||
| 63 | } | 105 | } |
| 64 | } | 106 | } |
| 65 | 107 | ||
| 66 | - | ||
| 67 | - private CompletionResult3_5 sendGPTAi(List<ChatRoomMessages> messageList) | ||
| 68 | - { | ||
| 69 | - logger.info("请求内容:{}",messageList); | ||
| 70 | - JSONObject jsonObject = new JSONObject(); | ||
| 71 | - jsonObject.put("model","gpt-3.5-turbo-0301"); | ||
| 72 | - jsonObject.put("messages",messageList); | ||
| 73 | - String str = HttpUtil.post("https://chatgpt.njlaikun.com/v1/chat/completions",jsonObject.toString()); | ||
| 74 | - logger.info("返回的数据:{}",str); | ||
| 75 | - CompletionResult3_5 completionResult = JSONObject.parseObject(str, CompletionResult3_5.class); | ||
| 76 | - return completionResult; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - /** | ||
| 80 | - * 免费接口 | ||
| 81 | - * @param messageList | ||
| 82 | - * @return | ||
| 83 | - */ | ||
| 84 | - private CompletionResult3_5 sendFreeGPTAi(List<ChatRoomMessages> messageList) | ||
| 85 | - { | ||
| 86 | - logger.info("请求内容:{}",messageList); | ||
| 87 | - JSONObject jsonObject = new JSONObject(); | ||
| 88 | - jsonObject.put("model","gpt-3.5-turbo-0301"); | ||
| 89 | - jsonObject.put("messages",messageList); | ||
| 90 | - String str = HttpUtil.post("https://free.chatgpt.njlaikun.com/v1/chat/completions",jsonObject.toString()); | ||
| 91 | - logger.info("返回的数据:{}",str); | ||
| 92 | - CompletionResult3_5 completionResult = JSONObject.parseObject(str, CompletionResult3_5.class); | ||
| 93 | - return completionResult; | ||
| 94 | - } | ||
| 95 | } | 108 | } |
| @@ -13,6 +13,24 @@ public class CompletionResult3_5 { | @@ -13,6 +13,24 @@ public class CompletionResult3_5 { | ||
| 13 | private String room_id; | 13 | private String room_id; |
| 14 | private Integer gptMessage_id; | 14 | private Integer gptMessage_id; |
| 15 | 15 | ||
| 16 | + private Integer contentLength; | ||
| 17 | + | ||
| 18 | + public Integer getContentLength() { | ||
| 19 | + return contentLength; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public void setContentLength(Integer contentLength) { | ||
| 23 | + this.contentLength = contentLength; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public String getRoom_id() { | ||
| 27 | + return room_id; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public void setRoom_id(String room_id) { | ||
| 31 | + this.room_id = room_id; | ||
| 32 | + } | ||
| 33 | + | ||
| 16 | public Integer getGptMessage_id() { | 34 | public Integer getGptMessage_id() { |
| 17 | return gptMessage_id; | 35 | return gptMessage_id; |
| 18 | } | 36 | } |
| @@ -25,7 +25,6 @@ import org.springframework.context.annotation.FilterType; | @@ -25,7 +25,6 @@ import org.springframework.context.annotation.FilterType; | ||
| 25 | "com.zhonglai.luhui.openai.service", | 25 | "com.zhonglai.luhui.openai.service", |
| 26 | "com.zhonglai.luhui.openai.controller" | 26 | "com.zhonglai.luhui.openai.controller" |
| 27 | } | 27 | } |
| 28 | - | ||
| 29 | ) | 28 | ) |
| 30 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) | 29 | @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) |
| 31 | public class OpenaiApplication { | 30 | public class OpenaiApplication { |
| @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; | ||
| 5 | import com.ruoyi.common.core.controller.BaseController; | 5 | import com.ruoyi.common.core.controller.BaseController; |
| 6 | import com.ruoyi.common.core.domain.AjaxResult; | 6 | import com.ruoyi.common.core.domain.AjaxResult; |
| 7 | import com.ruoyi.common.utils.DateUtils; | 7 | import com.ruoyi.common.utils.DateUtils; |
| 8 | +import com.ruoyi.common.utils.html.HttpUtils; | ||
| 8 | import com.ruoyi.system.login.dto.OpenAiLoginUser; | 9 | import com.ruoyi.system.login.dto.OpenAiLoginUser; |
| 9 | import com.ruoyi.system.login.dto.OpenAiUserInfo; | 10 | import com.ruoyi.system.login.dto.OpenAiUserInfo; |
| 10 | import com.ruoyi.system.service.PublicService; | 11 | import com.ruoyi.system.service.PublicService; |
| @@ -25,10 +26,11 @@ import org.springframework.web.bind.annotation.RestController; | @@ -25,10 +26,11 @@ import org.springframework.web.bind.annotation.RestController; | ||
| 25 | import javax.servlet.http.HttpServletRequest; | 26 | import javax.servlet.http.HttpServletRequest; |
| 26 | import javax.servlet.http.HttpServletResponse; | 27 | import javax.servlet.http.HttpServletResponse; |
| 27 | import javax.servlet.http.HttpSession; | 28 | import javax.servlet.http.HttpSession; |
| 28 | -import java.io.IOException; | ||
| 29 | -import java.io.InputStream; | ||
| 30 | -import java.io.PrintWriter; | 29 | +import java.io.*; |
| 31 | import java.math.BigDecimal; | 30 | import java.math.BigDecimal; |
| 31 | +import java.net.HttpURLConnection; | ||
| 32 | +import java.net.URL; | ||
| 33 | +import java.net.URLConnection; | ||
| 32 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
| 33 | import java.util.List; | 35 | import java.util.List; |
| 34 | import java.util.Optional; | 36 | import java.util.Optional; |
| @@ -44,7 +46,6 @@ public class ChatGPTStreamController extends BaseController { | @@ -44,7 +46,6 @@ public class ChatGPTStreamController extends BaseController { | ||
| 44 | @Autowired | 46 | @Autowired |
| 45 | private VipServiceImpl vipService; | 47 | private VipServiceImpl vipService; |
| 46 | @ApiOperation(value = "chatgpt3.5",notes = "上下文关联,要实现上下问关联就需要记录整个聊天的提问记录,目前只支持相同session的上下文关联,就是说,如果聊天页面关闭以后再打开,是没有上下文关联的") | 48 | @ApiOperation(value = "chatgpt3.5",notes = "上下文关联,要实现上下问关联就需要记录整个聊天的提问记录,目前只支持相同session的上下文关联,就是说,如果聊天页面关闭以后再打开,是没有上下文关联的") |
| 47 | - @Transactional | ||
| 48 | @RequestMapping(value = "/chatgptV3_5",method = RequestMethod.POST) | 49 | @RequestMapping(value = "/chatgptV3_5",method = RequestMethod.POST) |
| 49 | public void chatgptV3_5(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody ChatgptMessageDto chatgptMessageDto) throws IOException { | 50 | public void chatgptV3_5(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, @RequestBody ChatgptMessageDto chatgptMessageDto) throws IOException { |
| 50 | //跟进用户信息生成入口参数 | 51 | //跟进用户信息生成入口参数 |
| @@ -93,35 +94,64 @@ public class ChatGPTStreamController extends BaseController { | @@ -93,35 +94,64 @@ public class ChatGPTStreamController extends BaseController { | ||
| 93 | gptMessage.setSend_content(chatRoomMessages.getContent()); | 94 | gptMessage.setSend_content(chatRoomMessages.getContent()); |
| 94 | gptMessage.setCreate_time(DateUtils.getNowTimeMilly()); | 95 | gptMessage.setCreate_time(DateUtils.getNowTimeMilly()); |
| 95 | publicService.insertToTable(gptMessage,"`lk_openai`.`gpt_message`"); | 96 | publicService.insertToTable(gptMessage,"`lk_openai`.`gpt_message`"); |
| 96 | - //获取返回参数 | ||
| 97 | 97 | ||
| 98 | + //获取返回参数 | ||
| 98 | ChatGPTApiDto chatGPTApiDto = new ChatGPTApiDto(); | 99 | ChatGPTApiDto chatGPTApiDto = new ChatGPTApiDto(); |
| 99 | chatGPTApiDto.setGptMessage_id(gptMessage.getId()); | 100 | chatGPTApiDto.setGptMessage_id(gptMessage.getId()); |
| 100 | chatGPTApiDto.setMessageList(messageList); | 101 | chatGPTApiDto.setMessageList(messageList); |
| 101 | chatGPTApiDto.setUser_id(user_id); | 102 | chatGPTApiDto.setUser_id(user_id); |
| 102 | chatGPTApiDto.setRoom_id(room_id); | 103 | chatGPTApiDto.setRoom_id(room_id); |
| 103 | chatGPTApiDto.setIsfree(vipService.isfree(openAiUserInfo.getVip_level())); | 104 | chatGPTApiDto.setIsfree(vipService.isfree(openAiUserInfo.getVip_level())); |
| 104 | - HttpUtil.post("https://chatgpt.njlaikun.com/chatGPTApi/sendMessage", JSONObject.toJSONString(chatGPTApiDto)); | ||
| 105 | 105 | ||
| 106 | - Request request = new Request.Builder() | ||
| 107 | - .url("https://chatgpt.njlaikun.com/chatGPTApi/sendMessage") | ||
| 108 | - .post(okhttp3.RequestBody.create(JSONObject.toJSONString(chatGPTApiDto), MediaType.parse("application/json;"))) | ||
| 109 | - .build(); | ||
| 110 | - OkHttpClient okHttpClient = new OkHttpClient(); | ||
| 111 | - okHttpClient.newCall(request).enqueue(new Callback() { | ||
| 112 | - @Override | ||
| 113 | - public void onFailure(@NotNull Call call, @NotNull IOException e) { | ||
| 114 | 106 | ||
| 107 | + PrintWriter pout = null; | ||
| 108 | + BufferedReader in = null; | ||
| 109 | + try { | ||
| 110 | + URL url = new URL("http://localhost:8086/chatGPTApi/sendMessage"); | ||
| 111 | + // 打开和URL之间的连接 | ||
| 112 | + URLConnection conn = url.openConnection(); | ||
| 113 | + // 设置通用的请求属性 | ||
| 114 | + conn.setRequestProperty("accept", "*/*"); | ||
| 115 | + conn.setRequestProperty("connection", "Keep-Alive"); | ||
| 116 | + conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); | ||
| 117 | + // 发送POST请求必须设置如下两行 | ||
| 118 | + conn.setDoOutput(true); | ||
| 119 | + conn.setDoInput(true); | ||
| 120 | + // 获取URLConnection对象对应的输出流 | ||
| 121 | + pout = new PrintWriter(conn.getOutputStream()); | ||
| 122 | + // 发送请求参数 | ||
| 123 | + pout.print(JSONObject.toJSONString(chatGPTApiDto)); | ||
| 124 | + // flush输出流的缓冲 | ||
| 125 | + pout.flush(); | ||
| 126 | + | ||
| 127 | + // 定义BufferedReader输入流来读取URL的响应 | ||
| 128 | + in = new BufferedReader(new InputStreamReader(conn.getInputStream())); | ||
| 129 | + int character; | ||
| 130 | + while ((character = in.read()) != -1) { | ||
| 131 | + out.write((char) character); | ||
| 132 | + out.flush(); | ||
| 115 | } | 133 | } |
| 116 | - | ||
| 117 | - @Override | ||
| 118 | - public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { | ||
| 119 | - InputStream inputStream = response.body().byteStream(); | 134 | + } catch (Exception e) { |
| 135 | + System.out.println("发送 POST 请求出现异常!" + e); | ||
| 136 | + e.printStackTrace(); | ||
| 137 | + } | ||
| 138 | + // 使用finally块来关闭输出流、输入流 | ||
| 139 | + finally { | ||
| 140 | + try { | ||
| 141 | + if (!(out == null)) { | ||
| 142 | + out.close(); | ||
| 120 | } | 143 | } |
| 121 | - }); | 144 | + if (in != null) { |
| 145 | + in.close(); | ||
| 146 | + } | ||
| 147 | + } catch (IOException ex) { | ||
| 148 | + ex.printStackTrace(); | ||
| 149 | + } | ||
| 150 | + } | ||
| 151 | + | ||
| 122 | } | 152 | } |
| 123 | 153 | ||
| 124 | - @ApiOperation(value = "历史记录",notes = "默认获取最新5条记录") | 154 | + @ApiOperation(value = "更新消息状态") |
| 125 | @Transactional | 155 | @Transactional |
| 126 | @RequestMapping(value = "/upUserFlowPacketRemain",method = RequestMethod.POST) | 156 | @RequestMapping(value = "/upUserFlowPacketRemain",method = RequestMethod.POST) |
| 127 | public AjaxResult upUserFlowPacketRemain(@RequestBody CompletionResult3_5 completionResult3_5 ) | 157 | public AjaxResult upUserFlowPacketRemain(@RequestBody CompletionResult3_5 completionResult3_5 ) |
| @@ -132,14 +162,13 @@ public class ChatGPTStreamController extends BaseController { | @@ -132,14 +162,13 @@ public class ChatGPTStreamController extends BaseController { | ||
| 132 | if(null != list3_5 && list3_5.size() !=0 ) | 162 | if(null != list3_5 && list3_5.size() !=0 ) |
| 133 | { | 163 | { |
| 134 | GptMessage gptMessage = new GptMessage(); | 164 | GptMessage gptMessage = new GptMessage(); |
| 135 | - gptMessage.setSend_size(0); | ||
| 136 | gptMessage.setPrompt_tokens(0l); | 165 | gptMessage.setPrompt_tokens(0l); |
| 137 | gptMessage.setCompletion_tokens(0l); | 166 | gptMessage.setCompletion_tokens(0l); |
| 138 | gptMessage.setTotal_tokens(0l); | 167 | gptMessage.setTotal_tokens(0l); |
| 139 | gptMessage.setMessage_size(0); | 168 | gptMessage.setMessage_size(0); |
| 169 | + gptMessage.setSend_size(completionResult3_5.getContentLength()); | ||
| 140 | for (CompletionChoice3_5 completionChoice:list3_5) | 170 | for (CompletionChoice3_5 completionChoice:list3_5) |
| 141 | { | 171 | { |
| 142 | - gptMessage.setSend_size(gptMessage.getSend_size()+gptMessage.getSend_content().length()); | ||
| 143 | //统计代币 | 172 | //统计代币 |
| 144 | gptMessage.setCompletion_tokens(gptMessage.getCompletion_tokens()+usage.getCompletionTokens()); | 173 | gptMessage.setCompletion_tokens(gptMessage.getCompletion_tokens()+usage.getCompletionTokens()); |
| 145 | gptMessage.setPrompt_tokens(gptMessage.getPrompt_tokens()+usage.getPromptTokens()); | 174 | gptMessage.setPrompt_tokens(gptMessage.getPrompt_tokens()+usage.getPromptTokens()); |
| @@ -16,7 +16,15 @@ public class CompletionResult3_5 { | @@ -16,7 +16,15 @@ public class CompletionResult3_5 { | ||
| 16 | private Integer user_id; | 16 | private Integer user_id; |
| 17 | private String room_id; | 17 | private String room_id; |
| 18 | private Integer gptMessage_id; | 18 | private Integer gptMessage_id; |
| 19 | + private Integer contentLength; | ||
| 19 | 20 | ||
| 21 | + public Integer getContentLength() { | ||
| 22 | + return contentLength; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public void setContentLength(Integer contentLength) { | ||
| 26 | + this.contentLength = contentLength; | ||
| 27 | + } | ||
| 20 | public Integer getGptMessage_id() { | 28 | public Integer getGptMessage_id() { |
| 21 | return gptMessage_id; | 29 | return gptMessage_id; |
| 22 | } | 30 | } |
| @@ -28,7 +28,8 @@ public class ChatgptDetailsServiceImpl implements UserDetailsService { | @@ -28,7 +28,8 @@ public class ChatgptDetailsServiceImpl implements UserDetailsService { | ||
| 28 | adduser.setPhone(username); | 28 | adduser.setPhone(username); |
| 29 | adduser.setCreate_time(DateUtils.getNowTimeMilly()); | 29 | adduser.setCreate_time(DateUtils.getNowTimeMilly()); |
| 30 | adduser.setNickname(username); | 30 | adduser.setNickname(username); |
| 31 | - adduser.setVip_level(0); | 31 | + adduser.setVip_level(3); |
| 32 | + adduser.setVip_level_end_time(adduser.getCreate_time()+2592000); //30天 | ||
| 32 | adduser.setFlow_packet_remain(10000); //默认给1w免费额度 | 33 | adduser.setFlow_packet_remain(10000); //默认给1w免费额度 |
| 33 | adduser.setFlow_packet_total(10000); | 34 | adduser.setFlow_packet_total(10000); |
| 34 | adduser.setState(1); | 35 | adduser.setState(1); |
| @@ -49,8 +49,8 @@ public class VipServiceImpl { | @@ -49,8 +49,8 @@ public class VipServiceImpl { | ||
| 49 | 49 | ||
| 50 | chargingList.add(0,true); | 50 | chargingList.add(0,true); |
| 51 | chargingList.add(1,true); | 51 | chargingList.add(1,true); |
| 52 | - chargingList.add(2,false); | ||
| 53 | - chargingList.add(3,false); | 52 | + chargingList.add(2,true); |
| 53 | + chargingList.add(3,true); | ||
| 54 | chargingList.add(4,false); | 54 | chargingList.add(4,false); |
| 55 | chargingList.add(5,false); | 55 | chargingList.add(5,false); |
| 56 | 56 |
| 1 | -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 获取ip地址开关 addressEnabled: false # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8082 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-chat-gpt send-tags: 1 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/openAiUserLogin/* chatgpt: token: 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 timeout: 5000 | ||
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 获取ip地址开关 addressEnabled: false # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8082 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-chat-gpt send-tags: 1 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/openAiUserLogin/*,/chatGPTStream/upUserFlowPacketRemain chatgpt: token: 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 timeout: 5000 |
| @@ -137,6 +137,7 @@ public class PublicSQL { | @@ -137,6 +137,7 @@ public class PublicSQL { | ||
| 137 | { | 137 | { |
| 138 | Object object = map.get("object"); | 138 | Object object = map.get("object"); |
| 139 | String tableName = changTableNameFromObject(object); | 139 | String tableName = changTableNameFromObject(object); |
| 140 | + String primaryKey = (String) map.get("primaryKey"); | ||
| 140 | if(map.containsKey("tableName")) | 141 | if(map.containsKey("tableName")) |
| 141 | { | 142 | { |
| 142 | tableName = map.get("tableName").toString(); | 143 | tableName = map.get("tableName").toString(); |
| @@ -22,7 +22,8 @@ public interface PublicMapper { | @@ -22,7 +22,8 @@ public interface PublicMapper { | ||
| 22 | * 指定表名添加 | 22 | * 指定表名添加 |
| 23 | */ | 23 | */ |
| 24 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") | 24 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") |
| 25 | - int insertToTable(@Param("object") Object object,@Param("tableName") String tableName); | 25 | + @Options(useGeneratedKeys = true, keyProperty = "object.id") |
| 26 | + int insertToTable(@Param("object") Object object,@Param("tableName") String tableName,@Param("primaryKey") String primaryKey); | ||
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * 添加对象集合 | 29 | * 添加对象集合 |
| @@ -15,8 +15,9 @@ public interface PublicService { | @@ -15,8 +15,9 @@ public interface PublicService { | ||
| 15 | /** | 15 | /** |
| 16 | * 指定表名添加 | 16 | * 指定表名添加 |
| 17 | */ | 17 | */ |
| 18 | - int insertToTable(Object object, String tableName); | 18 | + int insertToTable(Object object, String tableName,String primaryKey); |
| 19 | 19 | ||
| 20 | + int insertToTable(Object object, String tableName); | ||
| 20 | /** | 21 | /** |
| 21 | * 添加对象集合 | 22 | * 添加对象集合 |
| 22 | */ | 23 | */ |
| @@ -30,7 +30,12 @@ public class PublicServiceImpl implements PublicService { | @@ -30,7 +30,12 @@ public class PublicServiceImpl implements PublicService { | ||
| 30 | */ | 30 | */ |
| 31 | public int insertToTable(Object object, String tableName) | 31 | public int insertToTable(Object object, String tableName) |
| 32 | { | 32 | { |
| 33 | - return publicMapper.insertToTable(object,tableName); | 33 | + return publicMapper.insertToTable(object,tableName,"id"); |
| 34 | + } | ||
| 35 | + | ||
| 36 | + public int insertToTable(Object object, String tableName,String primaryKey) | ||
| 37 | + { | ||
| 38 | + return publicMapper.insertToTable(object,tableName,primaryKey); | ||
| 34 | } | 39 | } |
| 35 | 40 | ||
| 36 | /** | 41 | /** |
-
请 注册 或 登录 后发表评论