diff --git a/curl.sh b/curl.sh index 7559105bcd4a66b3c1d8620425b8712627bc68c1..486c862093f8e49589544b1793b89f111a369177 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 e66540346502134c5efe75b6edc0f980c69d3351..df0bf7e8d042b37c15cfd7f5db0205d70f531e56 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 2c91cd3beab9d54cd270e3c8113b3c0249df22ee..bdd1d8801c8f57597a94ea711040d1f50f50de43 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());