@@ -84,16 +84,37 @@ public OpenAiService(final String token) {
84
84
this (token , DEFAULT_TIMEOUT );
85
85
}
86
86
87
+ /**
88
+ * Creates a new OpenAiService that wraps OpenAiApi
89
+ *
90
+ * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
91
+ * @param baseUrl OpenAi baseUrl, default is "https://api.openai.com/"
92
+ */
93
+ public OpenAiService (final String token , String baseUrl ) {
94
+ this (token , DEFAULT_TIMEOUT , baseUrl );
95
+ }
96
+
87
97
/**
88
98
* Creates a new OpenAiService that wraps OpenAiApi
89
99
*
90
100
* @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
91
101
* @param timeout http read timeout, Duration.ZERO means no timeout
92
102
*/
93
103
public OpenAiService (final String token , final Duration timeout ) {
104
+ this (token , timeout , null );
105
+ }
106
+
107
+ /**
108
+ * Creates a new OpenAiService that wraps OpenAiApi
109
+ *
110
+ * @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
111
+ * @param timeout http read timeout, Duration.ZERO means no timeout
112
+ * @param baseUrl OpenAi baseUrl, default is "https://api.openai.com/"
113
+ */
114
+ public OpenAiService (final String token , final Duration timeout , String baseUrl ) {
94
115
ObjectMapper mapper = defaultObjectMapper ();
95
116
OkHttpClient client = defaultClient (token , timeout );
96
- Retrofit retrofit = defaultRetrofit (client , mapper );
117
+ Retrofit retrofit = defaultRetrofit (client , mapper , baseUrl );
97
118
98
119
this .api = retrofit .create (OpenAiApi .class );
99
120
this .executorService = client .dispatcher ().executorService ();
@@ -572,7 +593,7 @@ public void shutdownExecutor() {
572
593
public static OpenAiApi buildApi (String token , Duration timeout ) {
573
594
ObjectMapper mapper = defaultObjectMapper ();
574
595
OkHttpClient client = defaultClient (token , timeout );
575
- Retrofit retrofit = defaultRetrofit (client , mapper );
596
+ Retrofit retrofit = defaultRetrofit (client , mapper , null );
576
597
577
598
return retrofit .create (OpenAiApi .class );
578
599
}
@@ -596,9 +617,9 @@ public static OkHttpClient defaultClient(String token, Duration timeout) {
596
617
.build ();
597
618
}
598
619
599
- public static Retrofit defaultRetrofit (OkHttpClient client , ObjectMapper mapper ) {
620
+ public static Retrofit defaultRetrofit (OkHttpClient client , ObjectMapper mapper , String baseUrl ) {
600
621
return new Retrofit .Builder ()
601
- .baseUrl (BASE_URL )
622
+ .baseUrl (baseUrl == null || baseUrl . isEmpty () ? BASE_URL : baseUrl )
602
623
.client (client )
603
624
.addConverterFactory (JacksonConverterFactory .create (mapper ))
604
625
.addCallAdapterFactory (RxJava2CallAdapterFactory .create ())
0 commit comments