Skip to content

socialzhy/ai-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Chat - 智能挂号助手

一个基于Spring Boot + Vue 3 + LangChain4j + 通义千问大模型的AI智能挂号助手,帮助用户快速、准确地推荐合适的就诊科室。

项目简介

本项目是一个学习LangChain4j使用方法的教学项目,通过实现一个实用的AI挂号助手场景,帮助开发者快速上手LangChain4j的核心功能。

📝 详细教程请参考:LangChain4j使用教程 - AI挂号助手

学习内容

LangChain4j核心功能

  1. AI Service 模式 - 通过接口定义AI交互,自动实现对话逻辑
  2. 流式输出 - 使用StreamingChatModel实现实时响应
  3. 会话记忆 - 基于memoryId管理多轮对话上下文
  4. 工具调用 - 注册和使用自定义工具(如RegistrationsNumTool)
  5. RAG配置 - 检索增强生成配置
  6. 安全防护 - Guardrails实现安全检查
  7. MCP集成 - Model Context Protocol配置

关键代码位置

  • AI Service实现: src/main/java/com/tdsay/aichat/ai/AiChatService.java
  • AI Service工厂: src/main/java/com/tdsay/aichat/ai/AiChatServiceFactory.java

技术栈

Spring Boot Java LangChain4j Vue.js Vite

后端

  • Java 21
  • Spring Boot 4.0.6
  • LangChain4j 1.1.0
  • 阿里云通义千问大模型 (DashScope)
  • Reactor (流式输出)
  • Lombok

前端

  • Vue 3
  • Vite 5
  • Axios

快速开始

前置条件

  • JDK 21+
  • Node.js 18+
  • Maven 3.6+
  • 阿里云通义千问API Key

后端启动

  1. 克隆项目
git clone <repository-url>
cd ai-chat
  1. 配置API Key 修改 src/main/resources/application.yaml 文件,填入你的通义千问API Key:
langchain4j:
  community:
    dashscope:
      chat-model:
        api-key: 你的API Key
      embedding-model:
        api-key: 你的API Key
      streaming-chat-model:
        api-key: 你的API Key
  1. 启动后端服务
mvn spring-boot:run

后端服务将在 http://localhost:8081 启动

前端启动

  1. 进入前端目录
cd ai-chat-web
  1. 安装依赖
npm install
  1. 启动开发服务器
npm run dev

前端服务将在 http://localhost:3000 启动

项目结构

ai-chat/
├── src/main/java/com/tdsay/aichat/
│   ├── AiChatApplication.java          # 主启动类
│   ├── ai/
│   │   ├── AiChat.java                 # AI聊天服务接口
│   │   ├── AiChatService.java          # AI聊天服务实现
│   │   ├── AiChatServiceFactory.java   # 服务工厂
│   │   ├── config/                     # 配置类
│   │   ├── guardrail/                  # 安全防护
│   │   ├── mcp/                        # MCP配置
│   │   ├── rag/                        # RAG配置
│   │   └── tools/                      # 工具类
│   └── res/
│       └── AiChatController.java       # REST控制器
├── src/main/resources/
│   ├── application.yaml                # 应用配置
│   ├── system-prompt.txt               # 系统提示词
│   └── docs/                           # 文档
├── ai-chat-web/                        # 前端项目
│   ├── src/
│   │   ├── api/chat.js                 # API调用
│   │   ├── components/ChatRoom.vue     # 聊天组件
│   │   └── App.vue
│   └── package.json
└── pom.xml                             # Maven配置

API接口

聊天接口

流式聊天

GET /api/ai/chat?memoryId={sessionId}&message={message}

使用SSE (Server-Sent Events) 流式返回AI响应

使用说明

  1. 打开前端页面
  2. 在输入框中输入你的症状或问题
  3. 点击发送,AI助手将实时流式返回建议
  4. 系统会自动生成会话ID,保持对话上下文

注意事项

⚠️ 重要说明:这是一个学习LangChain4j的Demo项目,不是真正的医疗挂号系统,仅供技术学习和研究使用。

  • AI提供的建议仅供分诊参考,不能替代医生的诊断
  • 如遇紧急情况,请立即前往医院急诊
  • 请妥善保管你的API Key,不要提交到公开仓库

许可证

本项目仅供学习和研究使用。

About

本项目是一个学习LangChain4j使用方法的教学项目,通过实现一个实用的AI挂号助手场景,帮助开发者快速上手LangChain4j的核心功能。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors