Skip to content

Commit 7b9cce7

Browse files
authored
feat: Increase the use cases for skills (#419)
1 parent 3a644af commit 7b9cce7

15 files changed

Lines changed: 1549 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@
7777
<module>spring-ai-alibaba-nl2sql-example</module>
7878
<module>spring-ai-alibaba-graph-example</module>
7979
<module>spring-ai-alibaba-bailian-example</module>
80-
<module>spring-ai-alibaba-evaluation-example</module>
81-
<!-- <module>spring-ai-alibaba-agent-example/a2a-example</module>-->
80+
<module>spring-ai-alibaba-evaluation-example</module>
8281
<!-- For mem0, this is on saa snapshot version, if use, please install saa in local -->
8382
<!-- <module>spring-ai-alibaba-mem0-example</module> -->
8483
</modules>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
HELP.md
2+
target/
3+
.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**/target/
5+
!**/src/test/**/target/
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
!**/src/main/**/build/
30+
!**/src/test/**/build/
31+
32+
### VS Code ###
33+
.vscode/
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# Skills Agent Web 应用
2+
3+
基于 Spring AI Alibaba 的 Web 版 AI Agent,支持浏览器访问和 REST API 调用。
4+
5+
## 特点
6+
7+
- ✅ Web 界面,支持浏览器访问
8+
- ✅ REST API,支持程序调用
9+
- ✅ 会话管理,支持多用户
10+
- ✅ 完美支持中文
11+
- ✅ 集成 Skills 系统
12+
- ✅ 实时对话
13+
14+
## 快速开始
15+
16+
### 1. 设置 API Key(可选)
17+
18+
```bash
19+
set DASHSCOPE_API_KEY=your_api_key_here
20+
```
21+
22+
如果不设置,会使用 application.yml 中的默认配置。
23+
24+
### 2. 启动应用
25+
26+
```bash
27+
mvn spring-boot:run
28+
```
29+
30+
或者先构建再运行:
31+
32+
```bash
33+
mvn clean package -DskipTests
34+
java -jar target/skills-agent-example-0.0.1-SNAPSHOT.jar
35+
```
36+
37+
### 3. 访问应用
38+
39+
打开浏览器访问:
40+
41+
```
42+
http://localhost:8080
43+
```
44+
45+
## API 文档
46+
47+
### 1. 发送消息
48+
49+
**POST** `/api/chat/message`
50+
51+
请求体:
52+
```json
53+
{
54+
"message": "你好,介绍一下你自己",
55+
"sessionId": "user123"
56+
}
57+
```
58+
59+
响应:
60+
```json
61+
{
62+
"success": true,
63+
"reply": "你好!我是一个 AI 助手...",
64+
"sessionId": "user123"
65+
}
66+
```
67+
68+
### 2. 重置会话
69+
70+
**POST** `/api/chat/reset`
71+
72+
请求体:
73+
```json
74+
{
75+
"sessionId": "user123"
76+
}
77+
```
78+
79+
响应:
80+
```json
81+
{
82+
"success": true,
83+
"message": "会话已重置",
84+
"sessionId": "user123"
85+
}
86+
```
87+
88+
### 3. 查看会话列表
89+
90+
**GET** `/api/chat/sessions`
91+
92+
响应:
93+
```json
94+
{
95+
"success": true,
96+
"sessionCount": 2,
97+
"sessions": ["user123", "user456"]
98+
}
99+
```
100+
101+
### 4. 健康检查
102+
103+
**GET** `/api/chat/health`
104+
105+
响应:
106+
```json
107+
{
108+
"status": "ok",
109+
"service": "Skills Agent API"
110+
}
111+
```
112+
113+
## 使用示例
114+
115+
### cURL 调用
116+
117+
```bash
118+
# 发送消息
119+
curl -X POST http://localhost:8080/api/chat/message \
120+
-H "Content-Type: application/json" \
121+
-d "{\"message\":\"你好\",\"sessionId\":\"test\"}"
122+
123+
# 重置会话
124+
curl -X POST http://localhost:8080/api/chat/reset \
125+
-H "Content-Type: application/json" \
126+
-d "{\"sessionId\":\"test\"}"
127+
```
128+
129+
### Python 调用
130+
131+
```python
132+
import requests
133+
134+
# 发送消息
135+
response = requests.post('http://localhost:8080/api/chat/message', json={
136+
'message': '帮我搜索关于机器学习的论文',
137+
'sessionId': 'python-client'
138+
})
139+
print(response.json()['reply'])
140+
141+
# 重置会话
142+
requests.post('http://localhost:8080/api/chat/reset', json={
143+
'sessionId': 'python-client'
144+
})
145+
```
146+
147+
### JavaScript 调用
148+
149+
```javascript
150+
// 发送消息
151+
const response = await fetch('http://localhost:8080/api/chat/message', {
152+
method: 'POST',
153+
headers: { 'Content-Type': 'application/json' },
154+
body: JSON.stringify({
155+
message: '你好',
156+
sessionId: 'js-client'
157+
})
158+
});
159+
const data = await response.json();
160+
console.log(data.reply);
161+
```
162+
163+
## 配置
164+
165+
### 修改端口
166+
167+
编辑 `src/main/resources/application.yml`
168+
169+
```yaml
170+
server:
171+
port: 9090 # 改成你想要的端口
172+
```
173+
174+
### 修改模型
175+
176+
```yaml
177+
spring:
178+
ai:
179+
dashscope:
180+
chat:
181+
options:
182+
model: qwen-max # 可选: qwen-plus, qwen-turbo, qwen-max
183+
```
184+
185+
### 跨域配置
186+
187+
如果需要从其他域名访问,Controller 已经配置了 `@CrossOrigin(origins = "*")`。
188+
189+
生产环境建议修改为具体域名:
190+
191+
```java
192+
@CrossOrigin(origins = "https://yourdomain.com")
193+
```
194+
195+
## Skills 功能
196+
197+
应用已集成以下 Skills:
198+
199+
1. **arxiv-search** - 搜索 arXiv 论文库
200+
2. **skill-creator** - 创建新的 skill
201+
3. **web-research** - 进行网络研究
202+
203+
Agent 会根据用户问题自动调用相应的 Skill。
204+
205+
## 部署
206+
207+
### Docker 部署
208+
209+
创建 `Dockerfile`:
210+
211+
```dockerfile
212+
FROM openjdk:17-slim
213+
COPY target/skills-agent-example-0.0.1-SNAPSHOT.jar app.jar
214+
EXPOSE 8080
215+
ENTRYPOINT ["java", "-jar", "/app.jar"]
216+
```
217+
218+
构建并运行:
219+
220+
```bash
221+
docker build -t skills-agent .
222+
docker run -p 8080:8080 -e DASHSCOPE_API_KEY=your_key skills-agent
223+
```
224+
225+
### 云服务器部署
226+
227+
```bash
228+
# 构建
229+
mvn clean package -DskipTests
230+
231+
# 上传 jar 到服务器
232+
scp target/skills-agent-example-0.0.1-SNAPSHOT.jar user@server:/app/
233+
234+
# 在服务器上运行
235+
nohup java -jar /app/skills-agent-example-0.0.1-SNAPSHOT.jar > /app/logs/app.log 2>&1 &
236+
```
237+
238+
## 故障排查
239+
240+
### 端口被占用
241+
242+
修改 `application.yml` 中的端口号,或者使用命令行参数:
243+
244+
```bash
245+
java -jar target/skills-agent-example-0.0.1-SNAPSHOT.jar --server.port=9090
246+
```
247+
248+
### API 调用失败
249+
250+
1. 检查 API Key 是否正确
251+
2. 检查网络连接
252+
3. 查看日志:`tail -f logs/spring.log`
253+
254+
### 会话过多导致内存问题
255+
256+
可以添加会话清理机制,或者使用 Redis 存储会话。
257+
258+
## 性能优化
259+
260+
1. **启用缓存** - 缓存常见问题的回答
261+
2. **异步处理** - 使用 `@Async` 处理长时间请求
262+
3. **连接池** - 配置 HTTP 客户端连接池
263+
4. **限流** - 添加 API 限流保护
264+
265+
## 安全建议
266+
267+
1. 添加认证机制(JWT、OAuth2)
268+
2. 限制请求频率
269+
3. 验证输入内容
270+
4. 使用 HTTPS
271+
5. 不要在前端暴露 API Key
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.5.9</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.cloud.alibaba.ai.example.skills</groupId>
12+
<artifactId>skills-agent-example</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>skills-agent-example</name>
15+
<description>skills-agent-example</description>
16+
<url/>
17+
<licenses>
18+
<license/>
19+
</licenses>
20+
<developers>
21+
<developer/>
22+
</developers>
23+
<scm>
24+
<connection/>
25+
<developerConnection/>
26+
<tag/>
27+
<url/>
28+
</scm>
29+
<properties>
30+
<java.version>17</java.version>
31+
</properties>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-test</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>com.alibaba.cloud.ai</groupId>
46+
<artifactId>spring-ai-alibaba-agent-framework</artifactId>
47+
<version>1.1.2.0-SNAPSHOT</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>com.alibaba.cloud.ai</groupId>
52+
<artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
53+
<version>1.1.2.0</version>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<groupId>org.springframework.boot</groupId>
61+
<artifactId>spring-boot-maven-plugin</artifactId>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>

0 commit comments

Comments
 (0)