Skip to content

Commit 550dd50

Browse files
authored
feat: support reasoning_content (#31)
1 parent 5f15771 commit 550dd50

6 files changed

Lines changed: 32 additions & 21 deletions

File tree

core/src/main/java/ai/z/openapi/service/model/ChatMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class ChatMessage {
1818

1919
private Object content;
2020

21+
@JsonProperty("reasoning_content")
22+
private String reasoningContent;
23+
2124
private Audio audio;
2225

2326
private String name;

core/src/main/java/ai/z/openapi/service/model/ChatThinking.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
public class ChatThinking {
1515

1616
/**
17-
* Model thinking type Only support by GLM-4.5 and above models. This parameter is
18-
* used to control whether the model enable the chain of thought. value: enabled,
19-
* disabled
17+
* Model thinking type Only support by GLM-4.5 and above models.<br>
18+
* Value: enabled, disabled <br>
19+
* Control whether the model enable the chain of thought.<br>
20+
* When enabled, GLM-4.5 will automatically determine whether to think, while GLM-4.5V
21+
* will think compulsorily.
2022
*/
2123
private String type;
2224

core/src/main/java/ai/z/openapi/service/model/Choice.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class Choice {
2121
@JsonProperty("index")
2222
private Long index;
2323

24+
/**
25+
* Reasoning content, supports by GLM-4.5 series.
26+
*/
2427
@JsonProperty("message")
2528
private ChatMessage message;
2629

core/src/main/java/ai/z/openapi/service/model/Delta.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class Delta {
1818

1919
private String content;
2020

21+
@JsonProperty("reasoning_content")
22+
private String reasoningContent;
23+
2124
private Audio audio;
2225

2326
@JsonProperty("tool_calls")

samples/src/main/ai.z.openapi.samples/ChatCompletionExample.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,25 @@ public static void main(String[] args) {
2525

2626
// Create chat request
2727
ChatCompletionCreateParams request = ChatCompletionCreateParams.builder()
28-
.model(Constants.ModelChatGLM4_5)
29-
.messages(Arrays.asList(
30-
ChatMessage.builder()
31-
.role(ChatMessageRole.USER.value())
32-
.content("Hello, how are you?")
33-
.build()
34-
))
35-
.stream(false)
36-
.temperature(0.7f)
37-
.maxTokens(1024)
38-
.build();
28+
.model(Constants.ModelChatGLM4_5)
29+
.messages(Arrays.asList(
30+
ChatMessage.builder()
31+
.role(ChatMessageRole.USER.value())
32+
.content("Hello, how to learn english?")
33+
.build()
34+
))
35+
.stream(false)
36+
.thinking(ChatThinking.builder().type("enabled").build())
37+
.temperature(0.7f)
38+
.maxTokens(1024)
39+
.build();
3940

4041
try {
4142
// Execute request
4243
ChatCompletionResponse response = client.chat().createChatCompletion(request);
4344

4445
if (response.isSuccess()) {
45-
Object content = response.getData().getChoices().get(0).getMessage().getContent();
46+
Object content = response.getData().getChoices().get(0).getMessage();
4647
System.out.println("Response: " + content);
4748
} else {
4849
System.err.println("Error: " + response.getMsg());

samples/src/main/ai.z.openapi.samples/StreamingChatExample.java renamed to samples/src/main/ai.z.openapi.samples/ChatCompletionStreamExample.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Streaming Chat Example
1010
* Demonstrates how to use ZaiClient for streaming chat conversations
1111
*/
12-
public class StreamingChatExample {
12+
public class ChatCompletionStreamExample {
1313

1414
public static void main(String[] args) {
1515
// Create client
@@ -25,6 +25,7 @@ public static void main(String[] args) {
2525
.content("Tell me a story")
2626
.build()
2727
))
28+
.thinking(ChatThinking.builder().type("enabled").build())
2829
.stream(true) // Enable streaming response
2930
.build();
3031

@@ -39,11 +40,9 @@ public static void main(String[] args) {
3940
// Process each streaming response chunk
4041
if (data.getChoices() != null && !data.getChoices().isEmpty()) {
4142
// Get content of current chunk
42-
String content = data.getChoices().get(0).getDelta().getContent();
43-
if (content != null) {
44-
// Print current chunk content
45-
System.out.print(content);
46-
}
43+
Delta delta = data.getChoices().get(0).getDelta();
44+
// Print current chunk
45+
System.out.print(delta + "\n");
4746
}
4847
},
4948
error -> System.err.println("\nStream error: " + error.getMessage()),

0 commit comments

Comments
 (0)