Skip to content

Commit ef832e7

Browse files
author
BitsAdmin
committed
Merge 'feat/arkruntime_add_json_schema' into 'integration_2026-01-15_1104234777858'
feat: [development task] ark runtime (2032532) See merge request: !857
2 parents 4784c0d + a4cb32c commit ef832e7

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/model/responses/common/ResponsesTextFormat.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package com.volcengine.ark.runtime.model.responses.common;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.JsonNode;
45

56
public class ResponsesTextFormat {
67
@JsonProperty("type")
78
private String type;
89

10+
@JsonProperty("name")
11+
private String name;
12+
13+
@JsonProperty("schema")
14+
private JsonNode schema;
15+
916
public String getType() {
1017
return type;
1118
}
@@ -14,6 +21,22 @@ public void setType(String type) {
1421
this.type = type;
1522
}
1623

24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
public JsonNode getSchema() {
33+
return schema;
34+
}
35+
36+
public void setSchema(JsonNode schema) {
37+
this.schema = schema;
38+
}
39+
1740
@Override
1841
public String toString() {
1942
return "ResponsesTextFormat{" +
@@ -27,15 +50,29 @@ public static Builder builder() {
2750

2851
public static class Builder {
2952
private String type;
53+
private String name;
54+
private JsonNode schema;
3055

3156
public Builder type(String type) {
3257
this.type = type;
3358
return this;
3459
}
3560

61+
public Builder name(String name) {
62+
this.name = name;
63+
return this;
64+
}
65+
66+
public Builder schema(JsonNode schema) {
67+
this.schema = schema;
68+
return this;
69+
}
70+
3671
public ResponsesTextFormat build() {
3772
ResponsesTextFormat responsesTextFormat = new ResponsesTextFormat();
3873
responsesTextFormat.setType(type);
74+
responsesTextFormat.setName(name);
75+
responsesTextFormat.setSchema(schema);
3976
return responsesTextFormat;
4077
}
4178
}

volcengine-java-sdk-ark-runtime/src/main/java/com/volcengine/ark/runtime/model/responses/constant/ResponsesConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class ResponsesConstants {
6666
// TextType.Enum
6767
public static final String TEXT_TYPE_TEXT = "text";
6868
public static final String TEXT_TYPE_JSON_OBJECT = "json_object";
69+
public static final String TEXT_TYPE_JSON_SCHEMA = "json_schema";
6970

7071
// ToolChoiceMode.Enum
7172
public static final String TOOL_CHOICE_MODE_AUTO = "auto";

volcengine-java-sdk-ark-runtime/test/java/com/volcengine/ark/runtime/CreateResponseExample.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.volcengine.ark.runtime;
22

3+
import com.fasterxml.jackson.databind.JsonNode;
34
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.volcengine.ark.runtime.model.responses.common.ResponsesCaching;
6+
import com.volcengine.ark.runtime.model.responses.common.ResponsesText;
7+
import com.volcengine.ark.runtime.model.responses.common.ResponsesTextFormat;
58
import com.volcengine.ark.runtime.model.responses.common.ResponsesThinking;
69
import com.volcengine.ark.runtime.model.responses.constant.ResponsesConstants;
710
import com.volcengine.ark.runtime.model.responses.content.*;
@@ -32,6 +35,7 @@
3235
public class CreateResponseExample {
3336

3437
private static final String modelName = "doubao-seed-1-6-250615";
38+
private static final String testSchema = "{\"type\":\"object\",\"properties\":{\"steps\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"explanation\":{\"type\":\"string\"},\"output\":{\"type\":\"string\"}},\"required\":[\"explanation\",\"output\"],\"additionalProperties\":false}},\"final_answer\":{\"type\":\"string\"}},\"required\":[\"steps\",\"final_answer\"],\"additionalProperties\":false}";
3539

3640
public static void main(String[] args) {
3741
String apiKey = System.getenv("ARK_API_KEY");
@@ -334,6 +338,28 @@ public static void main(String[] args) {
334338
System.err.println("Create Cached Response Error " + e.getMessage());
335339
}
336340

341+
try {
342+
System.out.println("\n----- [Request with JsonSchema] Request 8-----");
343+
CreateResponsesRequest request8 = CreateResponsesRequest.builder()
344+
.input(ResponsesInput.builder().stringValue("return in json format how can I solve 8x + 7 = -23").build())
345+
.model(modelName)
346+
.stream(false)
347+
.text(ResponsesText.builder().format(ResponsesTextFormat.builder()
348+
.type(ResponsesConstants.TEXT_TYPE_JSON_SCHEMA)
349+
.name("math_reasoning")
350+
.schema(new ObjectMapper().readTree(testSchema))
351+
.build()).build())
352+
.build();
353+
354+
ResponseObject response8 = service.createResponse(request8);
355+
System.out.println("=== response 8 ===");
356+
printResponseObject(response8);
357+
} catch (Exception e) {
358+
System.err.println("Create Response 8 Error " + e.getMessage());
359+
}
360+
361+
362+
337363
service.shutdownExecutor();
338364
}
339365

0 commit comments

Comments
 (0)