Aktualizovat src/main/java/it/ohalee/minecraftgpt/OpenAI.java

This commit is contained in:
Radim Lipovčan 2024-03-29 18:56:28 +01:00
parent 4bfa2d89d6
commit 217718d8f7

View File

@ -59,3 +59,35 @@ public class OpenAI {
}
}
public class CustomOpenAiService extends OpenAiService {
private final ExecutorService executorService;
private final String openaiBaseUrl = "http://frigate.lipovcan.cz:3001";
public CustomOpenAiService(String token, Duration timeout) {
super(token, timeout);
ObjectMapper mapper = OpenAiService.defaultObjectMapper();
OkHttpClient client = OpenAiService.defaultClient(token, timeout);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(openaiBaseUrl)
.client(client)
.addConverterFactory(JacksonConverterFactory.create(mapper))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
OpenAiApi customApi = retrofit.create(OpenAiApi.class);
// 使用反射设置 OpenAiService 类的 api 字段
try {
Field apiField = OpenAiService.class.getDeclaredField("api");
apiField.setAccessible(true);
apiField.set(this, customApi);
} catch (NoSuchFieldException | IllegalAccessException e) {
// 处理异常
e.printStackTrace();
}
this.executorService = client.dispatcher().executorService();
}
}