MCP ExplorerExplorer

Langchain4j Springboot

@melon1010on 9 months ago
12 MIT
FreeCommunity
AI Systems
# 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.

Overview

What is Langchain4j Springboot

LangChain4j-Springboot is a project that integrates LangChain4j with Spring Boot to build an intelligent AI application. It combines various tools such as GitHub API, web scraping, and local Ollama AI models, featuring an intelligent tool selection capability.

Use cases

Use cases include querying recent commits from GitHub repositories, extracting and answering questions based on web content, and utilizing AI tools to provide intelligent responses based on user input.

How to use

To use LangChain4j-Springboot, clone the repository, set up the required environment variables, install the necessary MCP tools, build the project using Maven, and run the application. Access the application via http://localhost:8080 to interact with different AI tools.

Key features

Key features include integration of multiple AI tools (GitHub API, web scraping, local Ollama model), intelligent tool selection that analyzes user queries to choose the best tool, and a user-friendly web interface that is responsive and easy to navigate.

Where to use

LangChain4j-Springboot can be used in various fields such as software development for querying GitHub repositories, educational purposes for answering questions based on web content, and in AI research for experimenting with local AI models.

Content

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 文件。

致谢

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers