From 1f049e0776dbd1bd2e661e8a1f39538146a7f929 Mon Sep 17 00:00:00 2001 From: 0007 <0007@qq.com> Date: Wed, 27 Aug 2025 19:57:37 +0800 Subject: [PATCH] Add File --- .../llm/chatglm/test/ChatGlmTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/ChatGlmTest.java diff --git a/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/ChatGlmTest.java b/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/ChatGlmTest.java new file mode 100644 index 0000000..434b1b3 --- /dev/null +++ b/agents-flex-llm/agents-flex-llm-chatglm/src/test/java/com/agentsflex/llm/chatglm/test/ChatGlmTest.java @@ -0,0 +1,52 @@ +package com.agentsflex.llm.chatglm.test; + +import com.agentsflex.core.document.Document; +import com.agentsflex.core.llm.Llm; +import com.agentsflex.core.llm.embedding.EmbeddingOptions; +import com.agentsflex.core.llm.response.AiMessageResponse; +import com.agentsflex.core.prompt.FunctionPrompt; +import com.agentsflex.core.store.VectorData; +import com.agentsflex.llm.chatglm.ChatglmLlm; +import com.agentsflex.llm.chatglm.ChatglmLlmConfig; +import org.junit.Test; + +import java.util.Arrays; + +public class ChatGlmTest { + + public static void main(String[] args) { + ChatglmLlmConfig config = new ChatglmLlmConfig(); + config.setApiKey("**.***********************"); + + Llm llm = new ChatglmLlm(config); + llm.chatStream("你叫什么名字", (context, response) -> System.out.println(response.getMessage().getContent())); + } + + + @Test + public void testEmbedding() { + ChatglmLlmConfig config = new ChatglmLlmConfig(); + config.setApiKey("**.***********************"); + + Llm llm = new ChatglmLlm(config); + Document document = new Document(); + document.setContent("你好"); + VectorData embeddings = llm.embed(document, EmbeddingOptions.DEFAULT); + System.out.println(Arrays.toString(embeddings.getVector())); + } + + + @Test + public void testFunctionCalling() { + ChatglmLlmConfig config = new ChatglmLlmConfig(); + config.setApiKey("**.***********************"); + + Llm llm = new ChatglmLlm(config); + + FunctionPrompt prompt = new FunctionPrompt("今天北京的天气怎么样", WeatherFunctions.class); + AiMessageResponse response = llm.chat(prompt); + + System.out.println(response.callFunctions()); + } + +}