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