|
@@ -58,25 +58,25 @@ public class AliBaiLianAIClient {
|
|
|
return apiKey;
|
|
|
}
|
|
|
|
|
|
-// public ModelsList ListModels() throws IOException {
|
|
|
-// OkHttpClient client = new OkHttpClient();
|
|
|
-// okhttp3.Request request = new okhttp3.Request.Builder()
|
|
|
-// .url(getModelsUrl())
|
|
|
-// .addHeader("Authorization", "Bearer " + getApiKey())
|
|
|
-// .build();
|
|
|
-// try {
|
|
|
-// okhttp3.Response response = client.newCall(request).execute();
|
|
|
-// String body = response.body().string();
|
|
|
-// Gson gson = new Gson();
|
|
|
-// return gson.fromJson(body, ModelsList.class);
|
|
|
-// } catch (IOException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// throw e;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- public ChatCompletionResponse ChatCompletion(ChatCompletionRequest request) throws IOException {
|
|
|
+ public ModelsList ListModels() throws IOException {
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ okhttp3.Request request = new okhttp3.Request.Builder()
|
|
|
+ .url(getModelsUrl())
|
|
|
+ .addHeader("Authorization", "Bearer " + getApiKey())
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ okhttp3.Response response = client.newCall(request).execute();
|
|
|
+ String body = response.body().string();
|
|
|
+ Gson gson = new Gson();
|
|
|
+ return gson.fromJson(body, ModelsList.class);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ChatCompletionResponse chatCompletion(ChatCompletionRequest request) throws IOException {
|
|
|
request.stream = false;
|
|
|
OkHttpClient client = new OkHttpClient.Builder()
|
|
|
.connectTimeout(2, TimeUnit.MINUTES)
|
|
@@ -104,7 +104,7 @@ public class AliBaiLianAIClient {
|
|
|
}
|
|
|
|
|
|
// return a stream of ChatCompletionStreamResponse
|
|
|
- public Flowable<ChatCompletionStreamResponse> ChatCompletionStream(ChatCompletionRequest request) throws IOException {
|
|
|
+ public Flowable<ChatCompletionStreamResponse> chatCompletionStream(ChatCompletionRequest request) throws IOException {
|
|
|
request.stream = true;
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json");
|