MCPInstall
LangChain4j-Springboot logo

LangChain4j-Springboot

by melon1010 34 stars melon1010/LangChain4j-Springboot

Combine LangChain4j with Spring Boot to Build an Intelligent AI Application This project integrates the GitHub API, web scraping, Ollama local AI models, and features the MCP (Model Configuration Protocol) intelligent tool selection functionality.

READMEmaster

LangChain4j与Spring Boot集成示例

这个项目展示了如何将LangChain4j与Spring Boot集成,创建一个功能丰富的AI应用程序,包括多种工具的集成和自动工具选择功能。

功能特点

  • 多种AI工具集成:

    • GitHub工具:查询GitHub仓库信息、提交历史等
    • 网页获取工具:获取网页内容并基于内容回答问题
    • Ollama集成:使用本地Ollama模型进行对话
  • 智能工具选择:

    • 自动分析用户问题,选择最合适的工具
    • 支持混合模式,结合多种工具的优势
  • 用户友好界面:

    • 简洁直观的Web界面
    • 示例问题快速上手
    • 响应式设计,适配各种设备

技术栈

  • 后端:

    • Spring Boot 3.x
    • LangChain4j
    • Ollama集成
    • MCP (Model Context Protocol) 工具
  • 前端:

    • Thymeleaf模板引擎
    • 现代CSS和JavaScript
    • 响应式设计

快速开始

前提条件

  • JDK 17+
  • Maven 3.6+
  • Node.js和npm(用于MCP工具)
  • Ollama(可选,用于本地模型)

环境变量设置

在运行应用前,需要设置以下环境变量:

# GitHub工具所需
export GITHUB_TOKEN=your_github_personal_access_token

# Ollama配置(可选)
export OLLAMA_BASE_URL=http://localhost:11434

安装MCP工具

# 安装uvx工具
npm install -g @modelcontextprotocol/uvx

# 安装GitHub MCP服务器
uvx install @modelcontextprotocol/server-github

# 安装Fetch MCP服务器
uvx install @modelcontextprotocol/server-fetch

构建和运行

# 克隆仓库
git clone https://github.com/melon1010/LangChain4j-Springboot.git
cd LangChain4j-Springboot

# 构建项目
mvn clean package

# 运行应用
java -jar target/langchain4j-springboot-0.0.1-SNAPSHOT.jar

应用将在 http://localhost:8080 启动。

使用指南

主页

访问 http://localhost:8080 进入主页,可以选择不同的工具或直接使用AI智能工具。

GitHub工具

  • 访问 http://localhost:8080/github
  • 输入关于GitHub仓库的问题,如"langchain4j项目最近的三个提交是什么?"
  • 系统将使用GitHub API获取信息并回答问题

网页获取工具

AI智能工具

  • 访问 http://localhost:8080/ai-tools
  • 输入问题,系统将自动选择合适的工具
  • 可以选择性地提供URL以获取特定网页的内容
  • 系统会显示使用了哪种工具来回答问题

配置

主要配置文件位于 src/main/resources/application.yml:

langchain4j:
  ollama:
    chat-model:
      base-url: http://localhost:11434
      model-name: llama3
      timeout: 60s

mcp:
  github:
    token: ${GITHUB_TOKEN}
    timeout: 120
    debug: true
  fetch:
    timeout: 120
    debug: true

故障排除

GitHub工具问题

  • 确保GitHub令牌有效且具有足够的权限
  • 检查网络连接是否正常
  • 启用调试模式获取更详细的日志

网页获取工具问题

  • 确保已正确安装uvx和MCP服务器
  • 检查URL是否可访问
  • 某些网站可能有反爬虫措施,可能无法获取内容

Ollama问题

  • 确保Ollama服务正在运行
  • 检查配置的模型是否已在Ollama中安装
  • 调整超时设置以适应较大的请求

贡献

欢迎贡献代码、报告问题或提出改进建议!请遵循以下步骤:

  1. Fork仓库
  2. 创建特性分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 创建Pull Request

许可证

本项目采用MIT许可证 - 详情请参阅 LICENSE 文件。

致谢

More Developer Tools MCP servers

Similar servers from the same category.

Sourcebot

sourcebot-dev

Enables code search across multiple repository hosts including GitHub, GitLab, Gitea, Gerrit, and Bitbucket with advanced filtering options for exploring large codebases through natural language queries.

searchgit

CodeAlive

codealive-ai

Provides a bridge to CodeAlive's platform for semantic code search, repository exploration, and context-aware chat completions that leverage deep understanding of entire codebases including documentation and dependencies.

search

Provides a secure, sandboxed environment for executing Python, Node.js, and shell commands in ephemeral containers with file management capabilities for code testing, visualization, and data analysis.

filesystemdatabase

NovaCV

lightbaby

Integrates with NovaCV API to generate, analyze, and convert resumes in various formats without dealing with complex document formatting

PDFSupport+5