@@ -30,6 +30,11 @@ public static OpenAiService getOpenAiService(JsonNode openAiConfig) {
3030 if (!openAiConfig .has ("isOpenai" ) || !openAiConfig .get ("isOpenai" ).asBoolean ()) {
3131 return null ;
3232 }
33+
34+ if (singleton != null && !openAiConfig .equals (singleton .getOpenAiConfig ())) {
35+ singleton = null ;
36+ }
37+
3338 if (singleton == null ) {
3439 synchronized (OpenAiService .class ) {
3540 if (singleton == null ) {
@@ -75,22 +80,22 @@ OkHttpClient defaultClient() {
7580 throw new IllegalArgumentException ("OpenAI token is required" );
7681 }
7782
78- OkHttpClient client
83+ OkHttpClient . Builder builder
7984 = com .theokanning .openai .service .OpenAiService .defaultClient (
8085 openAiConfig .get ("token" ).asText (),
8186 Duration .ofSeconds (openAiConfig .get ("timeout" ).asInt ())
82- );
87+ ). newBuilder () ;
8388
8489 if (openAiConfig .get ("isProxy" ).asBoolean ()) {
8590 Proxy proxy = new Proxy (Proxy .Type .HTTP ,
8691 new InetSocketAddress (openAiConfig .get ("proxyHost" ).asText (),
8792 openAiConfig .get ("proxyPort" ).asInt ()
8893 )
8994 );
90- client . newBuilder () .proxy (proxy ).build ();
95+ builder .proxy (proxy ).build ();
9196 }
9297
93- return client ;
98+ return builder . build () ;
9499 }
95100
96101 ObjectMapper defaultObjectMapper () {
@@ -108,4 +113,8 @@ public Flowable<ChatCompletionChunk> streamChatCompletion(
108113 ChatCompletionRequest request ) {
109114 return openAiService .streamChatCompletion (request );
110115 }
116+
117+ public JsonNode getOpenAiConfig () {
118+ return openAiConfig ;
119+ }
111120}
0 commit comments