Skip to content

Commit 24ce4f4

Browse files
committed
Java AI Starter项目
0 parents  commit 24ce4f4

File tree

9 files changed

+565
-0
lines changed

9 files changed

+565
-0
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OpenAI Configuration
2+
OPENAI_API_KEY=your_openai_api_key_here
3+
OPENAI_MODEL=gpt-3.5-turbo
4+
5+
# Server Configuration
6+
SERVER_PORT=8080
7+
8+
# Logging
9+
LOG_LEVEL=INFO
10+
11+
# Database (if needed)
12+
# DB_URL=jdbc:postgresql://localhost:5432/ai_db
13+
# DB_USERNAME=postgres
14+
# DB_PASSWORD=password

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Java
2+
target/
3+
*.jar
4+
*.war
5+
*.ear
6+
*.class
7+
8+
# IDE
9+
.idea/
10+
*.iml
11+
.vscode/
12+
.settings/
13+
.classpath
14+
.project
15+
*.launch
16+
bin/
17+
18+
# Environment
19+
.env
20+
*.env.local
21+
22+
# Logs
23+
logs/
24+
*.log
25+
26+
# OS
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Maven
31+
pom.xml.tag
32+
pom.xml.releaseBackup
33+
pom.xml.versionsBackup
34+
pom.xml.next
35+
release.properties
36+
dependency-reduced-pom.xml
37+
buildNumber.properties
38+
.mvn/timing.properties
39+
.mvn/wrapper/maven-wrapper.jar
40+
41+
# Others
42+
*.swp
43+
*.swo
44+
*~

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 IntelliDev AI
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
# Java AI Starter
2+
3+
![Java](https://img.shields.io/badge/Java-ED8B00?style=for-the-badge&logo=java&logoColor=white)
4+
![Spring Boot](https://img.shields.io/badge/Spring_Boot-6DB33F?style=for-the-badge&logo=spring-boot&logoColor=white)
5+
![OpenAI](https://img.shields.io/badge/OpenAI-412991?style=for-the-badge&logo=openai&logoColor=white)
6+
![License](https://img.shields.io/badge/License-MIT-blue.svg)
7+
8+
Spring Boot + OpenAI 快速启动模板,专为Java开发者设计的AI应用基础框架。
9+
10+
## 🎯 项目特点
11+
- **开箱即用**:预配置Spring Boot + OpenAI集成
12+
- **生产就绪**:统一异常处理、日志、配置管理
13+
- **模块化设计**:易于扩展和维护
14+
- **完整文档**:从开发到部署的完整指南
15+
16+
## 🚀 快速开始
17+
18+
### 环境要求
19+
- JDK 11+
20+
- Maven 3.6+
21+
- OpenAI API Key
22+
23+
### 1. 克隆项目
24+
```bash
25+
git clone https://github.com/IntelliDev-AI/java-ai-starter.git
26+
cd java-ai-starter
27+
```
28+
29+
### 2. 配置环境
30+
```bash
31+
# 复制环境配置模板
32+
cp .env.example .env
33+
34+
# 编辑 .env 文件,添加你的配置
35+
# OPENAI_API_KEY=你的API密钥
36+
# OPENAI_MODEL=gpt-3.5-turbo
37+
```
38+
39+
### 3. 运行项目
40+
```bash
41+
# 使用Maven
42+
./mvnw spring-boot:run
43+
44+
# 或打包运行
45+
./mvnw clean package
46+
java -jar target/java-ai-starter-0.0.1.jar
47+
```
48+
49+
### 4. 测试API
50+
```bash
51+
# 测试健康检查
52+
curl http://localhost:8080/health
53+
54+
# 测试AI对话
55+
curl -X POST http://localhost:8080/api/ai/chat \
56+
-H "Content-Type: application/json" \
57+
-d '{"message": "Hello, how are you?"}'
58+
```
59+
60+
## 🏗️ 项目结构
61+
```
62+
java-ai-starter/
63+
├── src/main/java/com/intellidev/
64+
│ ├── config/ # 配置类
65+
│ ├── controller/ # 控制器
66+
│ ├── service/ # 业务逻辑
67+
│ ├── client/ # 外部客户端(OpenAI)
68+
│ ├── model/ # 数据模型
69+
│ └── exception/ # 异常处理
70+
├── src/main/resources/
71+
│ ├── application.yml # 主配置
72+
│ └── templates/ # 模板文件
73+
├── src/test/ # 测试代码
74+
├── docs/ # 项目文档
75+
└── scripts/ # 部署脚本
76+
```
77+
78+
## 📖 核心功能
79+
80+
### 1. OpenAI集成
81+
- 自动配置API客户端
82+
- 支持流式响应
83+
- 错误重试机制
84+
- 请求限流控制
85+
86+
### 2. Web API
87+
- RESTful API设计
88+
- 统一响应格式
89+
- 参数验证
90+
- Swagger文档
91+
92+
### 3. 工具类
93+
- 文本处理工具
94+
- 文件上传处理
95+
- 缓存管理
96+
- 任务调度
97+
98+
### 4. 监控和日志
99+
- 健康检查端点
100+
- 请求日志
101+
- 性能监控
102+
- 错误追踪
103+
104+
## 🔧 配置说明
105+
106+
### 主要配置项
107+
```yaml
108+
# application.yml
109+
openai:
110+
api-key: ${OPENAI_API_KEY}
111+
model: ${OPENAI_MODEL:gpt-3.5-turbo}
112+
timeout: 30000
113+
max-tokens: 1000
114+
115+
server:
116+
port: 8080
117+
118+
spring:
119+
application:
120+
name: java-ai-starter
121+
```
122+
123+
### 环境变量
124+
```bash
125+
# .env.example
126+
OPENAI_API_KEY=你的OpenAI API密钥
127+
OPENAI_MODEL=gpt-3.5-turbo
128+
SERVER_PORT=8080
129+
LOG_LEVEL=INFO
130+
```
131+
132+
## 🧪 测试
133+
134+
### 运行测试
135+
```bash
136+
# 运行所有测试
137+
./mvnw test
138+
139+
# 运行特定测试类
140+
./mvnw test -Dtest=AIServiceTest
141+
142+
# 生成测试报告
143+
./mvnw surefire-report:report
144+
```
145+
146+
### 测试覆盖率
147+
```bash
148+
# 生成覆盖率报告
149+
./mvnw jacoco:report
150+
```
151+
152+
## 📦 部署
153+
154+
### Docker部署
155+
```bash
156+
# 构建镜像
157+
docker build -t intellidev/java-ai-starter .
158+
159+
# 运行容器
160+
docker run -p 8080:8080 \
161+
-e OPENAI_API_KEY=你的密钥 \
162+
intellidev/java-ai-starter
163+
```
164+
165+
### Docker Compose
166+
```yaml
167+
# docker-compose.yml
168+
version: '3.8'
169+
services:
170+
app:
171+
build: .
172+
ports:
173+
- "8080:8080"
174+
environment:
175+
- OPENAI_API_KEY=${OPENAI_API_KEY}
176+
restart: unless-stopped
177+
```
178+
179+
## 🤝 贡献指南
180+
181+
### 开发流程
182+
1. Fork本仓库
183+
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
184+
3. 提交更改 (`git commit -m 'Add amazing feature'`)
185+
4. 推送到分支 (`git push origin feature/amazing-feature`)
186+
5. 创建Pull Request
187+
188+
### 代码规范
189+
- 遵循Google Java代码风格
190+
- 编写单元测试
191+
- 更新相关文档
192+
- 保持向后兼容性
193+
194+
## 📄 许可证
195+
196+
本项目采用 MIT 许可证 - 查看 [LICENSE](LICENSE) 文件了解详情。
197+
198+
## 📞 支持
199+
200+
- 提交Issue:https://github.com/IntelliDev-AI/java-ai-starter/issues
201+
- 文档:查看 [docs](docs/) 目录
202+
- 邮箱:contact@intellidev.ai
203+
204+
## 🌟 致谢
205+
206+
感谢所有为本项目做出贡献的开发者!
207+
208+
---
209+
**IntelliDev AI** - Java + AI 解决方案专家

pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>com.intellidev</groupId>
9+
<artifactId>java-ai-starter</artifactId>
10+
<version>0.0.1</version>
11+
<packaging>jar</packaging>
12+
13+
<name>java-ai-starter</name>
14+
<description>Spring Boot + OpenAI快速启动模板</description>
15+
16+
<parent>
17+
<groupId>org.springframework.boot</groupId>
18+
<artifactId>spring-boot-starter-parent</artifactId>
19+
<version>3.1.5</version>
20+
<relativePath/>
21+
</parent>
22+
23+
<properties>
24+
<java.version>11</java.version>
25+
<maven.compiler.source>11</maven.compiler.source>
26+
<maven.compiler.target>11</maven.compiler.target>
27+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
</properties>
29+
30+
<dependencies>
31+
<!-- Spring Boot Starters -->
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-web</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-validation</artifactId>
39+
</dependency>
40+
41+
<!-- Utilities -->
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<optional>true</optional>
46+
</dependency>
47+
48+
<!-- OpenAI Java SDK -->
49+
<dependency>
50+
<groupId>com.theokanning.openai-gpt3-java</groupId>
51+
<artifactId>service</artifactId>
52+
<version>0.18.2</version>
53+
</dependency>
54+
55+
<!-- Testing -->
56+
<dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-test</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-maven-plugin</artifactId>
68+
<configuration>
69+
<excludes>
70+
<exclude>
71+
<groupId>org.projectlombok</groupId>
72+
<artifactId>lombok</artifactId>
73+
</exclude>
74+
</excludes>
75+
</configuration>
76+
</plugin>
77+
</plugins>
78+
</build>
79+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.intellidev.ai;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class JavaAIStarterApplication {
8+
public static void main(String[] args) {
9+
SpringApplication.run(JavaAIStarterApplication.class, args);
10+
}
11+
}

0 commit comments

Comments
 (0)