Aktualizovat src/main/java/it/ohalee/minecraftgpt/OpenAI.java
This commit is contained in:
parent
4bfa2d89d6
commit
217718d8f7
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user