- Solon Ai
Solon Ai
Content
Solon-AI
Java AI(智能体) 全场景应用开发框架(支持已知 AI 开发的各种能力)
【基于 Solon 应用开发框架构建】
https://solon.noear.org/article/learn-solon-ai
简介
面向全场景的 Java AI 应用开发框架(支持已知 AI 开发的各种能力)。是 Solon 项目的一部分。也可嵌入到 SpringBoot2、jFinal、Vert.x 等框架中使用。
其中 solon-ai(& mcp) 的嵌入示例:
- https://gitee.com/opensolon/solon-ai-mcp-embedded-examples
- https://gitcode.com/opensolon/solon-ai-mcp-embedded-examples
- https://github.com/opensolon/solon-ai-mcp-embedded-examples
主要接口体验示例
- ChatModel(通用接口,基于方言适配实现不同提供商与模型的扩展)
ChatModel chatModel = ChatModel.of("http://127.0.0.1:11434/api/chat")
.provider("ollama") //需要指定供应商,用于识别接口风格(也称为方言)
.model("qwen2.5:1.5b")
.build();
//同步调用,并打印响应消息
System.out.println(chatModel.prompt("hello").call().getMessage());
//响应式调用
chatModel.prompt("hello").stream(); //Publisher<ChatResponse>
- Function Calling(或者 Tool Calling)
//可以添加默认工具(即所有请求有产),或请求时工具
chatModel.prompt("今天杭州的天气情况?")
.options(op->op.toolsAdd(new FunctionTools()))
.call();
- Vision(多媒体感知)
chatModel.prompt(ChatMessage.ofUser("这图里有方块吗?", Image.ofUrl(imageUrl)))
.call();
- RAG(EmbeddingModel,Repository,DocumentLoader,RerankingModel)
//构建知识库
EmbeddingModel embeddingModel = EmbeddingModel.of(apiUrl).apiKey(apiKey).provider(provider).model(model).batchSize(10).build();
RerankingModel rerankingModel = RerankingModel.of(apiUrl).apiKey(apiKey).provider(provider).model(model).build();
InMemoryRepository repository = new InMemoryRepository(TestUtils.getEmbeddingModel()); //3.初始化知识库
repository.insert(new PdfLoader(pdfUri).load());
//检索
List<Document> docs = repository.search(query);
//如果有需要,可以重排一下
docs = rerankingModel.rerank(query, docs);
//提示语增强是
ChatMessage message = ChatMessage.augment(query, docs);
//调用大模型
chatModel.prompt(message)
.call();
- Ai Flow(模拟实现 Dify 的流程应用)
id: demo1
layout:
- type: "start"
- task: "@VarInput"
meta:
message: "Solon 是谁开发的?"
- task: "@EmbeddingModel"
meta:
embeddingConfig: # "@type": "org.noear.solon.ai.embedding.EmbeddingConfig"
provider: "ollama"
model: "bge-m3"
apiUrl: "http://127.0.0.1:11434/api/embed"
- task: "@InMemoryRepository"
meta:
documentSources:
- "https://solon.noear.org/article/about?format=md"
splitPipeline:
- "org.noear.solon.ai.rag.splitter.RegexTextSplitter"
- "org.noear.solon.ai.rag.splitter.TokenSizeTextSplitter"
- task: "@ChatModel"
meta:
systemPrompt: "你是个知识库"
stream: false
chatConfig: # "@type": "org.noear.solon.ai.chat.ChatConfig"
provider: "ollama"
model: "qwen2.5:1.5b"
apiUrl: "http://127.0.0.1:11434/api/chat"
- task: "@ConsoleOutput"
# FlowEngine flowEngine = FlowEngine.newInstance();
# ...
# flowEngine.eval("demo1");
- MCP server(支持多端点)
//组件方式构建
@McpServerEndpoint(name="mcp-case1", sseEndpoint = "/case1/sse")
public class McpServer {
@ToolMapping(description = "查询天气预报")
public String getWeather(@Param(description = "城市位置") String location) {
return "晴,14度";
}
@ResourceMapping(uri = "config://app-version", description = "获取应用版本号", mimeType = "text/config")
public String getAppVersion() {
return "v3.2.0";
}
@PromptMapping(description = "生成关于某个主题的提问")
public Collection<ChatMessage> askQuestion(@Param(description = "主题") String topic) {
return Arrays.asList(
ChatMessage.ofUser("请解释一下'" + topic + "'的概念?")
);
}
}
//原生 java 方式构建
McpServerEndpointProvider serverEndpoint = McpServerEndpointProvider.builder()
.name("mcp-case2")
.sseEndpoint("/case2/sse")
.build();
serverEndpoint.addTool(new MethodToolProvider(new McpServerTools())); //添加工具
serverEndpoint.addResource(new MethodResourceProvider(new McpServerResources())); //添加资源
serverEndpoint.addPrompt(new MethodPromptProvider(new McpServerPrompts())); //添加提示语
serverEndpoint.postStart();
- MCP client
McpClientToolProvider clientToolProvider = McpClientToolProvider.builder()
.apiUrl("http://localhost:8080/case1/sse")
.build();
String rst = clientToolProvider.callToolAsText("getWeather", Map.of("location", "杭州"))
.getContent();
- MCP Proxy (示例,把 gitee mcp stdio 转为 sse 服务)
配置参考自:https://gitee.com/oschina/mcp-gitee
@McpServerEndpoint(name = "mcp-case3", sseEndpoint="/case3/sse")
public class McpStdioToSseServerDemo implements ToolProvider {
McpClientProvider stdioToolProvider = McpClientProvider.builder()
.channel(McpChannel.STDIO) //表示使用 stdio
.serverParameters(ServerParameters.builder("npx")
.args("-y", "@gitee/mcp-gitee@latest")
.addEnvVar("GITEE_API_BASE", "https://gitee.com/api/v5")
.addEnvVar("GITEE_ACCESS_TOKEN", "<your personal access token>")
.build())
.build();
@Override
public Collection<FunctionTool> getTools() {
return stdioToolProvider.getTools();
}
}
Solon 项目相关代码仓库
| 代码仓库 | 描述 |
|---|---|
| /opensolon/solon | Solon ,主代码仓库 |
| /opensolon/solon-examples | Solon ,官网配套示例代码仓库 |
| /opensolon/solon-expression | Solon Expression ,代码仓库 |
| /opensolon/solon-flow | Solon Flow ,代码仓库 |
| /opensolon/solon-ai | Solon Ai ,代码仓库 |
| /opensolon/solon-cloud | Solon Cloud ,代码仓库 |
| /opensolon/solon-admin | Solon Admin ,代码仓库 |
| /opensolon/solon-jakarta | Solon Jakarta ,代码仓库(base java21) |
| /opensolon/solon-integration | Solon Integration ,代码仓库 |
| /opensolon/solon-gradle-plugin | Solon Gradle ,插件代码仓库 |
| /opensolon/solon-idea-plugin | Solon Idea ,插件代码仓库 |
| /opensolon/solon-vscode-plugin | Solon VsCode ,插件代码仓库 |
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
WindsurfThe new purpose-built IDE to harness magic
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Serper MCP ServerA Serper MCP Server
Amap Maps高德地图官方 MCP Server