feat: support glm 4.5 (#23)
This commit is contained in:
parent
0c3cd5cee0
commit
a31894fbfc
4 changed files with 41 additions and 18 deletions
|
|
@ -35,6 +35,26 @@ public final class Constants {
|
|||
// Text Generation Models
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* GLM-4.5 model code
|
||||
*/
|
||||
public static final String ModelChatGLM4_5 = "glm-4.5";
|
||||
|
||||
/**
|
||||
* GLM-4.5-Air model code
|
||||
*/
|
||||
public static final String ModelChatGLM4_5_AIR = "glm-4.5-air";
|
||||
|
||||
/**
|
||||
* GLM-4.5-X model code
|
||||
*/
|
||||
public static final String ModelChatGLM4_5_X = "glm-4.5-x";
|
||||
|
||||
/**
|
||||
* GLM-4.5-AirX model code
|
||||
*/
|
||||
public static final String ModelChatGLM4_5_AIRX = "glm-4.5-airx";
|
||||
|
||||
/**
|
||||
* GLM-4 Plus model - Enhanced version with improved capabilities.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ import lombok.NoArgsConstructor;
|
|||
public class ChatThinking {
|
||||
|
||||
/**
|
||||
* Model thinking type
|
||||
* Model thinking type Only support by GLM-4.5 and above models. This parameter is
|
||||
* used to control whether the model enable the chain of thought. value: enabled,
|
||||
* disabled
|
||||
*/
|
||||
private String type;
|
||||
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -45,7 +45,7 @@
|
|||
</scm>
|
||||
|
||||
<properties>
|
||||
<revision>0.0.0.4-alpha</revision>
|
||||
<revision>0.0.0.5-alpha</revision>
|
||||
<java.version>8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ai.z.openapi.samples;
|
|||
import ai.z.openapi.ZaiClient;
|
||||
import ai.z.openapi.service.model.*;
|
||||
import ai.z.openapi.core.Constants;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
|
|
@ -10,35 +11,35 @@ import java.util.Arrays;
|
|||
* Demonstrates how to use ZaiClient for basic chat conversations
|
||||
*/
|
||||
public class ChatCompletionExample {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Create client, recommended to set API Key via environment variable
|
||||
// export ZAI_API_KEY=your.api.key
|
||||
ZaiClient client = ZaiClient.builder().ofZHIPU().build();
|
||||
|
||||
|
||||
// Or set API Key via code
|
||||
// ZaiClient client = ZaiClient.builder()
|
||||
// .apiKey("your.api.key.your.api.secret")
|
||||
// .build();
|
||||
|
||||
|
||||
// Create chat request
|
||||
ChatCompletionCreateParams request = ChatCompletionCreateParams.builder()
|
||||
.model(Constants.ModelChatGLM4)
|
||||
.messages(Arrays.asList(
|
||||
ChatMessage.builder()
|
||||
.role(ChatMessageRole.USER.value())
|
||||
.content("Hello, how are you?")
|
||||
.build()
|
||||
))
|
||||
.stream(false)
|
||||
.temperature(0.7f)
|
||||
.maxTokens(1024)
|
||||
.build();
|
||||
|
||||
.model(Constants.ModelChatGLM4_5_AIR)
|
||||
.messages(Arrays.asList(
|
||||
ChatMessage.builder()
|
||||
.role(ChatMessageRole.USER.value())
|
||||
.content("Hello, how are you?")
|
||||
.build()
|
||||
))
|
||||
.stream(false)
|
||||
.temperature(0.7f)
|
||||
.maxTokens(1024)
|
||||
.build();
|
||||
|
||||
try {
|
||||
// Execute request
|
||||
ChatCompletionResponse response = client.chat().createChatCompletion(request);
|
||||
|
||||
|
||||
if (response.isSuccess()) {
|
||||
Object content = response.getData().getChoices().get(0).getMessage().getContent();
|
||||
System.out.println("Response: " + content);
|
||||
|
|
|
|||
Loading…
Reference in a new issue