|
|
|
@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
public class SparkGptClient implements InitializingBean {
|
|
|
|
|
@Resource
|
|
|
|
|
private SparkGptProperties sparkGptProperties;
|
|
|
|
|
private OkHttpClient okHttpClient;
|
|
|
|
|
// private OkHttpClient okHttpClient;
|
|
|
|
|
private String authUrl;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -46,12 +46,12 @@ public class SparkGptClient implements InitializingBean {
|
|
|
|
|
this.authUrl = authUrl.replace("http://", "ws://").replace("https://", "wss://");
|
|
|
|
|
log.info("[SPARK CHAT] 鉴权 endpoint : {}", this.authUrl);
|
|
|
|
|
// 初始化 okHttpClient
|
|
|
|
|
this.okHttpClient = new OkHttpClient()
|
|
|
|
|
.newBuilder()
|
|
|
|
|
.connectTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
.readTimeout(90, TimeUnit.SECONDS) // sse 接口的 readTimeout 不能设置小了
|
|
|
|
|
.writeTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
.build();
|
|
|
|
|
// this.okHttpClient = new OkHttpClient()
|
|
|
|
|
// .newBuilder()
|
|
|
|
|
// .connectTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
// .readTimeout(90, TimeUnit.SECONDS) // sse 接口的 readTimeout 不能设置小了
|
|
|
|
|
// .writeTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
// .build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -64,6 +64,12 @@ public class SparkGptClient implements InitializingBean {
|
|
|
|
|
// 设置请求参数
|
|
|
|
|
listener.setRequestJson(param.toJsonParams());
|
|
|
|
|
log.info("[SPARK CHAT] 请求参数 {}", JSONUtil.parseObj(param.toJsonParams()).toStringPretty());
|
|
|
|
|
OkHttpClient okHttpClient = new OkHttpClient()
|
|
|
|
|
.newBuilder()
|
|
|
|
|
.connectTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
.readTimeout(90, TimeUnit.SECONDS) // sse 接口的 readTimeout 不能设置小了
|
|
|
|
|
.writeTimeout(90, TimeUnit.SECONDS)
|
|
|
|
|
.build();
|
|
|
|
|
okHttpClient.newWebSocket(request, listener);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("[SPARK CHAT] Spark AI 请求异常: {}", e.getMessage());
|
|
|
|
|