Skip to content

Commit

Permalink
feat: Enhance API and fix deserialization issues (#22)
Browse files Browse the repository at this point in the history
1. Encapsulated new open api for templates, datasets and workflows.
2. Fixed the bug of deserializing enumeration values.
3. Replaced the deserialized enumeration values with constants.
  • Loading branch information
hanzeINGH authored Jan 10, 2025
1 parent 6c4cdb5 commit e25a777
Show file tree
Hide file tree
Showing 139 changed files with 2,309 additions and 345 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ dependencies {
| chat with image | [ChatWithImageExample.java](example/src/main/java/example/chat/ChatWithImageExample.java) |
| non-stream workflow chat | [RunWorkflowExample.java](example/src/main/java/example/workflow/RunWorkflowExample.java) |
| stream workflow chat | [StreamWorkflowExample.java](example/src/main/java/example/workflow/StreamWorkflowExample.java) |
| stream workflow chat with rx | [StreamWorkflowChatExample.java](example/src/main/java/example/workflow/StreamWorkflowChatExample.java) |
| async workflow run | [AsyncRunWorkflowExample.java](example/src/main/java/example/workflow/AsyncRunWorkflowExample.java) |
| conversation | [CreateConversationExample.java](example/src/main/java/example/conversation/ConversationCreateExample.java) |
| list conversation | [ListConversationsExample.java](example/src/main/java/example/conversation/ConversationsListExample.java) |
| workspace | [ListWorkspaceExample.java](example/src/main/java/example/workspace/WorkspaceListExample.java) |
| create update delete message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/MessageCrudExample.java) |
| list message | [ListWorkspaceExample.java](example/src/main/java/example/conversation/message/MessageListExample.java) |
| create update delete document | [ListWorkspaceExample.java](example/src/main/java/example/datasets/document/DocumentCrudExample.java) |
| create update delete document | [DocumentCrudExample.java](example/src/main/java/example/datasets/document/DocumentCrudExample.java) |
| list document | [DocumentListExample.java](example/src/main/java/example/datasets/document/DocumentListExample.java) |
| create update delete dataset | [DatasetCrudExample.java](example/src/main/java/example/datasets/DatasetCrudExample.java) |
| list dataset | [DatasetListExample.java](example/src/main/java/example/datasets/DatasetListExample.java) |
| update image caption | [ImageCrudExample.java](example/src/main/java/example/datasets/image/ImageCrudExample.java) |
| list image | [ImageListExample.java](example/src/main/java/example/datasets/image/ImageListExample.java) |
| duplicate template | [TemplateDuplicateExample.java](example/src/main/java/example/template/TemplateDuplicateExample.java) |
| initial client | [InitServiceExample.java](example/src/main/java/example/service/InitClientExample.java) |
| how to handle exception | [HandlerExceptionExample.java](example/src/main/java/example/service/HandlerExceptionExample.java) |
| get request log id | [GetLogExample.java](example/src/main/java/example/service/GetLogExample.java) |
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</parent>

<artifactId>coze-api</artifactId>
<version>0.1.6</version>
<version>0.2.0</version>

<scm>
<connection>scm:git:git://github.com/coze-dev/coze-java.git</connection>
Expand Down
41 changes: 41 additions & 0 deletions api/src/main/java/com/coze/openapi/api/DatasetAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.coze.openapi.api;

import com.coze.openapi.client.common.BaseReq;
import com.coze.openapi.client.common.BaseResponse;
import com.coze.openapi.client.dataset.CreateDatasetReq;
import com.coze.openapi.client.dataset.CreateDatasetResp;
import com.coze.openapi.client.dataset.DeleteDatasetResp;
import com.coze.openapi.client.dataset.ListDatasetResp;
import com.coze.openapi.client.dataset.ProcessDatasetReq;
import com.coze.openapi.client.dataset.ProcessDatasetResp;
import com.coze.openapi.client.dataset.UpdateDatasetReq;
import com.coze.openapi.client.dataset.UpdateDatasetResp;

import retrofit2.Call;
import retrofit2.http.*;

public interface DatasetAPI {
@POST("v1/datasets")
Call<BaseResponse<CreateDatasetResp>> create(@Body CreateDatasetReq req, @Tag BaseReq baseReq);

@GET("v1/datasets")
Call<BaseResponse<ListDatasetResp>> list(
@Query("space_id") String spaceID,
@Query("name") String name,
@Query("format_type") Integer formatType,
@Query("page_size") Integer pageSize,
@Query("page_num") Integer pageNum,
@Tag BaseReq baseReq);

@PUT("v1/datasets/{dataset_id}")
Call<BaseResponse<UpdateDatasetResp>> update(
@Path("dataset_id") String datasetID, @Body UpdateDatasetReq req, @Tag BaseReq baseReq);

@DELETE("v1/datasets/{dataset_id}")
Call<BaseResponse<DeleteDatasetResp>> delete(
@Path("dataset_id") String datasetID, @Tag BaseReq baseReq);

@POST("v1/datasets/{dataset_id}/process")
Call<BaseResponse<ProcessDatasetResp>> process(
@Path("dataset_id") String datasetID, @Body ProcessDatasetReq req, @Tag BaseReq baseReq);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.api;

import com.coze.openapi.client.common.BaseReq;
Expand All @@ -16,7 +15,7 @@
import retrofit2.http.POST;
import retrofit2.http.Tag;

public interface DocumentAPI {
public interface DatasetDocumentAPI {

@POST("/open_api/knowledge/document/create")
@Headers({"Content-Type: application/json", "Agw-Js-Conv: str"})
Expand Down
28 changes: 28 additions & 0 deletions api/src/main/java/com/coze/openapi/api/DatasetImageAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.coze.openapi.api;

import com.coze.openapi.client.common.BaseReq;
import com.coze.openapi.client.common.BaseResponse;
import com.coze.openapi.client.dataset.image.ListImageResp;
import com.coze.openapi.client.dataset.image.UpdateImageReq;
import com.coze.openapi.client.dataset.image.UpdateImageResp;

import retrofit2.Call;
import retrofit2.http.*;

public interface DatasetImageAPI {
@PUT("v1/datasets/{dataset_id}/images/{document_id}")
Call<BaseResponse<UpdateImageResp>> update(
@Path("dataset_id") String datasetID,
@Path("document_id") String documentID,
@Body UpdateImageReq req,
@Tag BaseReq baseReq);

@GET("v1/datasets/{dataset_id}/images")
Call<BaseResponse<ListImageResp>> list(
@Path("dataset_id") String datasetID,
@Query("keyword") String keyword,
@Query("has_caption") Boolean hasCaption,
@Query("page_num") Integer pageNum,
@Query("page_size") Integer pageSize,
@Tag BaseReq baseReq);
}
18 changes: 18 additions & 0 deletions api/src/main/java/com/coze/openapi/api/TemplateAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.coze.openapi.api;

import com.coze.openapi.client.common.BaseReq;
import com.coze.openapi.client.common.BaseResponse;
import com.coze.openapi.client.template.DuplicateTemplateReq;
import com.coze.openapi.client.template.DuplicateTemplateResp;

import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Tag;

public interface TemplateAPI {
@POST("/v1/templates/{template_id}/duplicate")
Call<BaseResponse<DuplicateTemplateResp>> duplicate(
@Path("template_id") String templateID, @Body DuplicateTemplateReq req, @Tag BaseReq baseReq);
}
17 changes: 17 additions & 0 deletions api/src/main/java/com/coze/openapi/api/WorkflowChatAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.coze.openapi.api;

import com.coze.openapi.client.common.BaseReq;
import com.coze.openapi.client.workflows.chat.WorkflowChatReq;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST;
import retrofit2.http.Streaming;
import retrofit2.http.Tag;

public interface WorkflowChatAPI {
@POST("/v1/workflows/chat")
@Streaming
Call<ResponseBody> stream(@Body WorkflowChatReq req, @Tag BaseReq baseReq);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* (C)2024 */
package com.coze.openapi.client.audio.common;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/** Audio format types. */
public enum AudioFormat {
WAV("wav"),
PCM("pcm"),
OGG_OPUS("ogg_opus"),
M4A("m4a"),
AAC("aac"),
MP3("mp3");
import lombok.Getter;

@Getter
public class AudioFormat {
public static final AudioFormat WAV = new AudioFormat("wav");
public static final AudioFormat PCM = new AudioFormat("pcm");
public static final AudioFormat OGG_OPUS = new AudioFormat("ogg_opus");
public static final AudioFormat M4A = new AudioFormat("m4a");
public static final AudioFormat AAC = new AudioFormat("aac");
public static final AudioFormat MP3 = new AudioFormat("mp3");

private final String value;

AudioFormat(String value) {
private AudioFormat(String value) {
this.value = value;
}

Expand All @@ -26,11 +27,12 @@ public String getValue() {

@JsonCreator
public static AudioFormat fromString(String value) {
for (AudioFormat format : AudioFormat.values()) {
AudioFormat[] formats = {WAV, PCM, OGG_OPUS, M4A, AAC, MP3};
for (AudioFormat format : formats) {
if (format.value.equals(value)) {
return format;
}
}
throw new IllegalArgumentException("Unknown AudioFormat: " + value);
return new AudioFormat(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* (C)2024 */
package com.coze.openapi.client.audio.common;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/** Language codes. */
public enum LanguageCode {
ZH("zh"),
EN("en"),
JA("ja"),
ES("es"),
ID("id"),
PT("pt");
import lombok.Getter;

@Getter
public class LanguageCode {
public static final LanguageCode ZH = new LanguageCode("zh");
public static final LanguageCode EN = new LanguageCode("en");
public static final LanguageCode JA = new LanguageCode("ja");
public static final LanguageCode ES = new LanguageCode("es");
public static final LanguageCode ID = new LanguageCode("id");
public static final LanguageCode PT = new LanguageCode("pt");

private final String value;

LanguageCode(String value) {
private LanguageCode(String value) {
this.value = value;
}

Expand All @@ -26,11 +27,12 @@ public String getValue() {

@JsonCreator
public static LanguageCode fromString(String value) {
for (LanguageCode code : LanguageCode.values()) {
LanguageCode[] codes = {ZH, EN, JA, ES, ID, PT};
for (LanguageCode code : codes) {
if (code.value.equals(value)) {
return code;
}
}
throw new IllegalArgumentException("Unknown LanguageCode: " + value);
return new LanguageCode(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/* (C)2024 */
package com.coze.openapi.client.audio.rooms.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

public enum AudioCodec {
AACLC("AACLC"),
G711A("G711A"),
OPUS("OPUS"),
G722("G722");
import lombok.Getter;

@Getter
public class AudioCodec {
public static final AudioCodec AACLC = new AudioCodec("AACLC");
public static final AudioCodec G711A = new AudioCodec("G711A");
public static final AudioCodec OPUS = new AudioCodec("OPUS");
public static final AudioCodec G722 = new AudioCodec("G722");

private final String value;

AudioCodec(String value) {
private AudioCodec(String value) {
this.value = value;
}

Expand All @@ -23,11 +25,12 @@ public String getValue() {

@JsonCreator
public static AudioCodec fromString(String value) {
for (AudioCodec codec : AudioCodec.values()) {
AudioCodec[] codecs = {AACLC, G711A, OPUS, G722};
for (AudioCodec codec : codecs) {
if (codec.value.equals(value)) {
return codec;
}
}
throw new IllegalArgumentException("Invalid audio codec: " + value);
return new AudioCodec(value);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.audio.rooms.model;

import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.audio.rooms.model;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.audio.voices.model;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.auth;

import lombok.AllArgsConstructor;
Expand Down
38 changes: 30 additions & 8 deletions api/src/main/java/com/coze/openapi/client/auth/GrantType.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
/* (C)2024 */
package com.coze.openapi.client.auth;

import lombok.AllArgsConstructor;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import lombok.Getter;

@Getter
@AllArgsConstructor
public enum GrantType {
AuthorizationCode("authorization_code"),
DeviceCode("urn:ietf:params:oauth:grant-type:device_code"),
JWTCode("urn:ietf:params:oauth:grant-type:jwt-bearer"),
RefreshToken("refresh_token");
public class GrantType {
public static final GrantType AUTHORIZATION_CODE = new GrantType("authorization_code");
public static final GrantType DEVICE_CODE =
new GrantType("urn:ietf:params:oauth:grant-type:device_code");
public static final GrantType JWT_CODE =
new GrantType("urn:ietf:params:oauth:grant-type:jwt-bearer");
public static final GrantType REFRESH_TOKEN = new GrantType("refresh_token");

private final String value;

private GrantType(String value) {
this.value = value;
}

@JsonValue
public String getValue() {
return value;
}

@JsonCreator
public static GrantType fromString(String value) {
GrantType[] types = {AUTHORIZATION_CODE, DEVICE_CODE, JWT_CODE, REFRESH_TOKEN};
for (GrantType type : types) {
if (type.value.equals(value)) {
return type;
}
}
return new GrantType(value);
}

@Override
public String toString() {
return this.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.auth.scope;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.auth.scope;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.auth.scope;

import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.auth.scope;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* (C)2024 */
package com.coze.openapi.client.bots.model;

import java.util.List;
Expand Down
Loading

0 comments on commit e25a777

Please sign in to comment.