chore: upgrade, unify dependencies and remove some unnecessary (#36)
This commit is contained in:
parent
3f425c320d
commit
f4e27659ff
33 changed files with 157 additions and 171 deletions
16
README.md
16
README.md
|
|
@ -47,14 +47,14 @@ dependencies {
|
|||
|
||||
This SDK uses the following core dependencies:
|
||||
|
||||
| Library | Version |
|
||||
|---------|----------|
|
||||
| OkHttp | 4.12.0 |
|
||||
| Java JWT | 4.4.0 |
|
||||
| Jackson | 2.17.2 |
|
||||
| Retrofit2 | 2.11.0 |
|
||||
| RxJava | 3.1.8 |
|
||||
| SLF4J | 2.0.16 |
|
||||
| Library | Version |
|
||||
|-----------|---------|
|
||||
| OkHttp3 | 3.14.9 |
|
||||
| Java JWT | 4.2.2 |
|
||||
| Jackson | 2.19.0 |
|
||||
| Retrofit2 | 2.12.0 |
|
||||
| RxJava3 | 3.1.10 |
|
||||
| SLF4J | 2.0.17 |
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
|
|
|
|||
16
README_CN.md
16
README_CN.md
|
|
@ -47,14 +47,14 @@ dependencies {
|
|||
|
||||
本SDK使用以下核心依赖库:
|
||||
|
||||
| 依赖库 | 版本 |
|
||||
|--------|------|
|
||||
| OkHttp | 4.12.0 |
|
||||
| Java JWT | 4.4.0 |
|
||||
| Jackson | 2.17.2 |
|
||||
| Retrofit2 | 2.11.0 |
|
||||
| RxJava | 3.1.8 |
|
||||
| SLF4J | 2.0.16 |
|
||||
| Library | Version |
|
||||
|-----------|---------|
|
||||
| OkHttp3 | 3.14.9 |
|
||||
| Java JWT | 4.2.2 |
|
||||
| Jackson | 2.19.0 |
|
||||
| Retrofit2 | 2.12.0 |
|
||||
| RxJava3 | 3.1.10 |
|
||||
| SLF4J | 2.0.17 |
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
|
|
|
|||
56
core/pom.xml
56
core/pom.xml
|
|
@ -47,17 +47,14 @@
|
|||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j.version>2.0.11</slf4j.version>
|
||||
<slf4j.version>2.0.17</slf4j.version>
|
||||
<okhttp.version>3.14.9</okhttp.version>
|
||||
<jackson.version>2.18.3</jackson.version>
|
||||
<retrofit2.version>2.9.0</retrofit2.version>
|
||||
<rxjava.version>3.1.8</rxjava.version>
|
||||
<jackson.version>2.19.0</jackson.version>
|
||||
<retrofit2.version>2.12.0</retrofit2.version>
|
||||
<rxjava.version>3.1.10</rxjava.version>
|
||||
<jwt.version>4.2.2</jwt.version>
|
||||
<lombok.version>1.18.32</lombok.version>
|
||||
<tika.version>2.9.0</tika.version>
|
||||
<junit.test.version>5.10.2</junit.test.version>
|
||||
<testcontainer.version>1.19.8</testcontainer.version>
|
||||
<mockserver.version>5.15.0</mockserver.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
@ -77,7 +74,6 @@
|
|||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
|
@ -104,7 +100,7 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>adapter-rxjava2</artifactId>
|
||||
<artifactId>adapter-rxjava3</artifactId>
|
||||
<version>${retrofit2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
@ -156,13 +152,7 @@
|
|||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--file tika-->
|
||||
<dependency>
|
||||
<groupId>org.apache.tika</groupId>
|
||||
<artifactId>tika-core</artifactId>
|
||||
<version>${tika.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test JUnit -->
|
||||
|
|
@ -184,40 +174,6 @@
|
|||
<version>${junit.test.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test Containers -->
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${testcontainer.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>mockserver</artifactId>
|
||||
<version>${testcontainer.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${testcontainer.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Test MockServer -->
|
||||
<dependency>
|
||||
<groupId>org.mock-server</groupId>
|
||||
<artifactId>mockserver-netty</artifactId>
|
||||
<version>${mockserver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mock-server</groupId>
|
||||
<artifactId>mockserver-client-java</artifactId>
|
||||
<version>${mockserver.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ import ai.z.openapi.core.model.FlowableClientResponse;
|
|||
import ai.z.openapi.utils.FlowableRequestSupplier;
|
||||
import ai.z.openapi.utils.OkHttps;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
|
||||
import retrofit2.converter.jackson.JacksonConverterFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
|
@ -111,7 +111,7 @@ public abstract class AbstractAiClient extends AbstractClientBaseService {
|
|||
this.retrofit = new Retrofit.Builder().baseUrl(baseUrl)
|
||||
.client(httpClient)
|
||||
.addConverterFactory(JacksonConverterFactory.create(mapper))
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ai.z.openapi.api.agents;
|
|||
import ai.z.openapi.service.agents.AgentAsyncResultRetrieveParams;
|
||||
import ai.z.openapi.service.agents.AgentsCompletionRequest;
|
||||
import ai.z.openapi.service.model.ModelData;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import ai.z.openapi.service.assistant.conversation.AssistantConversationUsageLis
|
|||
import ai.z.openapi.service.assistant.query_support.AssistantSupportStatus;
|
||||
import ai.z.openapi.service.assistant.conversation.AssistantConversationParameters;
|
||||
import ai.z.openapi.service.assistant.query_support.AssistantQuerySupportParams;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.audio;
|
|||
|
||||
import ai.z.openapi.service.audio.AudioSpeechRequest;
|
||||
import ai.z.openapi.service.audio.AudioTranscriptionResult;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ai.z.openapi.api.batches;
|
|||
import ai.z.openapi.service.batches.Batch;
|
||||
import ai.z.openapi.service.batches.BatchCreateParams;
|
||||
import ai.z.openapi.service.batches.BatchPage;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.chat;
|
|||
|
||||
import ai.z.openapi.service.model.ChatCompletionCreateParams;
|
||||
import ai.z.openapi.service.model.ModelData;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.embedding;
|
|||
|
||||
import ai.z.openapi.service.embedding.EmbeddingCreateParams;
|
||||
import ai.z.openapi.service.embedding.EmbeddingResult;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ai.z.openapi.api.file;
|
|||
import ai.z.openapi.service.file.File;
|
||||
import ai.z.openapi.service.file.FileDeleted;
|
||||
import ai.z.openapi.service.file.QueryFileResult;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.images;
|
|||
|
||||
import ai.z.openapi.service.image.CreateImageRequest;
|
||||
import ai.z.openapi.service.image.ImageResult;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.tools;
|
|||
|
||||
import ai.z.openapi.service.tools.WebSearchParamsRequest;
|
||||
import ai.z.openapi.service.tools.WebSearchPro;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.videos;
|
|||
|
||||
import ai.z.openapi.service.videos.VideoCreateParams;
|
||||
import ai.z.openapi.service.videos.VideoObject;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.api.web_search;
|
|||
|
||||
import ai.z.openapi.service.web_search.WebSearchDTO;
|
||||
import ai.z.openapi.service.web_search.WebSearchRequest;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ai.z.openapi.core.model;
|
||||
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
|
||||
/**
|
||||
* A client response that supports a reactive Flowable stream with separate body type and
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ import ai.z.openapi.utils.FlowableRequestSupplier;
|
|||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import ai.z.openapi.utils.StringUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.reactivex.BackpressureStrategy;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.BackpressureStrategy;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import java.util.Objects;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.service.agents;
|
|||
|
||||
import ai.z.openapi.service.model.ChatCompletionResponse;
|
||||
import ai.z.openapi.service.model.ModelData;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
|
||||
/**
|
||||
* Agent completion service interface
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import ai.z.openapi.service.model.ChatCompletionResponse;
|
|||
import ai.z.openapi.service.model.ModelData;
|
||||
import ai.z.openapi.utils.FlowableRequestSupplier;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.service.assistant;
|
|||
|
||||
import ai.z.openapi.core.model.FlowableClientResponse;
|
||||
import ai.z.openapi.service.model.ChatError;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
|||
import ai.z.openapi.utils.FlowableRequestSupplier;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.tika.Tika;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -128,35 +127,27 @@ public class AudioServiceImpl implements AudioService {
|
|||
|
||||
private AudioTranscriptionResponse createTranscriptionStream(AudioTranscriptionRequest request) {
|
||||
FlowableRequestSupplier<AudioTranscriptionRequest, retrofit2.Call<ResponseBody>> supplier = params -> {
|
||||
try {
|
||||
java.io.File file = params.getFile();
|
||||
Tika tika = new Tika();
|
||||
String contentType = tika.detect(file);
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse(contentType), file);
|
||||
MultipartBody.Part fileData = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
|
||||
java.io.File file = params.getFile();
|
||||
String contentType = detectContentType(file);
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse(contentType), file);
|
||||
MultipartBody.Part fileData = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
|
||||
|
||||
Map<String, RequestBody> requestMap = new HashMap<>();
|
||||
if (params.getModel() != null) {
|
||||
requestMap.put("model", RequestBody.create(MediaType.parse("text/plain"), params.getModel()));
|
||||
}
|
||||
if (params.getStream() != null) {
|
||||
requestMap.put("stream",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getStream().toString()));
|
||||
}
|
||||
if (params.getRequestId() != null) {
|
||||
requestMap.put("request_id",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getRequestId()));
|
||||
}
|
||||
if (params.getUserId() != null) {
|
||||
requestMap.put("user_id", RequestBody.create(MediaType.parse("text/plain"), params.getUserId()));
|
||||
}
|
||||
Map<String, RequestBody> requestMap = new HashMap<>();
|
||||
if (params.getModel() != null) {
|
||||
requestMap.put("model", RequestBody.create(MediaType.parse("text/plain"), params.getModel()));
|
||||
}
|
||||
if (params.getStream() != null) {
|
||||
requestMap.put("stream",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getStream().toString()));
|
||||
}
|
||||
if (params.getRequestId() != null) {
|
||||
requestMap.put("request_id", RequestBody.create(MediaType.parse("text/plain"), params.getRequestId()));
|
||||
}
|
||||
if (params.getUserId() != null) {
|
||||
requestMap.put("user_id", RequestBody.create(MediaType.parse("text/plain"), params.getUserId()));
|
||||
}
|
||||
|
||||
return audioApi.audioTranscriptionStream(requestMap, fileData);
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.error("Error create transcription: {}", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return audioApi.audioTranscriptionStream(requestMap, fileData);
|
||||
};
|
||||
return this.zAiClient.biStreamRequest(request, supplier, AudioTranscriptionResponse.class,
|
||||
AudioTranscriptionChunk.class);
|
||||
|
|
@ -164,35 +155,27 @@ public class AudioServiceImpl implements AudioService {
|
|||
|
||||
private AudioTranscriptionResponse createTranscriptionBlock(AudioTranscriptionRequest request) {
|
||||
RequestSupplier<AudioTranscriptionRequest, AudioTranscriptionResult> supplier = (params) -> {
|
||||
try {
|
||||
java.io.File file = params.getFile();
|
||||
Tika tika = new Tika();
|
||||
String contentType = tika.detect(file);
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse(contentType), file);
|
||||
MultipartBody.Part fileData = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
|
||||
java.io.File file = params.getFile();
|
||||
String contentType = detectContentType(file);
|
||||
RequestBody requestFile = RequestBody.create(MediaType.parse(contentType), file);
|
||||
MultipartBody.Part fileData = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
|
||||
|
||||
Map<String, RequestBody> requestMap = new HashMap<>();
|
||||
if (params.getModel() != null) {
|
||||
requestMap.put("model", RequestBody.create(MediaType.parse("text/plain"), params.getModel()));
|
||||
}
|
||||
if (params.getStream() != null) {
|
||||
requestMap.put("stream",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getStream().toString()));
|
||||
}
|
||||
if (params.getRequestId() != null) {
|
||||
requestMap.put("request_id",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getRequestId()));
|
||||
}
|
||||
if (params.getUserId() != null) {
|
||||
requestMap.put("user_id", RequestBody.create(MediaType.parse("text/plain"), params.getUserId()));
|
||||
}
|
||||
Map<String, RequestBody> requestMap = new HashMap<>();
|
||||
if (params.getModel() != null) {
|
||||
requestMap.put("model", RequestBody.create(MediaType.parse("text/plain"), params.getModel()));
|
||||
}
|
||||
if (params.getStream() != null) {
|
||||
requestMap.put("stream",
|
||||
RequestBody.create(MediaType.parse("text/plain"), params.getStream().toString()));
|
||||
}
|
||||
if (params.getRequestId() != null) {
|
||||
requestMap.put("request_id", RequestBody.create(MediaType.parse("text/plain"), params.getRequestId()));
|
||||
}
|
||||
if (params.getUserId() != null) {
|
||||
requestMap.put("user_id", RequestBody.create(MediaType.parse("text/plain"), params.getUserId()));
|
||||
}
|
||||
|
||||
return audioApi.audioTranscription(requestMap, fileData);
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.error("Error create transcription: {}", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return audioApi.audioTranscription(requestMap, fileData);
|
||||
};
|
||||
return this.zAiClient.executeRequest(request, supplier, AudioTranscriptionResponse.class);
|
||||
}
|
||||
|
|
@ -254,4 +237,38 @@ public class AudioServiceImpl implements AudioService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect MIME type based on file extension
|
||||
* @param file the file to detect
|
||||
* @return MIME type string
|
||||
*/
|
||||
private String detectContentType(java.io.File file) {
|
||||
String fileName = file.getName().toLowerCase();
|
||||
if (fileName.endsWith(".mp3")) {
|
||||
return "audio/mpeg";
|
||||
}
|
||||
else if (fileName.endsWith(".wav")) {
|
||||
return "audio/wav";
|
||||
}
|
||||
else if (fileName.endsWith(".m4a")) {
|
||||
return "audio/mp4";
|
||||
}
|
||||
else if (fileName.endsWith(".aac")) {
|
||||
return "audio/aac";
|
||||
}
|
||||
else if (fileName.endsWith(".ogg")) {
|
||||
return "audio/ogg";
|
||||
}
|
||||
else if (fileName.endsWith(".flac")) {
|
||||
return "audio/flac";
|
||||
}
|
||||
else if (fileName.endsWith(".wma")) {
|
||||
return "audio/x-ms-wma";
|
||||
}
|
||||
else {
|
||||
// Default to audio/mpeg for unknown audio files
|
||||
return "audio/mpeg";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.service.audio;
|
|||
|
||||
import ai.z.openapi.core.model.BiFlowableClientResponse;
|
||||
import ai.z.openapi.service.model.ChatError;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import ai.z.openapi.core.model.FlowableClientResponse;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.reactivex.FlowableEmitter;
|
||||
import io.reactivex.rxjava3.core.FlowableEmitter;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ai.z.openapi.service.tools;
|
|||
|
||||
import ai.z.openapi.core.model.FlowableClientResponse;
|
||||
import ai.z.openapi.service.model.ChatError;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.rxjava3.core.Flowable;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ai.z.openapi.utils;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
|
||||
/**
|
||||
* Functional interface for supplying single request operations using RxJava. This
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ import ai.z.openapi.core.token.TokenManager;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
@Testcontainers
|
||||
public class ZaiClientTest {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZaiClientTest.class);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
@Testcontainers
|
||||
public class DeserializeTest {
|
||||
|
||||
private final ObjectMapper mapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package ai.z.openapi.realtime;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Resources;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import ai.z.openapi.service.realtime.JasonUtil;
|
||||
import ai.z.openapi.service.realtime.OkHttpRealtimeClient;
|
||||
import ai.z.openapi.service.realtime.RealtimeClientEvent;
|
||||
|
|
@ -15,8 +14,9 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
|
@ -85,10 +85,15 @@ public class RealtimeClientTest {
|
|||
@Test
|
||||
@DisplayName("Test Audio Resource File Loading")
|
||||
void testAudioResourceFileLoading() throws IOException {
|
||||
URL resourceUrl = Resources.getResource(TEST_RESOURCE_FILE);
|
||||
assertNotNull(resourceUrl, "Test resource file should exist");
|
||||
InputStream resourceStream = getClass().getClassLoader().getResourceAsStream(TEST_RESOURCE_FILE);
|
||||
assertNotNull(resourceStream, "Test resource file should exist");
|
||||
|
||||
List<String> lines = Resources.readLines(resourceUrl, Charsets.UTF_8);
|
||||
List<String> lines = new java.util.ArrayList<>();
|
||||
try (Scanner scanner = new Scanner(resourceStream, StandardCharsets.UTF_8.name())) {
|
||||
while (scanner.hasNextLine()) {
|
||||
lines.add(scanner.nextLine());
|
||||
}
|
||||
}
|
||||
assertNotNull(lines, "Resource lines should not be null");
|
||||
assertFalse(lines.isEmpty(), "Resource file should not be empty");
|
||||
|
||||
|
|
@ -102,8 +107,15 @@ public class RealtimeClientTest {
|
|||
@Test
|
||||
@DisplayName("Test JSON Event Parsing")
|
||||
void testJsonEventParsing() throws IOException {
|
||||
URL resourceUrl = Resources.getResource(TEST_RESOURCE_FILE);
|
||||
List<String> lines = Resources.readLines(resourceUrl, Charsets.UTF_8);
|
||||
InputStream resourceStream = getClass().getClassLoader().getResourceAsStream(TEST_RESOURCE_FILE);
|
||||
assertNotNull(resourceStream, "Test resource file should exist");
|
||||
|
||||
List<String> lines = new java.util.ArrayList<>();
|
||||
try (Scanner scanner = new Scanner(resourceStream, StandardCharsets.UTF_8.name())) {
|
||||
while (scanner.hasNextLine()) {
|
||||
lines.add(scanner.nextLine());
|
||||
}
|
||||
}
|
||||
|
||||
int parsedEventCount = 0;
|
||||
for (String text : lines) {
|
||||
|
|
@ -137,8 +149,15 @@ public class RealtimeClientTest {
|
|||
logger.info("WebSocket connection established");
|
||||
|
||||
// Load and send test events
|
||||
URL resourceUrl = Resources.getResource(TEST_RESOURCE_FILE);
|
||||
List<String> lines = Resources.readLines(resourceUrl, Charsets.UTF_8);
|
||||
InputStream resourceStream = getClass().getClassLoader().getResourceAsStream(TEST_RESOURCE_FILE);
|
||||
assertNotNull(resourceStream, "Test resource file should exist");
|
||||
|
||||
List<String> lines = new java.util.ArrayList<>();
|
||||
try (Scanner scanner = new Scanner(resourceStream, StandardCharsets.UTF_8.name())) {
|
||||
while (scanner.hasNextLine()) {
|
||||
lines.add(scanner.nextLine());
|
||||
}
|
||||
}
|
||||
|
||||
int sentEventCount = 0;
|
||||
for (String text : lines) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import ai.z.openapi.service.model.Choice;
|
|||
import ai.z.openapi.service.model.ModelData;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,9 @@ import ai.z.openapi.service.model.QueryModelResultResponse;
|
|||
import ai.z.openapi.service.model.WebSearch;
|
||||
import ai.z.openapi.service.model.params.CodeGeexExtra;
|
||||
import ai.z.openapi.service.model.params.CodeGeexTarget;
|
||||
import ai.z.openapi.service.videos.VideoCreateParams;
|
||||
import ai.z.openapi.service.videos.VideosResponse;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import java.nio.file.Files;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
|
@ -297,7 +295,7 @@ public class ChatServiceTest {
|
|||
void testAudioWithAudio() throws IOException {
|
||||
String requestId = String.format(REQUEST_ID_TEMPLATE, System.currentTimeMillis());
|
||||
String file = ClassLoader.getSystemResource("asr.wav").getFile();
|
||||
byte[] bytes = FileUtils.readFileToByteArray(new File(file));
|
||||
byte[] bytes = Files.readAllBytes(new File(file).toPath());
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
String audioBytes = encoder.encodeToString(bytes);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import java.nio.file.Files;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
|
@ -197,7 +197,7 @@ public class VideosServiceTest {
|
|||
void testVideoGenerationWithImage() throws IOException {
|
||||
String requestId = String.format(REQUEST_ID_TEMPLATE, System.currentTimeMillis());
|
||||
String file = ClassLoader.getSystemResource("image_to_video.png").getFile();
|
||||
byte[] bytes = FileUtils.readFileToByteArray(new File(file));
|
||||
byte[] bytes = Files.readAllBytes(new File(file).toPath());
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
String imageUrl = encoder.encodeToString(bytes);
|
||||
VideoCreateParams request = VideoCreateParams.builder()
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class FunctionCallingExample {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ZaiClient client = ZaiClient.builder().apiKey("your_api_key").build();
|
||||
ZaiClient client = ZaiClient.builder().build();
|
||||
|
||||
// Define function tools
|
||||
Map<String, ChatFunctionParameterProperty> properties = new HashMap<>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue