From 7cd52d195fd6bbc71862a11278ef67db7ca8a31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=82=85=E5=93=A5?= Date: Thu, 14 Dec 2023 17:38:57 +0800 Subject: [PATCH] Update README.md --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index 26c3297..028f125 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,55 @@ public class ApiTest { // 等待 new CountDownLatch(1).await(); } + + /** + * 同步请求,future 模型,通过对流式的改造提供同步 + */ + @Test + public void test_completions_future() throws ExecutionException, InterruptedException { + // 入参;模型、请求信息 + ChatCompletionRequest request = new ChatCompletionRequest(); + request.setModel(Model.CHATGLM_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("写个java冒泡排序") + .build()); + } + }); + + CompletableFuture future = openAiSession.completions(request); + String response = future.get(); + + log.info("测试结果:{}", response); + } + + /** + * 同步请求,官网自带的同步方法 + */ + @Test + public void test_completions_sync() throws IOException { + // 入参;模型、请求信息 + ChatCompletionRequest request = new ChatCompletionRequest(); + request.setModel(Model.CHATGLM_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("写个java冒泡排序") + .build()); + } + }); + + ChatCompletionSyncResponse response = openAiSession.completionsSync(request); + + log.info("测试结果:{}", JSON.toJSONString(response)); + } } ``` -- GitLab