Skip to content

添加Ollama客户端支持 #3982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2025
Merged

Conversation

yangruoyu-yumeisoft
Copy link
Contributor

添加Ollama客户端支持,使用方法如下:

// 创建AI服务
OllamaService aiService = AIServiceFactory.getAIService(
	new AIConfigBuilder(ModelName.OLLAMA.getValue())
		.setApiUrl("http://localhost:11434")
		.setModel("qwen2.5-coder:32b")
		.build(),
	OllamaService.class
);

// 构造上下文
List<Message> messageList=new ArrayList<>();
messageList.add(new Message("system","你是一个疯疯癫癫的机器人"));
messageList.add(new Message("user","你能帮我做什么"));

// 输出对话结果
System.out.println(aiService.chat(messageList));

// 流式输出
aiService.chat("请帮我写一段描写Hutool的散文", System.err::println);

// 拉取模型(高耗时操作)
aiService.pullModel("qwen3:32b");

修改描述

  1. [新特性] hutool-ai添加Ollama支持,适用于私有化部署大模型或内网使用的场景

提交前自测

  • 自测通过

// 创建AI服务
OllamaService aiService = AIServiceFactory.getAIService(
	new AIConfigBuilder(ModelName.OLLAMA.getValue())
		.setApiUrl("http://localhost:11434")
		.setModel("qwen2.5-coder:32b")
		.build(),
	OllamaService.class
);

// 构造上下文
List<Message> messageList=new ArrayList<>();
messageList.add(new Message("system","你是一个疯疯癫癫的机器人"));
messageList.add(new Message("user","你能帮我做什么"));

// 输出对话结果
System.out.println(aiService.chat(messageList));

// 流式输出
aiService.chat("请帮我写一段描写Hutool的散文", System.err::println);

// 拉取模型(高耗时操作)
aiService.pullModel("qwen3:32b");
@elichow
Copy link
Collaborator

elichow commented Jun 26, 2025

@yangruoyu-yumeisoft 可以把测试代码也加上

@yangruoyu-yumeisoft
Copy link
Contributor Author

yangruoyu-yumeisoft commented Jun 26, 2025

测试代码已添加,并已测试通过 :)
image

@elichow
Copy link
Collaborator

elichow commented Jun 27, 2025

System.out.println();代码去一下吧,test的时候容易报错,其他的没问题了 @yangruoyu-yumeisoft

@yangruoyu-yumeisoft
Copy link
Contributor Author

已去掉 👌

@elichow elichow merged commit d23b9e1 into chinabugotech:v5-dev Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants