# 《AI智能客服系统》落地实现-第01节:整体项目结构搭建与说明

作者:冰河
星球:http://m6z.cn/6aeFbs (opens new window)
博客:https://binghe.gitcode.host (opens new window)
文章汇总:https://binghe.gitcode.host/md/all/all.html (opens new window)
源码获取地址:https://t.zsxq.com/0dhvFs5oR (opens new window)

沉淀,成长,突破,帮助他人,成就自我。

  • 本章难度:★☆☆☆☆
  • 本章重点:对AI智能客服系统的整体项目结构进行搭建和说明,从全局角度掌握AI智能客服系统的整体项目结构。重点掌握AI智能客服系统的通用设计思路和设计方法,并能够将其灵活应用到自身实际项目中。

大家好,我是冰河~~

截止到目前,我们已经简单明确了AI智能客服系统的需求和流程,并且对AI智能客服系统的执行流程进行了简单的设计。接下来,我们就可以开始着手设计和开发AI智能客服系统。

# 一、前言

AI智能客服系统总体涵盖后端服务和前端页面两大部分,并且在整体实现上比AI智能问答系统更加完善,功能也更丰富。AI智能客服系统会内置专业的提示词,除了与AI大模型交互外,也会提供健康检查、消息处理、实时监控对话数量、消息数量、每条消息的RT、总RT和平均RT等。同时,提供快捷咨询入口。让大家在学习和跟着专栏一起手敲代码时,能够感受到更加丰富的功能。

# 二、本节诉求

对AI智能客服系统的整体项目结构进行搭建和说明,从全局角度掌握AI智能客服系统的整体项目结构。重点掌握AI智能客服系统的通用设计思路和设计方法,并能够将其灵活应用到自身实际项目中。

# 三、项目搭建

注意:本节只给大家展示AI智能客服系统整体项目搭建的核心步骤,其他代码的实现细节,大家可以自行到本节对应的源码分支进行查看,这里不再赘述。

# 3.1 创建项目

创建一个名为spring-ai-chat-bot的Maven项目,并在pom.xml中按照《开篇:基于DeepSeek大模型的AI智能客服系统正式开撸 (opens new window)》一节中的技术选型添加相关的依赖。pom.xml文件的整体配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>

    <groupId>io.binghe.springai.bot</groupId>
    <artifactId>spring-ai-chat-bot</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-ai.version>1.0.0-M5</spring-ai.version>
        <mybatis.version>3.0.3</mybatis.version>
    </properties>

    <dependencies>
        <!-- Spring Boot Web依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Spring Boot Thymeleaf依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- MyBatis Spring Boot Starter -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.version}</version>
        </dependency>

        <!-- Spring AI OpenAI依赖(支持OpenAI兼容API如DeepSeek) -->
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
            <version>${spring-ai.version}</version>
        </dependency>

        <!-- H2数据库依赖 -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- MySQL驱动依赖 -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- JSON处理依赖 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>

        <!-- WebSocket依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <!-- 参数校验依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>

        <!-- 测试依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                    <encoding>UTF-8</encoding>
                    <compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

# 3.2 设计表结构

为了保持整体项目的简洁性,项目中对于数据库的选型为H2内存数据库,这里,我们AI智能大模型的聊天记录表进行简单的数据,整体表结构设计如下所示。

字段 名称 类型 是否主键 是否可为空
id 数据id BIGINT
user_request 用户发送的消息 TEXT
ai_response AI回复的消息 TEXT
created_time 创建时间 DATETIME
session_id 会话id VARCHAR(100)

创建表SQL语句如下所示。

CREATE TABLE IF NOT EXISTS chat_logs (
   id BIGINT AUTO_INCREMENT PRIMARY KEY,
   user_request TEXT NOT NULL,
   ai_response TEXT NOT NULL,
   created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
   session_id VARCHAR(100) NOT NULL
);
1
2
3
4
5
6
7

# 3.3 创建表结构

# 查看完整文章

加入冰河技术 (opens new window)知识星球,解锁完整技术文章、小册、视频与完整代码