This commit is contained in:
yutou 2023-09-13 15:22:56 +08:00
parent 9b70685949
commit e595cff31d
2 changed files with 9 additions and 11 deletions

View File

@ -60,10 +60,12 @@ public class BaiduGPTManager {
JSONObject json = new JSONObject();
json.put("messages", messages);
System.out.println("json = " + json);
String post = HttpTools.post(url + "?access_token=" + getToken()
, json.toJSONString().getBytes(StandardCharsets.UTF_8));
HashMap<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
String post = HttpTools.http_post(url + "?access_token=" + getToken()
, json.toJSONString().getBytes(StandardCharsets.UTF_8), 5, header);
System.out.println("post = " + post);
if(StringUtils.isEmpty(post)){
if (StringUtils.isEmpty(post)) {
clear();
return sendMessage(user, message);
}
@ -75,12 +77,8 @@ public class BaiduGPTManager {
}
public static void main(String[] args) throws Exception {
BaiduGPTManager.getManager().sendMessage("test", "定义个变量西瓜它的值是5");
Thread.sleep(1000);
BaiduGPTManager.getManager().sendMessage("test", "西瓜的值的多少");
Thread.sleep(1000);
BaiduGPTManager.getManager().clear();
BaiduGPTManager.getManager().sendMessage("test2", "西瓜的值的多少");
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "2023年创业什么赚钱?");
System.out.println(message.getResult());
}
}

View File

@ -95,8 +95,8 @@ public class HttpTools {
connection.setDoOutput(true);
connection.setDoInput(true);
connection.addRequestProperty("User-Agent", getExtUa());
connection.setConnectTimeout(5 * 1000);
connection.setReadTimeout(10 * 1000);
// connection.setConnectTimeout(5 * 1000);
// connection.setReadTimeout(10 * 1000);
//connection.addRequestProperty("Connection", "keep-alive");
//connection.addRequestProperty("User-Agent", getExtUa());
//connection.addRequestProperty("content-type", "application/json");