From 58438b86dedca37ee70d50aa93cbad880ac37a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5?= <184172133@qq.com> Date: Sat, 30 Mar 2024 18:57:25 +0800 Subject: [PATCH] =?UTF-8?q?docs=EF=BC=9Av2.1=20=E5=8F=91=E5=B8=83=20-=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/bugstack/chatglm/test/ApiTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/test/java/cn/bugstack/chatglm/test/ApiTest.java b/src/test/java/cn/bugstack/chatglm/test/ApiTest.java index 0be80a9..cef643f 100644 --- a/src/test/java/cn/bugstack/chatglm/test/ApiTest.java +++ b/src/test/java/cn/bugstack/chatglm/test/ApiTest.java @@ -40,7 +40,7 @@ public class ApiTest { // 1. 配置文件 Configuration configuration = new Configuration(); configuration.setApiHost("https://open.bigmodel.cn/"); - configuration.setApiSecretKey("62ddec38b1d0b9a7b0fddaf271e6ed90.HpD0SUBUlvqd05ey"); + configuration.setApiSecretKey("74e0b7fff9a578e2137300bcd58ae062.q0ABClJJS50rHQnn"); configuration.setLevel(HttpLoggingInterceptor.Level.BODY); // 2. 会话工厂 OpenAiSessionFactory factory = new DefaultOpenAiSessionFactory(configuration); @@ -125,7 +125,7 @@ public class ApiTest { // 入参;模型、请求信息 ChatCompletionRequest request = new ChatCompletionRequest(); - request.setModel(Model.GLM_3_5_TURBO); // GLM_3_5_TURBO、GLM_4 + request.setModel(Model.GLM_4); // GLM_3_5_TURBO、GLM_4 request.setIsCompatible(false); // 24年1月发布的 glm-3-turbo、glm-4 支持函数、知识库、联网功能 request.setTools(new ArrayList() { @@ -280,7 +280,7 @@ public class ApiTest { * 同步请求 */ @Test - public void test_completions_sync() throws Exception { + public void test_completions_sync_01() throws Exception { // 入参;模型、请求信息 ChatCompletionRequest request = new ChatCompletionRequest(); request.setModel(Model.GLM_3_5_TURBO); // chatGLM_6b_SSE、chatglm_lite、chatglm_lite_32k、chatglm_std、chatglm_pro @@ -312,6 +312,28 @@ public class ApiTest { log.info("测试结果:{}", JSON.toJSONString(response)); } + @Test + public void test_completions_sync_02() throws Exception { + // 入参;模型、请求信息 + ChatCompletionRequest request = new ChatCompletionRequest(); + request.setModel(Model.GLM_3_5_TURBO); // chatGLM_6b_SSE、chatglm_lite、chatglm_lite_32k、chatglm_std、chatglm_pro + request.setPrompt(new ArrayList() { + private static final long serialVersionUID = -7988151926241837899L; + + { + add(ChatCompletionRequest.Prompt.builder() + .role(Role.user.getCode()) + .content("1+1") + .build()); + } + }); + + ChatCompletionSyncResponse response = openAiSession.completionsSync(request); + + log.info("测试结果:{}", JSON.toJSONString(response)); + System.out.println(response.getChoices().get(0).getMessage().getContent()); + } + @Test public void test_genImages() throws Exception { ImageCompletionRequest request = new ImageCompletionRequest(); -- GitLab