Merge remote-tracking branch 'origin/master'
正在显示
6 个修改的文件
包含
69 行增加
和
3 行删除
| @@ -105,7 +105,7 @@ | @@ -105,7 +105,7 @@ | ||
| 105 | 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ | 105 | 生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/ |
| 106 | --> | 106 | --> |
| 107 | <classpathPrefix>lib/</classpathPrefix> | 107 | <classpathPrefix>lib/</classpathPrefix> |
| 108 | - <mainClass>com.zhonglai.luhui.alarm.AlarmApplication</mainClass> | 108 | + <mainClass>com.zhonglai.luhui.openai.OpenaiApplication</mainClass> |
| 109 | </manifest> | 109 | </manifest> |
| 110 | </archive> | 110 | </archive> |
| 111 | </configuration> | 111 | </configuration> |
| 1 | package com.zhonglai.luhui.openai.controller; | 1 | package com.zhonglai.luhui.openai.controller; |
| 2 | 2 | ||
| 3 | +import com.ruoyi.common.core.controller.BaseController; | ||
| 4 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 3 | import com.ruoyi.common.core.domain.Message; | 5 | import com.ruoyi.common.core.domain.Message; |
| 4 | import com.ruoyi.common.core.domain.MessageCode; | 6 | import com.ruoyi.common.core.domain.MessageCode; |
| 7 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 8 | +import com.ruoyi.system.service.PublicService; | ||
| 5 | import com.theokanning.openai.completion.CompletionChoice; | 9 | import com.theokanning.openai.completion.CompletionChoice; |
| 6 | import com.zhonglai.luhui.openai.utils.OpenAiUtils; | 10 | import com.zhonglai.luhui.openai.utils.OpenAiUtils; |
| 7 | import io.swagger.annotations.Api; | 11 | import io.swagger.annotations.Api; |
| 8 | import io.swagger.annotations.ApiOperation; | 12 | import io.swagger.annotations.ApiOperation; |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | import org.springframework.web.bind.annotation.*; | 14 | import org.springframework.web.bind.annotation.*; |
| 10 | 15 | ||
| 16 | +import javax.servlet.http.HttpServletRequest; | ||
| 17 | +import javax.servlet.http.HttpSession; | ||
| 11 | import java.util.List; | 18 | import java.util.List; |
| 12 | 19 | ||
| 13 | @Api(tags = "chatGPT接口") | 20 | @Api(tags = "chatGPT接口") |
| 14 | @RestController | 21 | @RestController |
| 15 | @RequestMapping("/chatgpt") | 22 | @RequestMapping("/chatgpt") |
| 16 | -public class ChatGPTController { | 23 | +public class ChatGPTController extends BaseController { |
| 24 | + @Autowired | ||
| 25 | + private PublicService publicService; | ||
| 26 | + | ||
| 17 | @ApiOperation("与AI机器进行聊天") | 27 | @ApiOperation("与AI机器进行聊天") |
| 18 | @RequestMapping(value = "/aiChatbot",method = RequestMethod.POST) | 28 | @RequestMapping(value = "/aiChatbot",method = RequestMethod.POST) |
| 19 | - public Message aiChatbot(@RequestBody String data) | 29 | + public Message aiChatbot(HttpServletRequest httpServletRequest, @RequestBody String data) |
| 20 | { | 30 | { |
| 31 | + HttpSession session = httpServletRequest.getSession(); | ||
| 32 | + if(session!=null) | ||
| 33 | + { | ||
| 34 | + logger.info("{}生成聊天会话:",session.getId()); | ||
| 35 | + List<CompletionChoice> list = OpenAiUtils.getAiChatbot(data,session.getId()); | ||
| 36 | + int i=0; | ||
| 37 | + for (CompletionChoice completionChoice:list) | ||
| 38 | + { | ||
| 39 | + i+=completionChoice.getText().length(); | ||
| 40 | + } | ||
| 41 | + logger.info("{}请求的流量:{},回复的流量:{}",session.getId(),data.length(),i); | ||
| 42 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,list); | ||
| 43 | + } | ||
| 21 | List<CompletionChoice> list = OpenAiUtils.getAiChatbot(data); | 44 | List<CompletionChoice> list = OpenAiUtils.getAiChatbot(data); |
| 22 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,list); | 45 | return new Message(MessageCode.DEFAULT_SUCCESS_CODE,list); |
| 23 | } | 46 | } |
| 47 | + | ||
| 24 | } | 48 | } |
| @@ -24,6 +24,9 @@ public class OpenAi { | @@ -24,6 +24,9 @@ public class OpenAi { | ||
| 24 | // 停用词 | 24 | // 停用词 |
| 25 | String stop; | 25 | String stop; |
| 26 | 26 | ||
| 27 | + // 用户 | ||
| 28 | + String user; | ||
| 29 | + | ||
| 27 | public OpenAi() { | 30 | public OpenAi() { |
| 28 | } | 31 | } |
| 29 | 32 | ||
| @@ -41,6 +44,14 @@ public class OpenAi { | @@ -41,6 +44,14 @@ public class OpenAi { | ||
| 41 | this.stop = stop; | 44 | this.stop = stop; |
| 42 | } | 45 | } |
| 43 | 46 | ||
| 47 | + public String getUser() { | ||
| 48 | + return user; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setUser(String user) { | ||
| 52 | + this.user = user; | ||
| 53 | + } | ||
| 54 | + | ||
| 44 | public String getId() { | 55 | public String getId() { |
| 45 | return id; | 56 | return id; |
| 46 | } | 57 | } |
| @@ -90,6 +90,10 @@ public class OpenAiUtils { | @@ -90,6 +90,10 @@ public class OpenAiUtils { | ||
| 90 | .topP(openAi.getTopP()) | 90 | .topP(openAi.getTopP()) |
| 91 | .frequencyPenalty(openAi.getFrequencyPenalty()) | 91 | .frequencyPenalty(openAi.getFrequencyPenalty()) |
| 92 | .presencePenalty(openAi.getPresencePenalty()); | 92 | .presencePenalty(openAi.getPresencePenalty()); |
| 93 | + if(!StringUtils.isEmpty(openAi.getUser())) | ||
| 94 | + { | ||
| 95 | + builder.user(openAi.getUser()); | ||
| 96 | + } | ||
| 93 | if (!StringUtils.isEmpty(openAi.getStop())) { | 97 | if (!StringUtils.isEmpty(openAi.getStop())) { |
| 94 | builder.stop(Arrays.asList(openAi.getStop().split(","))); | 98 | builder.stop(Arrays.asList(openAi.getStop().split(","))); |
| 95 | } | 99 | } |
| @@ -611,7 +615,18 @@ public class OpenAiUtils { | @@ -611,7 +615,18 @@ public class OpenAiUtils { | ||
| 611 | * @return | 615 | * @return |
| 612 | */ | 616 | */ |
| 613 | public static List<CompletionChoice> getAiChatbot(String question) { | 617 | public static List<CompletionChoice> getAiChatbot(String question) { |
| 618 | + return getAiChatbot(question,null); | ||
| 619 | + } | ||
| 620 | + | ||
| 621 | + /** | ||
| 622 | + * 与AI机器进行聊天 | ||
| 623 | + * | ||
| 624 | + * @param question | ||
| 625 | + * @return | ||
| 626 | + */ | ||
| 627 | + public static List<CompletionChoice> getAiChatbot(String question,String user) { | ||
| 614 | OpenAi openAi = PARMS.get("OpenAi44"); | 628 | OpenAi openAi = PARMS.get("OpenAi44"); |
| 629 | + openAi.setUser(user); | ||
| 615 | return getAiResult(openAi, String.format(openAi.getPrompt(), question)); | 630 | return getAiResult(openAi, String.format(openAi.getPrompt(), question)); |
| 616 | } | 631 | } |
| 617 | 632 |
| @@ -33,6 +33,17 @@ public class RuoYiConfig | @@ -33,6 +33,17 @@ public class RuoYiConfig | ||
| 33 | /** 验证码类型 */ | 33 | /** 验证码类型 */ |
| 34 | private static String captchaType; | 34 | private static String captchaType; |
| 35 | 35 | ||
| 36 | + /** root */ | ||
| 37 | + private static String root; | ||
| 38 | + | ||
| 39 | + public static String getRoot() { | ||
| 40 | + return root; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public static void setRoot(String root) { | ||
| 44 | + RuoYiConfig.root = root; | ||
| 45 | + } | ||
| 46 | + | ||
| 36 | public String getName() | 47 | public String getName() |
| 37 | { | 48 | { |
| 38 | return name; | 49 | return name; |
| @@ -140,6 +140,11 @@ public class Constants | @@ -140,6 +140,11 @@ public class Constants | ||
| 140 | public static final String RESOURCE_PREFIX = "/profile"; | 140 | public static final String RESOURCE_PREFIX = "/profile"; |
| 141 | 141 | ||
| 142 | /** | 142 | /** |
| 143 | + * 资源映射路径 前缀 | ||
| 144 | + */ | ||
| 145 | + public static final String ROOT = "/**"; | ||
| 146 | + | ||
| 147 | + /** | ||
| 143 | * RMI 远程方法调用 | 148 | * RMI 远程方法调用 |
| 144 | */ | 149 | */ |
| 145 | public static final String LOOKUP_RMI = "rmi:"; | 150 | public static final String LOOKUP_RMI = "rmi:"; |
-
请 注册 或 登录 后发表评论