USVT-137 把 ChatGPT 的 Token 放到 AWS 上
This commit is contained in:
parent
755f9090f2
commit
fb2c6e95d5
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.northtecom.visatrack.api.data.entity.WeChatCallState;
|
import com.northtecom.visatrack.api.data.entity.WeChatCallState;
|
||||||
import com.northtecom.visatrack.api.data.repository.*;
|
import com.northtecom.visatrack.api.data.repository.*;
|
||||||
import com.northtecom.visatrack.api.model.entity.wechat.WeChatMessage;
|
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.exception.WxErrorException;
|
||||||
import com.ossez.wechat.common.model.entity.WeChatOAuth2UserInfo;
|
import com.ossez.wechat.common.model.entity.WeChatOAuth2UserInfo;
|
||||||
import com.northtecom.visatrack.api.util.WeChatUtils;
|
import com.northtecom.visatrack.api.util.WeChatUtils;
|
||||||
|
@ -48,6 +49,8 @@ public class WeChatService {
|
||||||
|
|
||||||
private final WeChatOfficialAccountService weChatOfficialAccountService;
|
private final WeChatOfficialAccountService weChatOfficialAccountService;
|
||||||
private final WeChatUtils weChatUtils;
|
private final WeChatUtils weChatUtils;
|
||||||
|
|
||||||
|
private final OpenAiUtils openAiUtils;
|
||||||
private final VisaCaseRepository visaCaseRepository;
|
private final VisaCaseRepository visaCaseRepository;
|
||||||
|
|
||||||
private final WeChatCallStateRepository weChatCallStateRepository;
|
private final WeChatCallStateRepository weChatCallStateRepository;
|
||||||
|
@ -59,10 +62,11 @@ public class WeChatService {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@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.weChatOAuth2Service = weChatOAuth2Service;
|
||||||
this.weChatOfficialAccountService = weChatOfficialAccountService;
|
this.weChatOfficialAccountService = weChatOfficialAccountService;
|
||||||
this.weChatUtils = weChatUtils;
|
this.weChatUtils = weChatUtils;
|
||||||
|
this.openAiUtils = openAiUtils;
|
||||||
this.visaCaseRepository = visaCaseRepository;
|
this.visaCaseRepository = visaCaseRepository;
|
||||||
this.weChatCallStateRepository = weChatCallStateRepository;
|
this.weChatCallStateRepository = weChatCallStateRepository;
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
|
@ -191,7 +195,7 @@ public class WeChatService {
|
||||||
// weChatMessage.setContent(contentGPT);
|
// weChatMessage.setContent(contentGPT);
|
||||||
// weChatMessage.setCreateTime(Instant.now().toEpochMilli());
|
// weChatMessage.setCreateTime(Instant.now().toEpochMilli());
|
||||||
|
|
||||||
return "success";// WeChatUtils.covertToWeChatMessageXmlStr(weChatMessage);
|
return "success";// WeChatUtils.covertToWeChatMessageXmlStr(weChatMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(WeChatMessage weChatMessage) throws WxErrorException {
|
public void sendMessage(WeChatMessage weChatMessage) throws WxErrorException {
|
||||||
|
@ -207,7 +211,7 @@ public class WeChatService {
|
||||||
|
|
||||||
|
|
||||||
private String callChatGPT(String content) {
|
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")
|
CompletionRequest completionRequest = new CompletionRequestBuilder().setModel("text-davinci-003")
|
||||||
.setPrompt(content)
|
.setPrompt(content)
|
||||||
.setMaxTokens(500)
|
.setMaxTokens(500)
|
||||||
|
@ -215,9 +219,6 @@ public class WeChatService {
|
||||||
.setUser("testing")
|
.setUser("testing")
|
||||||
.setLogitBias(new HashMap<>())
|
.setLogitBias(new HashMap<>())
|
||||||
.createCompletionRequest();
|
.createCompletionRequest();
|
||||||
|
|
||||||
|
|
||||||
// service.createCompletion(completionRequest).getChoices().size();
|
|
||||||
content = service.createCompletion(completionRequest).getChoices().get(0).getText();
|
content = service.createCompletion(completionRequest).getChoices().get(0).getText();
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
|
|
|
@ -27,13 +27,12 @@ import java.util.Set;
|
||||||
public class OpenAiUtils {
|
public class OpenAiUtils {
|
||||||
|
|
||||||
public static final String OPENAI_PATH = "/openai";
|
public static final String OPENAI_PATH = "/openai";
|
||||||
public static final String OPENAI_key = "key";
|
public static final String OPENAI_TOKEN = "token";
|
||||||
public static final String DISCOURSE_API_USERNAME = "api_username";
|
public static Map<String, String> openAiConfMap = new HashMap<String, String>();
|
||||||
private Map<String, String> openAiConfMap = new HashMap<String, String>();
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public OpenAiUtils(AwsUtils awsUtils) {
|
public OpenAiUtils(AwsUtils awsUtils) {
|
||||||
openAiConfMap.put(OPENAI_key, StringUtils.EMPTY);
|
openAiConfMap.put(OPENAI_TOKEN, StringUtils.EMPTY);
|
||||||
|
|
||||||
openAiConfMap = awsUtils.getOpenAiParameterConfValueFromAWS(openAiConfMap);
|
openAiConfMap = awsUtils.getOpenAiParameterConfValueFromAWS(openAiConfMap);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue