Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class OpenAiService {
* @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
*/
public OpenAiService(final String token) {
this(token, DEFAULT_TIMEOUT);
this(token, DEFAULT_TIMEOUT, BASE_URL);
}

/**
Expand All @@ -91,9 +91,19 @@ public OpenAiService(final String token) {
* @param timeout http read timeout, Duration.ZERO means no timeout
*/
public OpenAiService(final String token, final Duration timeout) {
this(token, timeout, BASE_URL);
}

/**
* Creates a new OpenAiService that wraps OpenAiApi
*
* @param token OpenAi token string "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
* @param baseUrl URL for the service "https://api.openai.com/"
*/
public OpenAiService(final String token, final Duration timeout, final String baseUrl) {
ObjectMapper mapper = defaultObjectMapper();
OkHttpClient client = defaultClient(token, timeout);
Retrofit retrofit = defaultRetrofit(client, mapper);
Retrofit retrofit = defaultRetrofit(client, mapper, baseUrl);

this.api = retrofit.create(OpenAiApi.class);
this.executorService = client.dispatcher().executorService();
Expand Down Expand Up @@ -572,7 +582,7 @@ public void shutdownExecutor() {
public static OpenAiApi buildApi(String token, Duration timeout) {
ObjectMapper mapper = defaultObjectMapper();
OkHttpClient client = defaultClient(token, timeout);
Retrofit retrofit = defaultRetrofit(client, mapper);
Retrofit retrofit = defaultRetrofit(client, mapper, BASE_URL);

return retrofit.create(OpenAiApi.class);
}
Expand All @@ -596,9 +606,9 @@ public static OkHttpClient defaultClient(String token, Duration timeout) {
.build();
}

public static Retrofit defaultRetrofit(OkHttpClient client, ObjectMapper mapper) {
public static Retrofit defaultRetrofit(OkHttpClient client, ObjectMapper mapper, final String baseUrl) {
return new Retrofit.Builder()
.baseUrl(BASE_URL)
.baseUrl(baseUrl)
.client(client)
.addConverterFactory(JacksonConverterFactory.create(mapper))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
Expand Down