diff --git a/src/main/java/com/northtecom/visatrack/api/service/impl/WeChatService.java b/src/main/java/com/northtecom/visatrack/api/service/impl/WeChatService.java index 5bf5205..8e5afb8 100644 --- a/src/main/java/com/northtecom/visatrack/api/service/impl/WeChatService.java +++ b/src/main/java/com/northtecom/visatrack/api/service/impl/WeChatService.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.northtecom.visatrack.api.data.entity.WeChatCallState; import com.northtecom.visatrack.api.data.repository.*; import com.northtecom.visatrack.api.model.entity.wechat.WeChatMessage; +import com.northtecom.visatrack.api.util.OpenAiUtils; import com.ossez.wechat.common.exception.WxErrorException; import com.ossez.wechat.common.model.entity.WeChatOAuth2UserInfo; import com.northtecom.visatrack.api.util.WeChatUtils; @@ -48,6 +49,8 @@ public class WeChatService { private final WeChatOfficialAccountService weChatOfficialAccountService; private final WeChatUtils weChatUtils; + + private final OpenAiUtils openAiUtils; private final VisaCaseRepository visaCaseRepository; private final WeChatCallStateRepository weChatCallStateRepository; @@ -59,10 +62,11 @@ public class WeChatService { @Autowired - public WeChatService(WeChatOAuth2Service weChatOAuth2Service, WeChatOfficialAccountService weChatOfficialAccountService, WeChatUtils weChatUtils, VisaCaseRepository visaCaseRepository, WeChatCallStateRepository weChatCallStateRepository, UserRepository userRepository, CrawlService crawlService, VisaCheckeeCrawlDataRepository visaCheckeeCrawlDataRepository, ObjectMapper objectMapper) { + public WeChatService(WeChatOAuth2Service weChatOAuth2Service, WeChatOfficialAccountService weChatOfficialAccountService, WeChatUtils weChatUtils, OpenAiUtils openAiUtils, VisaCaseRepository visaCaseRepository, WeChatCallStateRepository weChatCallStateRepository, UserRepository userRepository, CrawlService crawlService, VisaCheckeeCrawlDataRepository visaCheckeeCrawlDataRepository, ObjectMapper objectMapper) { this.weChatOAuth2Service = weChatOAuth2Service; this.weChatOfficialAccountService = weChatOfficialAccountService; this.weChatUtils = weChatUtils; + this.openAiUtils = openAiUtils; this.visaCaseRepository = visaCaseRepository; this.weChatCallStateRepository = weChatCallStateRepository; this.userRepository = userRepository; @@ -191,7 +195,7 @@ public class WeChatService { // weChatMessage.setContent(contentGPT); // weChatMessage.setCreateTime(Instant.now().toEpochMilli()); - return "success";// WeChatUtils.covertToWeChatMessageXmlStr(weChatMessage); + return "success";// WeChatUtils.covertToWeChatMessageXmlStr(weChatMessage); } public void sendMessage(WeChatMessage weChatMessage) throws WxErrorException { @@ -207,7 +211,7 @@ public class WeChatService { private String callChatGPT(String content) { - OpenAiService service = new OpenAiService("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"); + OpenAiService service = new OpenAiService(OpenAiUtils.openAiConfMap.get(OpenAiUtils.OPENAI_TOKEN)); CompletionRequest completionRequest = new CompletionRequestBuilder().setModel("text-davinci-003") .setPrompt(content) .setMaxTokens(500) @@ -215,9 +219,6 @@ public class WeChatService { .setUser("testing") .setLogitBias(new HashMap<>()) .createCompletionRequest(); - - -// service.createCompletion(completionRequest).getChoices().size(); content = service.createCompletion(completionRequest).getChoices().get(0).getText(); return content; diff --git a/src/main/java/com/northtecom/visatrack/api/util/OpenAiUtils.java b/src/main/java/com/northtecom/visatrack/api/util/OpenAiUtils.java index d1d5de8..0c1a7e1 100644 --- a/src/main/java/com/northtecom/visatrack/api/util/OpenAiUtils.java +++ b/src/main/java/com/northtecom/visatrack/api/util/OpenAiUtils.java @@ -27,13 +27,12 @@ import java.util.Set; public class OpenAiUtils { public static final String OPENAI_PATH = "/openai"; - public static final String OPENAI_key = "key"; - public static final String DISCOURSE_API_USERNAME = "api_username"; - private Map openAiConfMap = new HashMap(); + public static final String OPENAI_TOKEN = "token"; + public static Map openAiConfMap = new HashMap(); @Autowired public OpenAiUtils(AwsUtils awsUtils) { - openAiConfMap.put(OPENAI_key, StringUtils.EMPTY); + openAiConfMap.put(OPENAI_TOKEN, StringUtils.EMPTY); openAiConfMap = awsUtils.getOpenAiParameterConfValueFromAWS(openAiConfMap);