package com.yb;
|
/*
|
*@title SimpleTest
|
*@description
|
*@author yb
|
*@version 1.0
|
*@create 2024/5/28 20:44
|
*/
|
|
import jakarta.annotation.Resource;
|
import org.junit.jupiter.api.Test;
|
import org.springframework.ai.chat.model.ChatResponse;
|
import org.springframework.ai.chat.prompt.Prompt;
|
import org.springframework.ai.ollama.OllamaChatModel;
|
import org.springframework.ai.ollama.api.OllamaOptions;
|
import org.springframework.boot.test.context.SpringBootTest;
|
import reactor.core.publisher.Flux;
|
|
@SpringBootTest
|
public class SimpleTest {
|
|
@Resource
|
private OllamaChatModel chatModel;
|
|
// @Test
|
// public void test(){
|
// //使用下载的 gemma:7b 配置模型属性,模型属性配置可以参考 OllamaChatModel 构造函数
|
// OllamaOptions options = OllamaOptions.create().withModel("llama3:8b");
|
// Prompt prompt = new Prompt("你好", options);
|
// //调用聊天模型,获取返回值对象
|
// ChatResponse res = chatModel.call(prompt);
|
// //获取 AI 回答字符串
|
// System.out.println(res.getResult().getOutput().getContent());
|
// }
|
//
|
// /**
|
// * 流式返回数据
|
// */
|
// @Test
|
// public void test2(){
|
// //使用下载的 gemma:7b 配置模型属性,模型属性配置可以参考 OllamaChatModel 构造函数
|
// OllamaOptions options = OllamaOptions.create().withModel("llama3:8b");
|
// Prompt prompt = new Prompt("你好", options);
|
// Flux<ChatResponse> flux = chatModel.stream(prompt);
|
// flux.toStream().forEach(res -> {
|
// System.out.println(res.getResult().getOutput().getContent());
|
// });
|
// }
|
|
@Test
|
public void test3(){
|
String res = chatModel.call("java 排序算法");
|
//获取模型返回结果
|
System.out.println(res);
|
}
|
|
}
|