From 196591149715838ae801c65e79d07e88a3d92ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5?= <184172133@qq.com> Date: Thu, 2 Nov 2023 22:12:11 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E8=A1=A5=E5=85=85=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- curl.sh | 2 +- .../java/cn/bugstack/chatglm/model/Role.java | 2 ++ .../cn/bugstack/chatglm/test/ApiTest.java | 20 ++++++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/curl.sh b/curl.sh index 7559105..486c862 100644 --- a/curl.sh +++ b/curl.sh @@ -1,5 +1,5 @@ curl -X POST \ - -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsInNpZ25fdHlwZSI6IlNJR04ifQ.eyJhcGlfa2V5IjoiNGUwODdlNDEzNTMwNmVmNGE2NzZmMGNjZTNjZWU1NjAiLCJleHAiOjE2OTcwNjcyOTk0MjIsInRpbWVzdGFtcCI6MTY5NzA2NTQ5OTQyMn0.wuKqloevMjt_E1LHWQ5sDYW5v52nhFQFVG4RMqp_hPc" \ + -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsInNpZ25fdHlwZSI6IlNJR04ifQ.eyJhcGlfa2V5IjoiNzdkNDg2YTMyOGQ1ZGRlNTBiOTE0Y2UxMDJlNzFkNGYiLCJleHAiOjE2OTczNTU1NTgwMTQsInRpbWVzdGFtcCI6MTY5NzM1Mzc1ODAxNH0.KNOXxlwULWcvNZ9CvdxGLgYlf4pDNA0az2FoFV7DX7Q" \ -H "Content-Type: application/json" \ -H "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)" \ -H "Accept: text/event-stream" \ diff --git a/src/main/java/cn/bugstack/chatglm/model/Role.java b/src/main/java/cn/bugstack/chatglm/model/Role.java index e665403..df0bf7e 100644 --- a/src/main/java/cn/bugstack/chatglm/model/Role.java +++ b/src/main/java/cn/bugstack/chatglm/model/Role.java @@ -20,6 +20,8 @@ public enum Role { * 模型生成的内容,role位assistant */ assistant("assistant"), + system("system"), + ; private final String code; diff --git a/src/test/java/cn/bugstack/chatglm/test/ApiTest.java b/src/test/java/cn/bugstack/chatglm/test/ApiTest.java index 2c91cd3..bdd1d88 100644 --- a/src/test/java/cn/bugstack/chatglm/test/ApiTest.java +++ b/src/test/java/cn/bugstack/chatglm/test/ApiTest.java @@ -35,7 +35,7 @@ public class ApiTest { // 1. 配置文件 Configuration configuration = new Configuration(); configuration.setApiHost("https://open.bigmodel.cn/"); - configuration.setApiSecretKey("4e087e4135306ef4a676f0cce3cee560.sgP2DUsWEVPxk0UI"); + configuration.setApiSecretKey("d570f7c5d289cdac2abdfdc562e39f3f.trqz1dH8ZK6ED7Pg"); // 2. 会话工厂 OpenAiSessionFactory factory = new DefaultOpenAiSessionFactory(configuration); // 3. 开启会话 @@ -54,10 +54,24 @@ public class ApiTest { private static final long serialVersionUID = -7988151926241837899L; { + add(ChatCompletionRequest.Prompt.builder() .role(Role.user.getCode()) - .content("写个java冒泡排序") + .content("你是一个专业的互联网文章作者,擅长互联网技术介绍、互联网商业、技术应用等方面的写作。\n" + + "接下来你要根据用户给你的主题,拓展生成用户想要的文字内容,内容可能是一篇文章、一个开头、一段介绍文字、文章总结、文章结尾等等。\n" + + "要求语言通俗易懂、幽默有趣,并且要以第一人称的口吻。") .build()); + + add(ChatCompletionRequest.Prompt.builder() + .role(Role.system.getCode()) + .content("请问有什么需要帮助的吗") + .build()); + + add(ChatCompletionRequest.Prompt.builder() + .role(Role.user.getCode()) + .content("Okay") + .build()); + } }); @@ -90,7 +104,7 @@ public class ApiTest { // 1. 配置文件 Configuration configuration = new Configuration(); configuration.setApiHost("https://open.bigmodel.cn/"); - configuration.setApiSecretKey("4e087e4135306ef4a676f0cce3cee560.sgP2DUsWEVPxk0UI"); + configuration.setApiSecretKey("4d00226f242793b9c267a64ab2eaf5cb.aIwQNiG59MhSWJbn"); // 2. 获取Token String token = BearerTokenUtils.getToken(configuration.getApiKey(), configuration.getApiSecret()); -- GitLab