-
Notifications
You must be signed in to change notification settings - Fork 98
feat: Support websocket #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
92b6657
feat: add audio transcription interface
hanzeINGH 1311529
save chat ws
hanzeINGH c4dfaf7
save ws transcription
hanzeINGH bd58521
format code
hanzeINGH 8ae410b
add ut
hanzeINGH b562d4d
format code
hanzeINGH 99910cf
format code
hanzeINGH 75c382a
fix ut
hanzeINGH f35b3c2
fix ci
hanzeINGH b57805e
fix ci
hanzeINGH 7315347
fix ci
hanzeINGH 65e3689
fix ci
hanzeINGH 4e85b6f
fix ci
hanzeINGH c5ed443
fix ci
hanzeINGH d8835b2
fix ci
hanzeINGH 7f51524
fix ci
hanzeINGH 43be7ee
fix ci
hanzeINGH 1fdab4d
fix ci
hanzeINGH be44ab1
fix ci
hanzeINGH 4fcadd3
fix ci
hanzeINGH 7ee1a3e
fix ci
hanzeINGH b1294a5
fix ci
hanzeINGH 9b400d7
fix ci
hanzeINGH 51f1f1e
fix ci
hanzeINGH 680a6eb
fix ci
hanzeINGH 159abbe
fix ci
hanzeINGH 1d592b8
fix ci
hanzeINGH 931d813
fix ci
hanzeINGH f9ce9d4
fix ci
hanzeINGH 143248f
fix ci
hanzeINGH dc60f14
fix ci
hanzeINGH ef75f9c
fix ci
hanzeINGH c69b6a4
fix ci
hanzeINGH c28e365
fix ci
hanzeINGH 2cc6153
fix cr
hanzeINGH 8f12072
fix code format
hanzeINGH f3f5e9f
fix: cr
hanzeINGH 7b745dd
fix: code format
hanzeINGH 92f47cb
fix cr
hanzeINGH 34793a8
fix code style
hanzeINGH a1f71cd
fix ci
hanzeINGH 74bf190
jwt refresh timing
hanzeINGH 5e60949
jwt refresh timing
hanzeINGH bac158f
fix cr
hanzeINGH e0dc61d
fix cr
hanzeINGH 5da6135
fix cr
hanzeINGH b0359ab
fix cr
hanzeINGH a2d2018
add ut
hanzeINGH d2ae3ab
fix error code
hanzeINGH 30a8a9c
add: turn detection event
hanzeINGH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| **/bin/* | ||
| **/obj/* | ||
| .mvn | ||
| *.wav | ||
|
|
||
| # Compiled class file | ||
| *.class | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
api/src/main/java/com/coze/openapi/api/AudioTranscriptionAPI.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.coze.openapi.api; | ||
|
|
||
| import com.coze.openapi.client.audio.transcriptions.CreateTranscriptionsResp; | ||
| import com.coze.openapi.client.common.BaseReq; | ||
| import com.coze.openapi.client.common.BaseResponse; | ||
|
|
||
| import okhttp3.MultipartBody; | ||
| import retrofit2.Call; | ||
| import retrofit2.http.Multipart; | ||
| import retrofit2.http.POST; | ||
| import retrofit2.http.Part; | ||
| import retrofit2.http.Tag; | ||
|
|
||
| public interface AudioTranscriptionAPI { | ||
| @Multipart | ||
| @POST("/v1/audio/transcriptions") | ||
| Call<BaseResponse<CreateTranscriptionsResp>> create( | ||
| @Part MultipartBody.Part file, @Tag BaseReq baseReq); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsReq.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.coze.openapi.client.audio.transcriptions; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| import com.coze.openapi.client.common.BaseReq; | ||
|
|
||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| @Getter | ||
| @SuperBuilder | ||
| @NoArgsConstructor | ||
| @EqualsAndHashCode(callSuper = true) | ||
| public class CreateTranscriptionsReq extends BaseReq { | ||
| /** local file path */ | ||
| private String filePath; | ||
|
|
||
| /* | ||
| * file byte array | ||
| */ | ||
| private byte[] fileBytes; | ||
|
|
||
| /** file name */ | ||
| private String fileName; | ||
|
|
||
| /** file object */ | ||
| private File file; | ||
|
|
||
| public static CreateTranscriptionsReq of(String fileName, byte[] fileBytes) { | ||
| return CreateTranscriptionsReq.builder().fileName(fileName).fileBytes(fileBytes).build(); | ||
| } | ||
|
|
||
| public static CreateTranscriptionsReq of(File file) { | ||
| return CreateTranscriptionsReq.builder().file(file).build(); | ||
| } | ||
|
|
||
| public static CreateTranscriptionsReq of(String filePath) { | ||
| return CreateTranscriptionsReq.builder().filePath(filePath).build(); | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
api/src/main/java/com/coze/openapi/client/audio/transcriptions/CreateTranscriptionsResp.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.coze.openapi.client.audio.transcriptions; | ||
|
|
||
| import com.coze.openapi.client.common.BaseResp; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import lombok.*; | ||
|
|
||
| @Data | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @EqualsAndHashCode(callSuper = true) | ||
| @ToString(callSuper = true) | ||
| public class CreateTranscriptionsResp extends BaseResp { | ||
| @JsonProperty("text") | ||
| private String text; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Implement validation for mutually exclusive file source fields.
The class accepts multiple ways to provide file data (filePath, fileBytes, file object) without validation logic to ensure that at least one valid file source is provided or to handle cases when multiple sources are specified.
Consider adding a validation method that:
Here's a suggested implementation:
@Getter @SuperBuilder @NoArgsConstructor @EqualsAndHashCode(callSuper = true) public class CreateTranscriptionsReq extends BaseReq { /** local file path */ private String filePath; /** file byte array */ private byte[] fileBytes; /** file name */ private String fileName; /** file object */ private File file; + /** + * Validates that this request has at least one valid file source. + * @return true if the request has valid file data + * @throws IllegalArgumentException if no valid file source is provided + */ + public boolean validate() { + if (file != null && file.exists() && file.isFile()) { + return true; + } + if (filePath != null && !filePath.isEmpty()) { + return true; + } + if (fileBytes != null && fileBytes.length > 0 && fileName != null && !fileName.isEmpty()) { + return true; + } + throw new IllegalArgumentException("No valid file source provided. Please provide either a file path, file object, or file bytes with a name."); + } public static CreateTranscriptionsReq of(String fileName, byte[] fileBytes) { return CreateTranscriptionsReq.builder().fileName(fileName).fileBytes(fileBytes).build(); } public static CreateTranscriptionsReq of(File file) { return CreateTranscriptionsReq.builder().file(file).build(); } public static CreateTranscriptionsReq of(String filePath) { return CreateTranscriptionsReq.builder().filePath(filePath).build(); } }📝 Committable suggestion