This commit is contained in:
2025-08-27 19:57:31 +08:00
parent f6286d1ac1
commit 18b829e886

View File

@@ -0,0 +1,57 @@
package com.agentsflex.llm.qianfan;
import com.agentsflex.core.document.Document;
import com.agentsflex.core.llm.Llm;
import com.agentsflex.core.llm.embedding.EmbeddingOptions;
import com.agentsflex.core.llm.exception.LlmException;
import com.agentsflex.core.llm.response.AiMessageResponse;
import com.agentsflex.core.prompt.FunctionPrompt;
import com.agentsflex.core.store.VectorData;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
public class QianFanLlmTest {
QianFanLlmConfig config = new QianFanLlmConfig();
@Before
public void setUp() {
config.setApiKey("***");
config.setDebug(true);
}
@Test(expected = LlmException.class)
public void testChat() {
Llm llm = new QianFanLlm(config);
String response = llm.chat("请问你叫什么名字");
System.out.println(response);
}
@Test()
public void testChatStream() throws InterruptedException {
Llm llm = new QianFanLlm(config);
llm.chatStream("who are your", (context, response) -> System.out.print(response.getMessage().getContent()));
Thread.sleep(2000);
}
@Test()
public void testFunctionChat() {
Llm llm = new QianFanLlm(config);
FunctionPrompt prompt = new FunctionPrompt("今天北京的天气怎么样", WeatherFunctions.class);
AiMessageResponse response = llm.chat(prompt);
System.out.println(response.callFunctions());
}
@Test()
public void testEmb() {
Llm llm = new QianFanLlm(config);
Document document = new Document();
document.setContent("你好");
VectorData embeddings = llm.embed(document, EmbeddingOptions.DEFAULT);
System.out.println(Arrays.toString(embeddings.getVector()));
}
}