mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
Compare commits
102 Commits
fa8f1f2091
...
v7-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10d660fb06 | ||
|
|
831fed4bb3 | ||
|
|
4d0074e6a6 | ||
|
|
707daa94f7 | ||
|
|
60b80340fc | ||
|
|
0255f8a365 | ||
|
|
f20536ea12 | ||
|
|
cc0b4b10c7 | ||
|
|
0d0c7622b6 | ||
|
|
e89cb0bdea | ||
|
|
bf3376f464 | ||
|
|
a621066525 | ||
|
|
8bb82a9d92 | ||
|
|
27f77f83a7 | ||
|
|
04bb0183e5 | ||
|
|
98a03945f7 | ||
|
|
be20536ba1 | ||
|
|
a4a02bdbd6 | ||
|
|
7391526b74 | ||
|
|
0978d2ce1b | ||
|
|
55794a1725 | ||
|
|
8f94b5ba2e | ||
|
|
d2ed2124b6 | ||
|
|
2d8fe7b468 | ||
|
|
b532ca01c5 | ||
|
|
8ad16be6cb | ||
|
|
e6e32a76b9 | ||
|
|
db7c7f2e34 | ||
|
|
90e8d3bdac | ||
|
|
91b8a50b68 | ||
|
|
50dc76ee76 | ||
|
|
fdc7d4fb3c | ||
|
|
c17c5bb013 | ||
|
|
9cc095463e | ||
|
|
c424d76f88 | ||
|
|
2b7adbef08 | ||
|
|
6fda8f0244 | ||
|
|
bb607e30ae | ||
|
|
9d83869d85 | ||
|
|
a7c5259d4b | ||
|
|
5034b04a14 | ||
|
|
6d94eb6ae6 | ||
|
|
a7663b93f7 | ||
|
|
52afcdd388 | ||
|
|
e7546e6c34 | ||
|
|
ac5abab4ea | ||
|
|
e0275c56ac | ||
|
|
9d9d326aa8 | ||
|
|
73635fd1b2 | ||
|
|
caf0ca658e | ||
|
|
fbf1b6cd1f | ||
|
|
0655b26b73 | ||
|
|
3e56130847 | ||
|
|
68bcc8f5de | ||
|
|
698443860f | ||
|
|
d296b94a9b | ||
|
|
39f51ee899 | ||
|
|
aaa6932ae1 | ||
|
|
5a3acc6b80 | ||
|
|
580c34bbfa | ||
|
|
28d1a8cdff | ||
|
|
8b7d621cd7 | ||
|
|
7c2746c76a | ||
|
|
b68e180ad5 | ||
|
|
4942367ab4 | ||
|
|
9f4a7b7d9e | ||
|
|
d960f5b353 | ||
|
|
faf9897097 | ||
|
|
3d3cadd1bc | ||
|
|
596cdc2984 | ||
|
|
a51da7369d | ||
|
|
5f61312587 | ||
|
|
0073597ae6 | ||
|
|
a0ca35101e | ||
|
|
c7ba1a5a3c | ||
|
|
11fc243705 | ||
|
|
255ff52071 | ||
|
|
50d9182b97 | ||
|
|
1a102f9359 | ||
|
|
51b9bfd8bb | ||
|
|
f8bf24aa0c | ||
|
|
05dfc221a5 | ||
|
|
8b3e6c99c4 | ||
|
|
80eccf98bb | ||
|
|
6d493b2fc9 | ||
|
|
eb68f61a18 | ||
|
|
9cbeea018d | ||
|
|
74738b67ca | ||
|
|
c8199504fc | ||
|
|
861b961b6f | ||
|
|
49093afcd4 | ||
|
|
2a90c4b7b5 | ||
|
|
bedfa07a8a | ||
|
|
07739d72db | ||
|
|
45419bb8dc | ||
|
|
570f846d4d | ||
|
|
1b54272ea8 | ||
|
|
869b82b8d0 | ||
|
|
33aa3ecf3a | ||
|
|
d58d5ea032 | ||
|
|
038a6ca0c8 | ||
|
|
22d487624d |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
# These are supported funding model platforms
|
# These are supported funding model platforms
|
||||||
|
|
||||||
github: [Looly]
|
github: [Looly]
|
||||||
custom: ['https://gitee.com/dromara/hutool', 'https://dromara.gitee.io/donate.html']
|
custom: ['https://gitee.com/chinabugotech/hutool']
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 6.0.0-M22 (2025-05-07)
|
# 7.0.0-M1 (2025-05-07)
|
||||||
|
|
||||||
### ❌不兼容特性
|
### ❌不兼容特性
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【http】 修复`HttpClient5Response`无响应体导致的空指针问题(issue#3930@Github)
|
||||||
38
README-EN.md
Executable file → Normal file
38
README-EN.md
Executable file → Normal file
@@ -33,11 +33,11 @@
|
|||||||
<a target="_blank" href='https://gitee.com/dromara/hutool/stargazers'>
|
<a target="_blank" href='https://gitee.com/dromara/hutool/stargazers'>
|
||||||
<img src='https://gitee.com/dromara/hutool/badge/star.svg?theme=gvp' alt='star'/>
|
<img src='https://gitee.com/dromara/hutool/badge/star.svg?theme=gvp' alt='star'/>
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href='https://github.com/dromara/hutool'>
|
<a target="_blank" href='https://github.com/chinabugotech/hutool'>
|
||||||
<img src="https://img.shields.io/github/stars/dromara/hutool.svg?style=social" alt="github star"/>
|
<img src="https://img.shields.io/github/stars/chinabugotech/hutool.svg?style=social" alt="github star"/>
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href='https://gitcode.com/dromara/hutool'>
|
<a target="_blank" href='https://gitcode.com/chinabugotech/hutool'>
|
||||||
<img src="https://gitcode.com/dromara/hutool/star/badge.svg" alt="gitcode star"/>
|
<img src="https://gitcode.com/chinabugotech/hutool/star/badge.svg" alt="gitcode star"/>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -126,32 +126,32 @@ Each module can be introduced individually, or all modules can be introduced by
|
|||||||
### 🍊Maven
|
### 🍊Maven
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🍐Gradle
|
### 🍐Gradle
|
||||||
```
|
```
|
||||||
implementation 'org.dromara.hutool:hutool-all:6.0.0-M23'
|
implementation 'cn.hutool.v7:hutool-all:7.0.0-M2'
|
||||||
```
|
```
|
||||||
|
|
||||||
## 📥Download
|
## 📥Download
|
||||||
|
|
||||||
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/6.0.0-M23/)
|
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/v7/hutool-all/7.0.0-M2/)
|
||||||
|
|
||||||
> 🔔️note:
|
> 🔔️note:
|
||||||
> Hutool 5.x supports JDK8+ and is not tested on Android platforms, and cannot guarantee that all tool classes or tool methods are available.
|
> Hutool 7.x supports JDK17 and is not tested on Android platforms, and cannot guarantee that all tool classes or tool methods are available.
|
||||||
> If your project uses JDK7, please use Hutool 4.x version.
|
> If your project uses JDK7, please use Hutool 4.x version.
|
||||||
|
|
||||||
### 🚽Compile and install
|
### 🚽Compile and install
|
||||||
|
|
||||||
Download the entire project source code
|
Download the entire project source code
|
||||||
|
|
||||||
gitee:[https://gitee.com/dromara/hutool](https://gitee.com/dromara/hutool)
|
gitee:[https://gitee.com/chinabugotech/hutool](https://gitee.com/chinabugotech/hutool)
|
||||||
|
|
||||||
github:[https://github.com/dromara/hutool](https://github.com/dromara/hutool)
|
github:[https://github.com/chinabugotech/hutool](https://github.com/chinabugotech/hutool)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd ${hutool}
|
cd ${hutool}
|
||||||
@@ -168,16 +168,16 @@ Hutool's source code is divided into two branches:
|
|||||||
|
|
||||||
| branch | description |
|
| branch | description |
|
||||||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| v6-master | The master branch, the branch used by the release version, is the same as the jar committed to the central repository and does not receive any pr or modifications. |
|
| v7-master | The master branch, the branch used by the release version, is the same as the jar committed to the central repository and does not receive any pr or modifications. |
|
||||||
| v6-dev | Development branch, which defaults to the next SNAPSHOT version, accepts modifications or pr |
|
| v7-dev | Development branch, which defaults to the next SNAPSHOT version, accepts modifications or pr |
|
||||||
|
|
||||||
### 🐞Provide feedback or suggestions on bugs
|
### 🐞Provide feedback or suggestions on bugs
|
||||||
|
|
||||||
When submitting feedback, please indicate which JDK version, Hutool version, and related dependency library version you are using.
|
When submitting feedback, please indicate which JDK version, Hutool version, and related dependency library version you are using.
|
||||||
|
|
||||||
- [Gitee issue](https://gitee.com/dromara/hutool/issues)
|
- [Gitee issue](https://gitee.com/chinabugotech/hutool/issues)
|
||||||
- [Github issue](https://github.com/dromara/hutool/issues)
|
- [Github issue](https://github.com/chinabugotech/hutool/issues)
|
||||||
- [Gitcode issue](https://gitcode.com/dromara/hutool/issues)
|
- [Gitcode issue](https://gitcode.com/chinabugotech/hutool/issues)
|
||||||
|
|
||||||
### 🧬Principles of PR(pull request)
|
### 🧬Principles of PR(pull request)
|
||||||
|
|
||||||
@@ -186,13 +186,13 @@ Hutool welcomes anyone to contribute code to Hutool, but the author suffers from
|
|||||||
1. Improve the comments, especially each new method should follow the Java documentation specification to indicate the method description, parameter description, return value description and other information, if necessary, please add unit tests, if you want, you can also add your name.
|
1. Improve the comments, especially each new method should follow the Java documentation specification to indicate the method description, parameter description, return value description and other information, if necessary, please add unit tests, if you want, you can also add your name.
|
||||||
2. Code indentation according to Eclipse.
|
2. Code indentation according to Eclipse.
|
||||||
3. Newly added methods do not use third-party library methods,Unless the method tool is add to the '**extra module**'.
|
3. Newly added methods do not use third-party library methods,Unless the method tool is add to the '**extra module**'.
|
||||||
4. Please pull request to the `v6-dev` branch. Hutool uses a new branch after 5.x: `v6-master` is the master branch, which indicates the version of the central library that has been released, and this branch does not allow pr or modifications.
|
4. Please pull request to the `v7-dev` branch. Hutool uses a new branch after 7.x: `v7-master` is the master branch, which indicates the version of the central library that has been released, and this branch does not allow pr or modifications.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
## ⭐Star Hutool
|
## ⭐Star Hutool
|
||||||
|
|
||||||
[](https://starchart.cc/dromara/hutool)
|
[](https://starchart.cc/chinabugotech/hutool)
|
||||||
|
|
||||||
## 📌WeChat Official Account
|
## 📌WeChat Official Account
|
||||||
|
|
||||||
|
|||||||
61
README.md
Executable file → Normal file
61
README.md
Executable file → Normal file
@@ -9,8 +9,8 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a target="_blank" href="https://search.maven.org/artifact/org.dromara.hutool/hutool-all">
|
<a target="_blank" href="https://search.maven.org/artifact/cn.hutool/hutool-all">
|
||||||
<img alt="" src="https://img.shields.io/maven-central/v/org.dromara.hutool/hutool-all.svg?label=Maven%20Central" />
|
<img alt="" src="https://img.shields.io/maven-central/v/cn.hutool/hutool-all.svg?label=Maven%20Central" />
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.html">
|
<a target="_blank" href="https://www.apache.org/licenses/LICENSE-2.0.html">
|
||||||
<img alt="" src="https://img.shields.io/:license-apache2.0-blue.svg?logo=apache" />
|
<img alt="" src="https://img.shields.io/:license-apache2.0-blue.svg?logo=apache" />
|
||||||
@@ -18,26 +18,26 @@
|
|||||||
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html">
|
<a target="_blank" href="https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html">
|
||||||
<img alt="" src="https://img.shields.io/badge/JDK-8+-green.svg" />
|
<img alt="" src="https://img.shields.io/badge/JDK-8+-green.svg" />
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href="https://travis-ci.com/dromara/hutool">
|
<a target="_blank" href="https://travis-ci.com/chinabugotech/hutool">
|
||||||
<img alt="" src="https://travis-ci.com/dromara/hutool.svg?branch=v5-master" />
|
<img alt="" src="https://travis-ci.com/chinabugotech/hutool.svg?branch=v5-master" />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://www.codacy.com/gh/dromara/hutool/dashboard?utm_source=github.com&utm_medium=referral&utm_content=dromara/hutool&utm_campaign=Badge_Grade">
|
<a href="https://www.codacy.com/gh/chinabugotech/hutool/dashboard?utm_source=github.com&utm_medium=referral&utm_content=chinabugotech/hutool&utm_campaign=Badge_Grade">
|
||||||
<img alt="" src="https://app.codacy.com/project/badge/Grade/8a6897d9de7440dd9de8804c28d2871d"/>
|
<img alt="" src="https://app.codacy.com/project/badge/Grade/8a6897d9de7440dd9de8804c28d2871d"/>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://codecov.io/gh/dromara/hutool">
|
<a href="https://codecov.io/gh/cn/hutool">
|
||||||
<img alt="" src="https://codecov.io/gh/dromara/hutool/branch/v6-master/graph/badge.svg" />
|
<img alt="" src="https://codecov.io/gh/chinabugotech/hutool/branch/v7-master/graph/badge.svg" />
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href="https://gitter.im/hutool/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge">
|
<a target="_blank" href="https://gitter.im/hutool/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge">
|
||||||
<img alt="" src="https://badges.gitter.im/hutool/Lobby.svg" />
|
<img alt="" src="https://badges.gitter.im/hutool/Lobby.svg" />
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href='https://gitee.com/dromara/hutool/stargazers'>
|
<a target="_blank" href='https://gitee.com/chinabugotech/hutool/stargazers'>
|
||||||
<img alt="star" src='https://gitee.com/dromara/hutool/badge/star.svg?theme=gvp'/>
|
<img alt="star" src='https://gitee.com/chinabugotech/hutool/badge/star.svg'/>
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href='https://github.com/dromara/hutool'>
|
<a target="_blank" href='https://github.com/chinabugotech/hutool'>
|
||||||
<img alt="github star" src="https://img.shields.io/github/stars/dromara/hutool.svg?style=social"/>
|
<img alt="github star" src="https://img.shields.io/github/stars/chinabugotech/hutool.svg?style=social"/>
|
||||||
</a>
|
</a>
|
||||||
<a target="_blank" href='https://gitcode.com/dromara/hutool'>
|
<a target="_blank" href='https://gitcode.com/chinabugotech/hutool'>
|
||||||
<img src="https://gitcode.com/dromara/hutool/star/badge.svg" alt="gitcode star"/>
|
<img src="https://gitcode.com/chinabugotech/hutool/star/badge.svg" alt="gitcode star"/>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -77,13 +77,14 @@
|
|||||||
|
|
||||||
### ✨版本选择
|
### ✨版本选择
|
||||||
|
|
||||||
Hutool目前主要版本4.x、5.x、6.x,选择如下:
|
Hutool目前主要版本4.x、5.x、6.x、7.x,选择如下:
|
||||||
|
|
||||||
| 版本 | jdk| Maven仓库 | 主要特点 |
|
| 版本 | jdk | Maven仓库 | 主要特点 |
|
||||||
|-----|----|--------------------------------------------------------------------------------------------------------|-------------------------------------|
|
|-----|--------|--------------------------------------------------------------------------------------------------------|-------------------------------------|
|
||||||
| 4.x | jdk1.7 | [cn.hutool/hutool-all/4.x](https://mvnrepository.com/artifact/cn.hutool/hutool-all/4.6.17) | jdk1.7编译 |
|
| 4.x | jdk1.7 | [cn.hutool/hutool-all/4.x](https://mvnrepository.com/artifact/cn.hutool/hutool-all/4.6.17) | jdk1.7编译 |
|
||||||
| 5.x | jdk1.8 | [cn.hutool/hutool-all/5.x ](https://mvnrepository.com/artifact/cn.hutool/hutool-all) | jdk1.8编译,使用JavaEE,适配JDK11、17、21 |
|
| 5.x | jdk1.8 | [cn.hutool/hutool-all/5.x ](https://mvnrepository.com/artifact/cn.hutool/hutool-all) | jdk1.8编译,使用JavaEE,适配JDK11、17、21 |
|
||||||
| 6.x | jdk1.8 | [org.dromara.hutool/hutool-all/6.x ](https://mvnrepository.com/artifact/org.dromara.hutool/hutool-all) | jdk1.8编译,使用Jakarta EE,适配JDK11、17、21 |
|
| 6.x | jdk1.8 | [org.dromara.hutool/hutool-all/6.x ](https://mvnrepository.com/artifact/org.dromara.hutool/hutool-all) | jdk1.8编译,使用Jakarta EE,适配JDK11、17、21 |
|
||||||
|
| 7.x | jdk17 | [cn.hutool.v7/hutool-all/7.x ](https://mvnrepository.com/artifact/cn.hutool.v7/hutool-all) | jdk17编译,使用Jakarta EE,适配17+ |
|
||||||
|
|
||||||
## 🛠️包含组件
|
## 🛠️包含组件
|
||||||
|
|
||||||
@@ -128,30 +129,30 @@ Hutool目前主要版本4.x、5.x、6.x,选择如下:
|
|||||||
```xml
|
```xml
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
### 🍐Gradle
|
### 🍐Gradle
|
||||||
|
|
||||||
```
|
```
|
||||||
implementation 'org.dromara.hutool:hutool-all:6.0.0-M23'
|
implementation 'cn.hutool.v7:hutool-all:7.0.0-M2'
|
||||||
```
|
```
|
||||||
|
|
||||||
### 📥下载jar
|
### 📥下载jar
|
||||||
|
|
||||||
点击以下链接,下载`hutool-all-X.X.X.jar`即可:
|
点击以下链接,下载`hutool-all-X.X.X.jar`即可:
|
||||||
|
|
||||||
- [Maven中央库](https://repo1.maven.org/maven2/org/dromara/hutool/hutool-all/6.0.0-M23/)
|
- [Maven中央库](https://repo1.maven.org/maven2/cn/hutool/v7/hutool-all/7.0.0-M2/)
|
||||||
|
|
||||||
> 🔔️注意
|
> 🔔️注意
|
||||||
> Hutool 6.x支持JDK8+,对Android平台没有测试,不能保证所有工具类或工具方法可用。
|
> Hutool 7.x支持JDK17,对Android平台没有测试,不能保证所有工具类或工具方法可用。
|
||||||
|
|
||||||
### 🚽编译安装
|
### 🚽编译安装
|
||||||
|
|
||||||
访问Hutool的Gitee主页:[https://gitee.com/dromara/hutool](https://gitee.com/dromara/hutool)
|
访问Hutool的Gitee主页:[https://gitee.com/chinabugotech/hutool](https://gitee.com/chinabugotech/hutool)
|
||||||
下载整个项目源码(v6-master或v6-dev分支都可)然后进入Hutool项目目录执行:
|
下载整个项目源码(v6-master或v6-dev分支都可)然后进入Hutool项目目录执行:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -170,23 +171,23 @@ Hutool的源码分为两个分支,功能如下:
|
|||||||
|
|
||||||
| 分支 | 作用 |
|
| 分支 | 作用 |
|
||||||
|-----------|--------------------------------------------|
|
|-----------|--------------------------------------------|
|
||||||
| v6-master | 主分支,release版本使用的分支,与中央库提交的jar一致,不接收任何pr或修改 |
|
| v7-master | 主分支,release版本使用的分支,与中央库提交的jar一致,不接收任何pr或修改 |
|
||||||
| v6-dev | 开发分支,默认为下个版本的SNAPSHOT版本,接受修改或pr |
|
| v7-dev | 开发分支,默认为下个版本的SNAPSHOT版本,接受修改或pr |
|
||||||
|
|
||||||
### 🐞提供bug反馈或建议
|
### 🐞提供bug反馈或建议
|
||||||
|
|
||||||
提交问题反馈请说明正在使用的JDK版本呢、Hutool版本和相关依赖库版本。
|
提交问题反馈请说明正在使用的JDK版本呢、Hutool版本和相关依赖库版本。
|
||||||
|
|
||||||
- [Gitee issue](https://gitee.com/dromara/hutool/issues)
|
- [Gitee issue](https://gitee.com/chinabugotech/hutool/issues)
|
||||||
- [Github issue](https://github.com/dromara/hutool/issues)
|
- [Github issue](https://github.com/chinabugotech/hutool/issues)
|
||||||
- [Gitcode issue Gitcode问题](https://gitcode.com/dromara/hutool/issues)
|
- [Gitcode issue Gitcode问题](https://gitcode.com/chinabugotech/hutool/issues)
|
||||||
|
|
||||||
### 🧬贡献代码的步骤
|
### 🧬贡献代码的步骤
|
||||||
|
|
||||||
1. 在Gitee、Github或Gitcode上fork项目到自己的repo
|
1. 在Gitee、Github或Gitcode上fork项目到自己的repo
|
||||||
2. 把fork过去的项目也就是你的项目clone到你的本地
|
2. 把fork过去的项目也就是你的项目clone到你的本地
|
||||||
3. 修改代码(记得一定要修改v6-dev分支)
|
3. 修改代码(记得一定要修改v7-dev分支)
|
||||||
4. commit后push到自己的库(v6-dev分支)
|
4. commit后push到自己的库(v7-dev分支)
|
||||||
5. 登录Gitee、Github或Gitcode在你首页可以看到一个 pull request 按钮,点击它,填写一些说明信息,然后提交即可。
|
5. 登录Gitee、Github或Gitcode在你首页可以看到一个 pull request 按钮,点击它,填写一些说明信息,然后提交即可。
|
||||||
6. 等待维护者合并
|
6. 等待维护者合并
|
||||||
|
|
||||||
@@ -209,7 +210,7 @@ Hutool欢迎任何人为Hutool添砖加瓦,贡献代码,不过维护者是
|
|||||||
|
|
||||||
## ⭐Star Hutool
|
## ⭐Star Hutool
|
||||||
|
|
||||||
[](https://starchart.cc/dromara/hutool)[](https://starchart.cc/dromara/hutool)
|
[](https://starchart.cc/chinabugotech/hutool)
|
||||||
|
|
||||||
### GitHub Contributor Over Time
|
### GitHub Contributor Over Time
|
||||||
[](https://git-contributor.com?chart=contributorOverTime&repo=dromara/hutool)
|
[](https://git-contributor.com?chart=contributorOverTime&repo=dromara/hutool)
|
||||||
|
|||||||
13
SECURITY.md
13
SECURITY.md
@@ -1,13 +0,0 @@
|
|||||||
# Security Policy
|
|
||||||
|
|
||||||
## Supported Versions(支持的版本)
|
|
||||||
|
|
||||||
| Version | Supported |
|
|
||||||
|---------|--------------------|
|
|
||||||
| 6.x.x | :white_check_mark: |
|
|
||||||
|
|
||||||
## Reporting a Vulnerability(报告漏洞)
|
|
||||||
|
|
||||||
如果你发现有安全问题或漏洞,请发送邮件到`loolly@aliyun.com`。
|
|
||||||
|
|
||||||
To report any found security issues or vulnerabilities, please send a mail to `loolly@aliyun.com`.
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013-2025 Hutool Team and hutool.cn
|
# Copyright (c) 2013-2025 Hutool Team and hutool.cn
|
||||||
#
|
#
|
||||||
@@ -14,5 +16,5 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
org.dromara.hutool.extra.aop.engine.spring.SpringCglibProxyEngine
|
export JAVA_HOME="/cygdrive/d/java/jdk-17.0.15"
|
||||||
org.dromara.hutool.extra.aop.engine.jdk.JdkProxyEngine
|
export PATH="$JAVA_HOME/bin:$PATH"
|
||||||
@@ -16,12 +16,12 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
echo -e "\033[32mCheckout to v6-dev\033[0m"
|
echo -e "\033[32mCheckout to v7-dev\033[0m"
|
||||||
git checkout v6-dev
|
git checkout v7-dev
|
||||||
|
|
||||||
echo -e "\033[32mPush to Github(origin) v6-dev\033[0m"
|
echo -e "\033[32mPush to Github(origin) v7-dev\033[0m"
|
||||||
git push origin v6-dev
|
git push origin v7-dev
|
||||||
echo -e "\033[32mPush to Gitee v6-dev\033[0m"
|
echo -e "\033[32mPush to Gitee v7-dev\033[0m"
|
||||||
git push osc v6-dev
|
git push osc v7-dev
|
||||||
echo -e "\033[32mPush to Gitcode v6-dev\033[0m"
|
echo -e "\033[32mPush to Gitcode v7-dev\033[0m"
|
||||||
git push gitcode v6-dev
|
git push gitcode v7-dev
|
||||||
|
|||||||
@@ -19,15 +19,15 @@
|
|||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
||||||
|
|
||||||
echo -e "\033[32mCheckout to v6-master\033[0m"
|
echo -e "\033[32mCheckout to v7-master\033[0m"
|
||||||
git checkout v6-master
|
git checkout v7-master
|
||||||
|
|
||||||
echo -e "\033[32mMerge v6-dev branch\033[0m"
|
echo -e "\033[32mMerge v7-dev branch\033[0m"
|
||||||
git merge v6-dev -m 'Prepare release'
|
git merge v7-dev -m 'Prepare release'
|
||||||
|
|
||||||
echo -e "\033[32mPush to Github(origin) v6-master\033[0m"
|
echo -e "\033[32mPush to Github(origin) v7-master\033[0m"
|
||||||
git push origin v6-master
|
git push origin v7-master
|
||||||
echo -e "\033[32mPush to Gitee v6-master\033[0m"
|
echo -e "\033[32mPush to Gitee v7-master\033[0m"
|
||||||
git push osc v6-master
|
git push osc v7-master
|
||||||
echo -e "\033[32mPush to Gitcode v6-master\033[0m"
|
echo -e "\033[32mPush to Gitcode v7-master\033[0m"
|
||||||
git push gitcode v6-master
|
git push gitcode v7-master
|
||||||
|
|||||||
10
bin/sync.sh
10
bin/sync.sh
@@ -19,10 +19,10 @@
|
|||||||
# show Hutool logo
|
# show Hutool logo
|
||||||
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
"$(dirname ${BASH_SOURCE[0]})"/logo.sh
|
||||||
|
|
||||||
# 保证当前在v6-dev分支
|
# 保证当前在v7-dev分支
|
||||||
git checkout v6-dev
|
git checkout v7-dev
|
||||||
|
|
||||||
# 同时同步Gitee、Github和Gitcode的库
|
# 同时同步Gitee、Github和Gitcode的库
|
||||||
git pull osc v6-dev
|
git pull osc v7-dev
|
||||||
git pull origin v6-dev
|
git pull origin v7-dev
|
||||||
git pull gitcode v6-dev
|
git pull gitcode v7-dev
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
6.0.0-M23
|
7.0.0-M2
|
||||||
|
|||||||
@@ -55,6 +55,16 @@
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<!-- 百度统计 -->
|
||||||
|
<script>
|
||||||
|
var _hmt = _hmt || [];
|
||||||
|
(function () {
|
||||||
|
var hm = document.createElement("script");
|
||||||
|
hm.src = "https://hm.baidu.com/hm.js?a76bc7a2d60207f04195af1c51cdb9ba";
|
||||||
|
var s = document.getElementsByTagName("script")[0];
|
||||||
|
s.parentNode.insertBefore(hm, s);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
var version = '6.0.0-M23'
|
var version = '7.0.0-M2'
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-parent</artifactId>
|
<artifactId>hutool-parent</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>hutool-ai</artifactId>
|
<artifactId>hutool-ai</artifactId>
|
||||||
@@ -17,34 +17,29 @@
|
|||||||
<description>Hutool AI大模型封装</description>
|
<description>Hutool AI大模型封装</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<Automatic-Module-Name>org.dromara.hutool.ai</Automatic-Module-Name>
|
<Automatic-Module-Name>cn.hutool.v7.ai</Automatic-Module-Name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-core</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.dromara.hutool</groupId>
|
|
||||||
<artifactId>hutool-http</artifactId>
|
<artifactId>hutool-http</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-log</artifactId>
|
<artifactId>hutool-log</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-json</artifactId>
|
<artifactId>hutool-json</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-swing</artifactId>
|
<artifactId>hutool-swing</artifactId>
|
||||||
<version>${project.parent.version}</version>
|
<version>${project.parent.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
import org.dromara.hutool.core.exception.HutoolException;
|
import cn.hutool.v7.core.exception.HutoolException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异常处理类
|
* 异常处理类
|
||||||
@@ -14,15 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;
|
import cn.hutool.v7.core.spi.ServiceLoader;
|
||||||
|
import cn.hutool.v7.core.spi.SpiUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建AIModelService的工厂类
|
* 创建AIModelService的工厂类
|
||||||
@@ -32,11 +33,11 @@ import java.util.ServiceLoader;
|
|||||||
*/
|
*/
|
||||||
public class AIServiceFactory {
|
public class AIServiceFactory {
|
||||||
|
|
||||||
private static final Map<String, AIServiceProvider> providers = new SafeConcurrentHashMap<>();
|
private static final Map<String, AIServiceProvider> providers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// 加载所有 AIModelProvider 实现类
|
// 加载所有 AIModelProvider 实现类
|
||||||
static {
|
static {
|
||||||
final ServiceLoader<AIServiceProvider> loader = ServiceLoader.load(AIServiceProvider.class);
|
final ServiceLoader<AIServiceProvider> loader = SpiUtil.loadList(AIServiceProvider.class);
|
||||||
for (final AIServiceProvider provider : loader) {
|
for (final AIServiceProvider provider : loader) {
|
||||||
providers.put(provider.getServiceName().toLowerCase(), provider);
|
providers.put(provider.getServiceName().toLowerCase(), provider);
|
||||||
}
|
}
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.ai.model.deepseek.DeepSeekService;
|
import cn.hutool.v7.ai.model.deepseek.DeepSeekService;
|
||||||
import org.dromara.hutool.ai.model.doubao.DoubaoService;
|
import cn.hutool.v7.ai.model.doubao.DoubaoService;
|
||||||
import org.dromara.hutool.ai.model.grok.GrokService;
|
import cn.hutool.v7.ai.model.grok.GrokService;
|
||||||
import org.dromara.hutool.ai.model.hutool.HutoolService;
|
import cn.hutool.v7.ai.model.hutool.HutoolService;
|
||||||
import org.dromara.hutool.ai.model.openai.OpenaiService;
|
import cn.hutool.v7.ai.model.openai.OpenaiService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模型厂商的名称(不指具体的模型)
|
* 模型厂商的名称(不指具体的模型)
|
||||||
@@ -42,7 +42,11 @@ public enum ModelName {
|
|||||||
/**
|
/**
|
||||||
* grok
|
* grok
|
||||||
*/
|
*/
|
||||||
GROK("grok");
|
GROK("grok"),
|
||||||
|
/**
|
||||||
|
* ollama
|
||||||
|
*/
|
||||||
|
OLLAMA("ollama");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 各模型厂商包含的model(指具体的模型)
|
* 各模型厂商包含的model(指具体的模型)
|
||||||
@@ -30,7 +30,7 @@ public class Models {
|
|||||||
|
|
||||||
private final String model;
|
private final String model;
|
||||||
|
|
||||||
Hutool(String model) {
|
Hutool(final String model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ public class Models {
|
|||||||
|
|
||||||
private final String model;
|
private final String model;
|
||||||
|
|
||||||
DeepSeek(String model) {
|
DeepSeek(final String model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class Models {
|
|||||||
|
|
||||||
private final String model;
|
private final String model;
|
||||||
|
|
||||||
Openai(String model) {
|
Openai(final String model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ public class Models {
|
|||||||
|
|
||||||
private final String model;
|
private final String model;
|
||||||
|
|
||||||
Doubao(String model) {
|
Doubao(final String model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ public class Models {
|
|||||||
|
|
||||||
private final String model;
|
private final String model;
|
||||||
|
|
||||||
Grok(String model) {
|
Grok(final String model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,4 +191,18 @@ public class Models {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ollama的模型
|
||||||
|
public enum Ollama {
|
||||||
|
QWEN3_32B("qwen3:32b");
|
||||||
|
|
||||||
|
private final String model;
|
||||||
|
|
||||||
|
Ollama(final String model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
@@ -14,12 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;
|
import cn.hutool.v7.core.spi.ServiceLoader;
|
||||||
|
import cn.hutool.v7.core.spi.SpiUtil;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ServiceLoader;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AIConfig实现类的加载器
|
* AIConfig实现类的加载器
|
||||||
@@ -29,11 +30,11 @@ import java.util.ServiceLoader;
|
|||||||
*/
|
*/
|
||||||
public class AIConfigRegistry {
|
public class AIConfigRegistry {
|
||||||
|
|
||||||
private static final Map<String, Class<? extends AIConfig>> configClasses = new SafeConcurrentHashMap<>();
|
private static final Map<String, Class<? extends AIConfig>> configClasses = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
// 加载所有 AIConfig 实现类
|
// 加载所有 AIConfig 实现类
|
||||||
static {
|
static {
|
||||||
final ServiceLoader<AIConfig> loader = ServiceLoader.load(AIConfig.class);
|
final ServiceLoader<AIConfig> loader = SpiUtil.loadList(AIConfig.class);
|
||||||
for (final AIConfig config : loader) {
|
for (final AIConfig config : loader) {
|
||||||
configClasses.put(config.getModelName().toLowerCase(), config.getClass());
|
configClasses.put(config.getModelName().toLowerCase(), config.getClass());
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用于加载AI服务,每一个通过SPI创建的AI服务都要实现此接口
|
* 用于加载AI服务,每一个通过SPI创建的AI服务都要实现此接口
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIException;
|
import cn.hutool.v7.ai.AIException;
|
||||||
import org.dromara.hutool.http.HttpGlobalConfig;
|
import cn.hutool.v7.http.HttpGlobalConfig;
|
||||||
import org.dromara.hutool.http.HttpUtil;
|
import cn.hutool.v7.http.HttpUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.http.meta.HeaderName;
|
import cn.hutool.v7.http.meta.HeaderName;
|
||||||
import org.dromara.hutool.http.meta.Method;
|
import cn.hutool.v7.http.meta.Method;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -40,6 +40,9 @@ import java.util.function.Consumer;
|
|||||||
*/
|
*/
|
||||||
public class BaseAIService {
|
public class BaseAIService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI配置
|
||||||
|
*/
|
||||||
protected final AIConfig config;
|
protected final AIConfig config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,11 +125,11 @@ public class BaseAIService {
|
|||||||
* @param paramMap 请求参数
|
* @param paramMap 请求参数
|
||||||
* @param callback 流式数据回调函数
|
* @param callback 流式数据回调函数
|
||||||
*/
|
*/
|
||||||
protected void sendPostStream(final String endpoint, final Map<String, Object> paramMap, Consumer<String> callback) {
|
protected void sendPostStream(final String endpoint, final Map<String, Object> paramMap, final Consumer<String> callback) {
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
try {
|
try {
|
||||||
// 创建连接
|
// 创建连接
|
||||||
URL apiUrl = new URL(config.getApiUrl() + endpoint);
|
final URL apiUrl = new URL(config.getApiUrl() + endpoint);
|
||||||
connection = (HttpURLConnection) apiUrl.openConnection();
|
connection = (HttpURLConnection) apiUrl.openConnection();
|
||||||
connection.setRequestMethod(Method.POST.name());
|
connection.setRequestMethod(Method.POST.name());
|
||||||
connection.setRequestProperty(HeaderName.CONTENT_TYPE.getValue(), "application/json");
|
connection.setRequestProperty(HeaderName.CONTENT_TYPE.getValue(), "application/json");
|
||||||
@@ -137,21 +140,21 @@ public class BaseAIService {
|
|||||||
//设置连接超时
|
//设置连接超时
|
||||||
connection.setConnectTimeout(config.getTimeout());
|
connection.setConnectTimeout(config.getTimeout());
|
||||||
// 发送请求体
|
// 发送请求体
|
||||||
try (OutputStream os = connection.getOutputStream()) {
|
try (final OutputStream os = connection.getOutputStream()) {
|
||||||
String jsonInputString = JSONUtil.toJsonStr(paramMap);
|
final String jsonInputString = JSONUtil.toJsonStr(paramMap);
|
||||||
os.write(jsonInputString.getBytes());
|
os.write(jsonInputString.getBytes());
|
||||||
os.flush();
|
os.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取流式响应
|
// 读取流式响应
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
// 调用回调函数处理每一行数据
|
// 调用回调函数处理每一行数据
|
||||||
callback.accept(line);
|
callback.accept(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
callback.accept("{\"error\": \"" + e.getMessage() + "\"}");
|
callback.accept("{\"error\": \"" + e.getMessage() + "\"}");
|
||||||
} finally {
|
} finally {
|
||||||
// 关闭连接
|
// 关闭连接
|
||||||
@@ -14,11 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config基础类,定义模型配置的基本属性
|
* Config基础类,定义模型配置的基本属性
|
||||||
@@ -28,17 +27,29 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class BaseConfig implements AIConfig {
|
public class BaseConfig implements AIConfig {
|
||||||
|
|
||||||
//apiKey
|
/**
|
||||||
|
* API Key
|
||||||
|
*/
|
||||||
protected volatile String apiKey;
|
protected volatile String apiKey;
|
||||||
//API请求地址
|
/**
|
||||||
|
* API请求地址
|
||||||
|
*/
|
||||||
protected volatile String apiUrl;
|
protected volatile String apiUrl;
|
||||||
//具体模型
|
/**
|
||||||
|
* 模型名称
|
||||||
|
*/
|
||||||
protected volatile String model;
|
protected volatile String model;
|
||||||
//动态扩展字段
|
/**
|
||||||
protected Map<String, Object> additionalConfig = new SafeConcurrentHashMap<>();
|
* 额外的配置
|
||||||
//连接超时时间
|
*/
|
||||||
|
protected final Map<String, Object> additionalConfig = new ConcurrentHashMap<>();
|
||||||
|
/**
|
||||||
|
* 请求超时
|
||||||
|
*/
|
||||||
protected volatile int timeout = 180000;
|
protected volatile int timeout = 180000;
|
||||||
//读取超时时间
|
/**
|
||||||
|
* 读取超时
|
||||||
|
*/
|
||||||
protected volatile int readTimeout = 300000;
|
protected volatile int readTimeout = 300000;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,7 +94,7 @@ public class BaseConfig implements AIConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getAdditionalConfigMap() {
|
public Map<String, Object> getAdditionalConfigMap() {
|
||||||
return new SafeConcurrentHashMap<>(additionalConfig);
|
return new ConcurrentHashMap<>(additionalConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 公共Message类
|
* 公共Message类
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.core;
|
package cn.hutool.v7.ai.core;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deepSeek公共类
|
* deepSeek公共类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.BaseConfig;
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DeepSeek配置类,初始化API接口地址,设置默认的模型
|
* DeepSeek配置类,初始化API接口地址,设置默认的模型
|
||||||
@@ -27,20 +27,37 @@ import org.dromara.hutool.ai.core.BaseConfig;
|
|||||||
*/
|
*/
|
||||||
public class DeepSeekConfig extends BaseConfig {
|
public class DeepSeekConfig extends BaseConfig {
|
||||||
|
|
||||||
private final String API_URL = "https://api.deepseek.com";
|
/**
|
||||||
|
* 定义API的基础URL,用于后续的所有API请求
|
||||||
|
*/
|
||||||
|
public final String API_URL = "https://api.deepseek.com";
|
||||||
|
|
||||||
private final String DEFAULT_MODEL = Models.DeepSeek.DEEPSEEK_CHAT.getModel();
|
/**
|
||||||
|
* 定义默认的模型名称,用于在没有指定模型时使用
|
||||||
|
*/
|
||||||
|
public final String DEFAULT_MODEL = Models.DeepSeek.DEEPSEEK_CHAT.getModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认构造函数,用于初始化DeepSeek配置对象
|
||||||
|
* 设置API的基础URL和默认的模型名称
|
||||||
|
*/
|
||||||
public DeepSeekConfig() {
|
public DeepSeekConfig() {
|
||||||
setApiUrl(API_URL);
|
setApiUrl(API_URL);
|
||||||
setModel(DEFAULT_MODEL);
|
setModel(DEFAULT_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeepSeekConfig(String apiKey) {
|
/**
|
||||||
this();
|
* 带API密钥参数的构造函数
|
||||||
|
* 用于初始化DeepSeek配置对象,并设置API密钥
|
||||||
|
*
|
||||||
|
* @param apiKey 用户的API密钥,用于认证和授权
|
||||||
|
*/
|
||||||
|
public DeepSeekConfig(final String apiKey) {
|
||||||
|
this(); // 调用默认构造函数初始化API_URL和DEFAULT_MODEL
|
||||||
setApiKey(apiKey);
|
setApiKey(apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelName() {
|
public String getModelName() {
|
||||||
return "deepSeek";
|
return "deepSeek";
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建DeepSeek服务实现类
|
* 创建DeepSeek服务实现类
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.BaseAIService;
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* doubao公共类
|
* doubao公共类
|
||||||
@@ -24,70 +24,139 @@ package org.dromara.hutool.ai.model.doubao;
|
|||||||
*/
|
*/
|
||||||
public class DoubaoCommon {
|
public class DoubaoCommon {
|
||||||
|
|
||||||
//doubao上下文缓存参数
|
/**
|
||||||
|
* doubao上下文缓存参数
|
||||||
|
*/
|
||||||
public enum DoubaoContext {
|
public enum DoubaoContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* session
|
||||||
|
*/
|
||||||
SESSION("session"),
|
SESSION("session"),
|
||||||
|
/**
|
||||||
|
* common_prefix
|
||||||
|
*/
|
||||||
COMMON_PREFIX("common_prefix");
|
COMMON_PREFIX("common_prefix");
|
||||||
|
|
||||||
private final String mode;
|
private final String mode;
|
||||||
|
|
||||||
DoubaoContext(String mode) {
|
DoubaoContext(final String mode) {
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数
|
||||||
|
*
|
||||||
|
* @return 参数
|
||||||
|
*/
|
||||||
public String getMode() {
|
public String getMode() {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//doubao视觉参数
|
/**
|
||||||
|
* doubao视觉参数
|
||||||
|
*/
|
||||||
public enum DoubaoVision {
|
public enum DoubaoVision {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动
|
||||||
|
*/
|
||||||
AUTO("auto"),
|
AUTO("auto"),
|
||||||
|
/**
|
||||||
|
* 低
|
||||||
|
*/
|
||||||
LOW("low"),
|
LOW("low"),
|
||||||
|
/**
|
||||||
|
* 高
|
||||||
|
*/
|
||||||
HIGH("high");
|
HIGH("high");
|
||||||
|
|
||||||
private final String detail;
|
private final String detail;
|
||||||
|
|
||||||
DoubaoVision(String detail) {
|
DoubaoVision(final String detail) {
|
||||||
this.detail = detail;
|
this.detail = detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取参数
|
||||||
|
*
|
||||||
|
* @return 参数
|
||||||
|
*/
|
||||||
public String getDetail() {
|
public String getDetail() {
|
||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//doubao视频生成参数
|
/**
|
||||||
|
* doubao视频生成参数
|
||||||
|
*/
|
||||||
public enum DoubaoVideo {
|
public enum DoubaoVideo {
|
||||||
|
|
||||||
//宽高比例
|
//宽高比例
|
||||||
|
/**
|
||||||
|
* 视频比例16:9,适用于横向宽屏显示,常用作标准视频比例
|
||||||
|
*/
|
||||||
RATIO_16_9("--rt", "16:9"),//[1280, 720]
|
RATIO_16_9("--rt", "16:9"),//[1280, 720]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频比例4:3,传统电视屏幕比例,适用于标准清晰度的视频内容
|
||||||
|
*/
|
||||||
RATIO_4_3("--rt", "4:3"),//[960, 720]
|
RATIO_4_3("--rt", "4:3"),//[960, 720]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频比例1:1,正方形画面,适用于社交媒体平台上的短视频内容
|
||||||
|
*/
|
||||||
RATIO_1_1("--rt", "1:1"),//[720, 720]
|
RATIO_1_1("--rt", "1:1"),//[720, 720]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频比例3:4,竖向视频比例,适用于手机端的视频播放场景
|
||||||
|
*/
|
||||||
RATIO_3_4("--rt", "3:4"),//[720, 960]
|
RATIO_3_4("--rt", "3:4"),//[720, 960]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频比例9:16,常见的竖屏视频比例,广泛用于短视频应用
|
||||||
|
*/
|
||||||
RATIO_9_16("--rt", "9:16"),//[720, 1280]
|
RATIO_9_16("--rt", "9:16"),//[720, 1280]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 视频比例21:9,超宽屏幕比例,提供更广阔的视野,适合电影和游戏体验
|
||||||
|
*/
|
||||||
RATIO_21_9("--rt", "21:9"),//[1280, 544]
|
RATIO_21_9("--rt", "21:9"),//[1280, 544]
|
||||||
|
|
||||||
//生成视频时长
|
//生成视频时长
|
||||||
DURATION_5("--dur", 5),//文生视频,图生视频
|
/**
|
||||||
DURATION_10("--dur", 10),//文生视频
|
* 文生视频,图生视频
|
||||||
|
*/
|
||||||
|
DURATION_5("--dur", 5),
|
||||||
|
/**
|
||||||
|
* 文生视频
|
||||||
|
*/
|
||||||
|
DURATION_10("--dur", 10),
|
||||||
|
|
||||||
//帧率,即一秒时间内视频画面数量
|
/**
|
||||||
|
* 帧率,即一秒时间内视频画面数量
|
||||||
|
*/
|
||||||
FPS_5("--fps", 24),
|
FPS_5("--fps", 24),
|
||||||
|
|
||||||
//视频分辨率
|
/**
|
||||||
|
* 视频分辨率
|
||||||
|
*/
|
||||||
RESOLUTION_5("--rs", "720p"),
|
RESOLUTION_5("--rs", "720p"),
|
||||||
|
|
||||||
//生成视频是否包含水印
|
/**
|
||||||
|
* 生成视频包含水印
|
||||||
|
*/
|
||||||
WATERMARK_TRUE("--wm", true),
|
WATERMARK_TRUE("--wm", true),
|
||||||
|
/**
|
||||||
|
* 生成视频不包含水印
|
||||||
|
*/
|
||||||
WATERMARK_FALSE("--wm", false);
|
WATERMARK_FALSE("--wm", false);
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
DoubaoVideo(String type, Object value) {
|
DoubaoVideo(final String type, final Object value) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
|
import cn.hutool.v7.ai.Models;
|
||||||
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doubao配置类,初始化API接口地址,设置默认的模型
|
||||||
|
*
|
||||||
|
* @author elichow
|
||||||
|
* @since 6.0.0
|
||||||
|
*/
|
||||||
|
public class DoubaoConfig extends BaseConfig {
|
||||||
|
|
||||||
|
// 定义API的基础URL,用于和服务器通信
|
||||||
|
private static final String API_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
||||||
|
|
||||||
|
// 定义默认的模型配置,用于初始化配置对象时设定
|
||||||
|
private static final String DEFAULT_MODEL = Models.Doubao.DOUBAO_1_5_LITE_32K.getModel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无参构造函数,用于创建DoubaoConfig对象
|
||||||
|
* 初始化时会设置API_URL和DEFAULT_MODEL
|
||||||
|
*/
|
||||||
|
public DoubaoConfig() {
|
||||||
|
setApiUrl(API_URL);
|
||||||
|
setModel(DEFAULT_MODEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带有apiKey参数的构造函数,用于创建DoubaoConfig对象并设置API密钥
|
||||||
|
* 初始化时会设置API_URL、DEFAULT_MODEL以及传入的apiKey
|
||||||
|
*
|
||||||
|
* @param apiKey 用户的API密钥,用于验证用户身份
|
||||||
|
*/
|
||||||
|
public DoubaoConfig(final String apiKey) {
|
||||||
|
this(); // 先调用无参构造函数初始化API_URL和DEFAULT_MODEL
|
||||||
|
setApiKey(apiKey); // 设置用户的API密钥
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModelName() {
|
||||||
|
return "doubao";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Doubap服务实现类
|
* 创建Doubap服务实现类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.BaseAIService;
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -39,25 +39,25 @@ import java.util.function.Consumer;
|
|||||||
public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
||||||
|
|
||||||
//对话
|
//对话
|
||||||
private final String CHAT_ENDPOINT = "/chat/completions";
|
private static final String CHAT_ENDPOINT = "/chat/completions";
|
||||||
//文本向量化
|
//文本向量化
|
||||||
private final String EMBEDDING_TEXT = "/embeddings";
|
private static final String EMBEDDING_TEXT = "/embeddings";
|
||||||
//图文向量化
|
//图文向量化
|
||||||
private final String EMBEDDING_VISION = "/embeddings/multimodal";
|
private static final String EMBEDDING_VISION = "/embeddings/multimodal";
|
||||||
//应用bots
|
//应用bots
|
||||||
private final String BOTS_CHAT = "/bots/chat/completions";
|
private static final String BOTS_CHAT = "/bots/chat/completions";
|
||||||
//分词
|
//分词
|
||||||
private final String TOKENIZATION = "/tokenization";
|
private static final String TOKENIZATION = "/tokenization";
|
||||||
//批量推理chat
|
//批量推理chat
|
||||||
private final String BATCH_CHAT = "/batch/chat/completions";
|
private static final String BATCH_CHAT = "/batch/chat/completions";
|
||||||
//创建上下文缓存
|
//创建上下文缓存
|
||||||
private final String CREATE_CONTEXT = "/context/create";
|
private static final String CREATE_CONTEXT = "/context/create";
|
||||||
//上下文缓存对话
|
//上下文缓存对话
|
||||||
private final String CHAT_CONTEXT = "/context/chat/completions";
|
private static final String CHAT_CONTEXT = "/context/chat/completions";
|
||||||
//创建视频生成任务
|
//创建视频生成任务
|
||||||
private final String CREATE_VIDEO = "/contents/generations/tasks";
|
private static final String CREATE_VIDEO = "/contents/generations/tasks";
|
||||||
//文生图
|
//文生图
|
||||||
private final String IMAGES_GENERATIONS = "/images/generations";
|
private static final String IMAGES_GENERATIONS = "/images/generations";
|
||||||
|
|
||||||
public DoubaoServiceImpl(final AIConfig config) {
|
public DoubaoServiceImpl(final AIConfig config) {
|
||||||
//初始化doubao客户端
|
//初始化doubao客户端
|
||||||
@@ -66,109 +66,109 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String chat(final List<Message> messages) {
|
public String chat(final List<Message> messages) {
|
||||||
String paramJson = buildChatRequestBody(messages);
|
final String paramJson = buildChatRequestBody(messages);
|
||||||
Response response = sendPost(CHAT_ENDPOINT, paramJson);
|
final Response response = sendPost(CHAT_ENDPOINT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void chat(List<Message> messages, Consumer<String> callback) {
|
public void chat(final List<Message> messages, final Consumer<String> callback) {
|
||||||
Map<String, Object> paramMap = buildChatStreamRequestBody(messages);
|
final Map<String, Object> paramMap = buildChatStreamRequestBody(messages);
|
||||||
ThreadUtil.newThread(() -> sendPostStream(CHAT_ENDPOINT, paramMap, callback::accept), "doubao-chat-sse").start();
|
ThreadUtil.newThread(() -> sendPostStream(CHAT_ENDPOINT, paramMap, callback::accept), "doubao-chat-sse").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String chatVision(String prompt, final List<String> images, String detail) {
|
public String chatVision(final String prompt, final List<String> images, final String detail) {
|
||||||
String paramJson = buildChatVisionRequestBody(prompt, images, detail);
|
final String paramJson = buildChatVisionRequestBody(prompt, images, detail);
|
||||||
Response response = sendPost(CHAT_ENDPOINT, paramJson);
|
final Response response = sendPost(CHAT_ENDPOINT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void chatVision(String prompt, List<String> images, String detail, Consumer<String> callback) {
|
public void chatVision(final String prompt, final List<String> images, final String detail, final Consumer<String> callback) {
|
||||||
Map<String, Object> paramMap = buildChatVisionStreamRequestBody(prompt, images, detail);
|
final Map<String, Object> paramMap = buildChatVisionStreamRequestBody(prompt, images, detail);
|
||||||
ThreadUtil.newThread(() -> sendPostStream(CHAT_ENDPOINT, paramMap, callback::accept), "doubao-chatVision-sse").start();
|
ThreadUtil.newThread(() -> sendPostStream(CHAT_ENDPOINT, paramMap, callback::accept), "doubao-chatVision-sse").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String videoTasks(String text, String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
|
public String videoTasks(final String text, final String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
|
||||||
String paramJson = buildGenerationsTasksRequestBody(text, image, videoParams);
|
final String paramJson = buildGenerationsTasksRequestBody(text, image, videoParams);
|
||||||
Response response = sendPost(CREATE_VIDEO, paramJson);
|
final Response response = sendPost(CREATE_VIDEO, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVideoTasksInfo(String taskId) {
|
public String getVideoTasksInfo(final String taskId) {
|
||||||
Response response = sendGet(CREATE_VIDEO + "/" + taskId);
|
final Response response = sendGet(CREATE_VIDEO + "/" + taskId);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String embeddingText(String[] input) {
|
public String embeddingText(final String[] input) {
|
||||||
String paramJson = buildEmbeddingTextRequestBody(input);
|
final String paramJson = buildEmbeddingTextRequestBody(input);
|
||||||
Response response = sendPost(EMBEDDING_TEXT, paramJson);
|
final Response response = sendPost(EMBEDDING_TEXT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String embeddingVision(String text, String image) {
|
public String embeddingVision(final String text, final String image) {
|
||||||
String paramJson = buildEmbeddingVisionRequestBody(text, image);
|
final String paramJson = buildEmbeddingVisionRequestBody(text, image);
|
||||||
Response response = sendPost(EMBEDDING_VISION, paramJson);
|
final Response response = sendPost(EMBEDDING_VISION, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String botsChat(final List<Message> messages) {
|
public String botsChat(final List<Message> messages) {
|
||||||
String paramJson = buildBotsChatRequestBody(messages);
|
final String paramJson = buildBotsChatRequestBody(messages);
|
||||||
Response response = sendPost(BOTS_CHAT, paramJson);
|
final Response response = sendPost(BOTS_CHAT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void botsChat(List<Message> messages, Consumer<String> callback) {
|
public void botsChat(final List<Message> messages, final Consumer<String> callback) {
|
||||||
Map<String, Object> paramMap = buildBotsChatStreamRequestBody(messages);
|
final Map<String, Object> paramMap = buildBotsChatStreamRequestBody(messages);
|
||||||
ThreadUtil.newThread(() -> sendPostStream(BOTS_CHAT, paramMap, callback::accept), "doubao-botsChat-sse").start();
|
ThreadUtil.newThread(() -> sendPostStream(BOTS_CHAT, paramMap, callback::accept), "doubao-botsChat-sse").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String tokenization(String[] text) {
|
public String tokenization(final String[] text) {
|
||||||
String paramJson = buildTokenizationRequestBody(text);
|
final String paramJson = buildTokenizationRequestBody(text);
|
||||||
Response response = sendPost(TOKENIZATION, paramJson);
|
final Response response = sendPost(TOKENIZATION, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String batchChat(final List<Message> messages) {
|
public String batchChat(final List<Message> messages) {
|
||||||
String paramJson = buildBatchChatRequestBody(messages);
|
final String paramJson = buildBatchChatRequestBody(messages);
|
||||||
Response response = sendPost(BATCH_CHAT, paramJson);
|
final Response response = sendPost(BATCH_CHAT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createContext(final List<Message> messages, String mode) {
|
public String createContext(final List<Message> messages, final String mode) {
|
||||||
String paramJson = buildCreateContextRequest(messages, mode);
|
final String paramJson = buildCreateContextRequest(messages, mode);
|
||||||
Response response = sendPost(CREATE_CONTEXT, paramJson);
|
final Response response = sendPost(CREATE_CONTEXT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String chatContext(final List<Message> messages, String contextId) {
|
public String chatContext(final List<Message> messages, final String contextId) {
|
||||||
String paramJson = buildChatContentRequestBody(messages, contextId);
|
final String paramJson = buildChatContentRequestBody(messages, contextId);
|
||||||
Response response = sendPost(CHAT_CONTEXT, paramJson);
|
final Response response = sendPost(CHAT_CONTEXT, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void chatContext(List<Message> messages, String contextId, Consumer<String> callback) {
|
public void chatContext(final List<Message> messages, final String contextId, final Consumer<String> callback) {
|
||||||
Map<String, Object> paramMap = buildChatContentStreamRequestBody(messages, contextId);
|
final Map<String, Object> paramMap = buildChatContentStreamRequestBody(messages, contextId);
|
||||||
ThreadUtil.newThread(() -> sendPostStream(CHAT_CONTEXT, paramMap, callback::accept), "doubao-chatContext-sse").start();
|
ThreadUtil.newThread(() -> sendPostStream(CHAT_CONTEXT, paramMap, callback::accept), "doubao-chatContext-sse").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String imagesGenerations(String prompt) {
|
public String imagesGenerations(final String prompt) {
|
||||||
String paramJson = buildImagesGenerationsRequestBody(prompt);
|
final String paramJson = buildImagesGenerationsRequestBody(prompt);
|
||||||
Response response = sendPost(IMAGES_GENERATIONS, paramJson);
|
final Response response = sendPost(IMAGES_GENERATIONS, paramJson);
|
||||||
return response.bodyStr();
|
return response.bodyStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建chatVision请求体
|
//构建chatVision请求体
|
||||||
private String buildChatVisionRequestBody(String prompt, final List<String> images, String detail) {
|
private String buildChatVisionRequestBody(final String prompt, final List<String> images, final String detail) {
|
||||||
// 定义消息结构
|
// 定义消息结构
|
||||||
final List<Message> messages = new ArrayList<>();
|
final List<Message> messages = new ArrayList<>();
|
||||||
final List<Object> content = new ArrayList<>();
|
final List<Object> content = new ArrayList<>();
|
||||||
@@ -207,10 +207,10 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
contentMap.put("type", "text");
|
contentMap.put("type", "text");
|
||||||
contentMap.put("text", prompt);
|
contentMap.put("text", prompt);
|
||||||
content.add(contentMap);
|
content.add(contentMap);
|
||||||
for (String img : images) {
|
for (final String img : images) {
|
||||||
HashMap<String, Object> imgUrlMap = new HashMap<>();
|
final HashMap<String, Object> imgUrlMap = new HashMap<>();
|
||||||
imgUrlMap.put("type", "image_url");
|
imgUrlMap.put("type", "image_url");
|
||||||
HashMap<String, String> urlMap = new HashMap<>();
|
final HashMap<String, String> urlMap = new HashMap<>();
|
||||||
urlMap.put("url", img);
|
urlMap.put("url", img);
|
||||||
urlMap.put("detail", detail);
|
urlMap.put("detail", detail);
|
||||||
imgUrlMap.put("image_url", urlMap);
|
imgUrlMap.put("image_url", urlMap);
|
||||||
@@ -228,7 +228,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
return JSONUtil.toJsonStr(paramMap);
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> buildChatVisionStreamRequestBody(String prompt, final List<String> images, String detail) {
|
private Map<String, Object> buildChatVisionStreamRequestBody(final String prompt, final List<String> images, final String detail) {
|
||||||
// 定义消息结构
|
// 定义消息结构
|
||||||
final List<Message> messages = new ArrayList<>();
|
final List<Message> messages = new ArrayList<>();
|
||||||
final List<Object> content = new ArrayList<>();
|
final List<Object> content = new ArrayList<>();
|
||||||
@@ -237,10 +237,10 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
contentMap.put("type", "text");
|
contentMap.put("type", "text");
|
||||||
contentMap.put("text", prompt);
|
contentMap.put("text", prompt);
|
||||||
content.add(contentMap);
|
content.add(contentMap);
|
||||||
for (String img : images) {
|
for (final String img : images) {
|
||||||
HashMap<String, Object> imgUrlMap = new HashMap<>();
|
final HashMap<String, Object> imgUrlMap = new HashMap<>();
|
||||||
imgUrlMap.put("type", "image_url");
|
imgUrlMap.put("type", "image_url");
|
||||||
HashMap<String, String> urlMap = new HashMap<>();
|
final HashMap<String, String> urlMap = new HashMap<>();
|
||||||
urlMap.put("url", img);
|
urlMap.put("url", img);
|
||||||
urlMap.put("detail", detail);
|
urlMap.put("detail", detail);
|
||||||
imgUrlMap.put("image_url", urlMap);
|
imgUrlMap.put("image_url", urlMap);
|
||||||
@@ -260,7 +260,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建文本向量化请求体
|
//构建文本向量化请求体
|
||||||
private String buildEmbeddingTextRequestBody(String[] input) {
|
private String buildEmbeddingTextRequestBody(final String[] input) {
|
||||||
//使用JSON工具
|
//使用JSON工具
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
@@ -271,7 +271,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建图文向量化请求体
|
//构建图文向量化请求体
|
||||||
private String buildEmbeddingVisionRequestBody(String text, String image) {
|
private String buildEmbeddingVisionRequestBody(final String text, final String image) {
|
||||||
//使用JSON工具
|
//使用JSON工具
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
@@ -311,7 +311,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建分词请求体
|
//构建分词请求体
|
||||||
private String buildTokenizationRequestBody(String[] text) {
|
private String buildTokenizationRequestBody(final String[] text) {
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
paramMap.put("text", text);
|
paramMap.put("text", text);
|
||||||
@@ -328,7 +328,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建创建上下文缓存请求体
|
//构建创建上下文缓存请求体
|
||||||
private String buildCreateContextRequest(final List<Message> messages, String mode) {
|
private String buildCreateContextRequest(final List<Message> messages, final String mode) {
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("messages", messages);
|
paramMap.put("messages", messages);
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
@@ -340,7 +340,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建上下文缓存对话请求体
|
//构建上下文缓存对话请求体
|
||||||
private String buildChatContentRequestBody(final List<Message> messages, String contextId) {
|
private String buildChatContentRequestBody(final List<Message> messages, final String contextId) {
|
||||||
//使用JSON工具
|
//使用JSON工具
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
@@ -352,7 +352,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
return JSONUtil.toJsonStr(paramMap);
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> buildChatContentStreamRequestBody(final List<Message> messages, String contextId) {
|
private Map<String, Object> buildChatContentStreamRequestBody(final List<Message> messages, final String contextId) {
|
||||||
//使用JSON工具
|
//使用JSON工具
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("stream", true);
|
paramMap.put("stream", true);
|
||||||
@@ -366,7 +366,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建创建视频任务请求体
|
//构建创建视频任务请求体
|
||||||
private String buildGenerationsTasksRequestBody(String text, String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
|
private String buildGenerationsTasksRequestBody(final String text, final String image, final List<DoubaoCommon.DoubaoVideo> videoParams) {
|
||||||
//使用JSON工具
|
//使用JSON工具
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
@@ -392,10 +392,10 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
//添加视频参数
|
//添加视频参数
|
||||||
if (videoParams != null && !videoParams.isEmpty()) {
|
if (videoParams != null && !videoParams.isEmpty()) {
|
||||||
//如果有文本参数就加在后面
|
//如果有文本参数就加在后面
|
||||||
if (textMap != null && !textMap.isEmpty()) {
|
if (!textMap.isEmpty()) {
|
||||||
int textIndex = content.indexOf(textMap);
|
final int textIndex = content.indexOf(textMap);
|
||||||
StringBuilder textBuilder = new StringBuilder(text);
|
final StringBuilder textBuilder = new StringBuilder(text);
|
||||||
for (DoubaoCommon.DoubaoVideo videoParam : videoParams) {
|
for (final DoubaoCommon.DoubaoVideo videoParam : videoParams) {
|
||||||
textBuilder.append(" ").append(videoParam.getType()).append(" ").append(videoParam.getValue());
|
textBuilder.append(" ").append(videoParam.getType()).append(" ").append(videoParam.getValue());
|
||||||
}
|
}
|
||||||
textMap.put("type", "text");
|
textMap.put("type", "text");
|
||||||
@@ -408,8 +408,8 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//如果没有文本参数就重新增加
|
//如果没有文本参数就重新增加
|
||||||
StringBuilder textBuilder = new StringBuilder();
|
final StringBuilder textBuilder = new StringBuilder();
|
||||||
for (DoubaoCommon.DoubaoVideo videoParam : videoParams) {
|
for (final DoubaoCommon.DoubaoVideo videoParam : videoParams) {
|
||||||
textBuilder.append(videoParam.getType()).append(videoParam.getValue()).append(" ");
|
textBuilder.append(videoParam.getType()).append(videoParam.getValue()).append(" ");
|
||||||
}
|
}
|
||||||
textMap.put("type", "text");
|
textMap.put("type", "text");
|
||||||
@@ -426,7 +426,7 @@ public class DoubaoServiceImpl extends BaseAIService implements DoubaoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//构建文生图请求体
|
//构建文生图请求体
|
||||||
private String buildImagesGenerationsRequestBody(String prompt) {
|
private String buildImagesGenerationsRequestBody(final String prompt) {
|
||||||
final Map<String, Object> paramMap = new HashMap<>();
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
paramMap.put("model", config.getModel());
|
paramMap.put("model", config.getModel());
|
||||||
paramMap.put("prompt", prompt);
|
paramMap.put("prompt", prompt);
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* grok公共类
|
* grok公共类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.BaseConfig;
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grok配置类,初始化API接口地址,设置默认的模型
|
* Grok配置类,初始化API接口地址,设置默认的模型
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Grok服务实现类
|
* 创建Grok服务实现类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.BaseAIService;
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hutool公共类
|
* hutool公共类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.BaseConfig;
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hutool配置类,初始化API接口地址,设置默认的模型
|
* Hutool配置类,初始化API接口地址,设置默认的模型
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
/**r
|
/**r
|
||||||
* 创建Hutool服务实现类
|
* 创建Hutool服务实现类
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIException;
|
import cn.hutool.v7.ai.AIException;
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.BaseAIService;
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ollama公共类
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
public class OllamaCommon {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ollama模型格式枚举
|
||||||
|
*/
|
||||||
|
public enum OllamaFormat {
|
||||||
|
/**
|
||||||
|
* JSON格式
|
||||||
|
*/
|
||||||
|
JSON("json"),
|
||||||
|
/**
|
||||||
|
* 无格式
|
||||||
|
*/
|
||||||
|
NONE("");
|
||||||
|
|
||||||
|
private final String format;
|
||||||
|
|
||||||
|
OllamaFormat(String format) {
|
||||||
|
this.format = format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ollama选项常量
|
||||||
|
*/
|
||||||
|
public static class Options {
|
||||||
|
/**
|
||||||
|
* 温度参数
|
||||||
|
*/
|
||||||
|
public static final String TEMPERATURE = "temperature";
|
||||||
|
/**
|
||||||
|
* top_p参数
|
||||||
|
*/
|
||||||
|
public static final String TOP_P = "top_p";
|
||||||
|
/**
|
||||||
|
* top_k参数
|
||||||
|
*/
|
||||||
|
public static final String TOP_K = "top_k";
|
||||||
|
/**
|
||||||
|
* 最大token数
|
||||||
|
*/
|
||||||
|
public static final String NUM_PREDICT = "num_predict";
|
||||||
|
/**
|
||||||
|
* 随机种子
|
||||||
|
*/
|
||||||
|
public static final String SEED = "seed";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,36 +14,42 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.BaseConfig;
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Doubao配置类,初始化API接口地址,设置默认的模型
|
* Ollama配置类,初始化API接口地址,设置默认的模型
|
||||||
*
|
*
|
||||||
* @author elichow
|
* @author yangruoyu-yumeisoft
|
||||||
* @since 6.0.0
|
* @since 5.8.40
|
||||||
*/
|
*/
|
||||||
public class DoubaoConfig extends BaseConfig {
|
public class OllamaConfig extends BaseConfig {
|
||||||
|
|
||||||
private final String API_URL = "https://ark.cn-beijing.volces.com/api/v3";
|
private final String API_URL = "http://localhost:11434";
|
||||||
|
|
||||||
private final String DEFAULT_MODEL = Models.Doubao.DOUBAO_1_5_LITE_32K.getModel();
|
private final String DEFAULT_MODEL = Models.Ollama.QWEN3_32B.getModel();
|
||||||
|
|
||||||
public DoubaoConfig() {
|
public OllamaConfig() {
|
||||||
setApiUrl(API_URL);
|
setApiUrl(API_URL);
|
||||||
setModel(DEFAULT_MODEL);
|
setModel(DEFAULT_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubaoConfig(String apiKey) {
|
public OllamaConfig(String apiUrl) {
|
||||||
this();
|
this();
|
||||||
setApiKey(apiKey);
|
setApiUrl(apiUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OllamaConfig(String apiUrl, String model) {
|
||||||
|
this();
|
||||||
|
setApiUrl(apiUrl);
|
||||||
|
setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelName() {
|
public String getModelName() {
|
||||||
return "doubao";
|
return "ollama";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建Ollama服务实现类
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
public class OllamaProvider implements AIServiceProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getServiceName() {
|
||||||
|
return "ollama";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OllamaService create(final AIConfig config) {
|
||||||
|
return new OllamaServiceImpl(config);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ollama特有的功能
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
public interface OllamaService extends AIService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文本补全
|
||||||
|
*
|
||||||
|
* @param prompt 输入提示
|
||||||
|
* @return AI回答
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String generate(String prompt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文本补全-SSE流式输出
|
||||||
|
*
|
||||||
|
* @param prompt 输入提示
|
||||||
|
* @param callback 流式数据回调函数
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
void generate(String prompt, Consumer<String> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文本补全(带选项)
|
||||||
|
*
|
||||||
|
* @param prompt 输入提示
|
||||||
|
* @param format 响应格式
|
||||||
|
* @return AI回答
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String generate(String prompt, String format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文本补全(带选项)-SSE流式输出
|
||||||
|
*
|
||||||
|
* @param prompt 输入提示
|
||||||
|
* @param format 响应格式
|
||||||
|
* @param callback 流式数据回调函数
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
void generate(String prompt, String format, Consumer<String> callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成文本嵌入向量
|
||||||
|
*
|
||||||
|
* @param prompt 输入文本
|
||||||
|
* @return 嵌入向量结果
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String embeddings(String prompt);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列出本地可用的模型
|
||||||
|
*
|
||||||
|
* @return 模型列表
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String listModels();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示模型信息
|
||||||
|
*
|
||||||
|
* @param modelName 模型名称
|
||||||
|
* @return 模型信息
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String showModel(String modelName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取模型
|
||||||
|
*
|
||||||
|
* @param modelName 模型名称
|
||||||
|
* @return 拉取结果
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String pullModel(String modelName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除模型
|
||||||
|
*
|
||||||
|
* @param modelName 模型名称
|
||||||
|
* @return 删除结果
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String deleteModel(String modelName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制模型
|
||||||
|
*
|
||||||
|
* @param source 源模型名称
|
||||||
|
* @param destination 目标模型名称
|
||||||
|
* @return 复制结果
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
String copyModel(String source, String destination);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 简化的对话方法
|
||||||
|
*
|
||||||
|
* @param prompt 对话题词
|
||||||
|
* @return AI回答
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
default String chat(String prompt) {
|
||||||
|
final List<Message> messages = new ArrayList<>();
|
||||||
|
messages.add(new Message("user", prompt));
|
||||||
|
return chat(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 简化的对话方法-SSE流式输出
|
||||||
|
*
|
||||||
|
* @param prompt 对话题词
|
||||||
|
* @param callback 流式数据回调函数
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
default void chat(String prompt, Consumer<String> callback) {
|
||||||
|
final List<Message> messages = new ArrayList<>();
|
||||||
|
messages.add(new Message("user", prompt));
|
||||||
|
chat(messages, callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
|
import cn.hutool.v7.ai.AIException;
|
||||||
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
import cn.hutool.v7.core.bean.path.BeanPath;
|
||||||
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
|
import cn.hutool.v7.http.client.Request;
|
||||||
|
import cn.hutool.v7.http.client.Response;
|
||||||
|
import cn.hutool.v7.http.meta.HeaderName;
|
||||||
|
import cn.hutool.v7.http.meta.Method;
|
||||||
|
import cn.hutool.v7.json.JSONObject;
|
||||||
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ollama服务,AI具体功能的实现
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
public class OllamaServiceImpl extends BaseAIService implements OllamaService {
|
||||||
|
|
||||||
|
// 对话补全
|
||||||
|
private static final String CHAT_ENDPOINT = "/api/chat";
|
||||||
|
// 文本生成
|
||||||
|
private static final String GENERATE_ENDPOINT = "/api/generate";
|
||||||
|
// 文本嵌入
|
||||||
|
private static final String EMBEDDINGS_ENDPOINT = "/api/embeddings";
|
||||||
|
// 列出模型
|
||||||
|
private static final String LIST_MODELS_ENDPOINT = "/api/tags";
|
||||||
|
// 显示模型信息
|
||||||
|
private static final String SHOW_MODEL_ENDPOINT = "/api/show";
|
||||||
|
// 拉取模型
|
||||||
|
private static final String PULL_MODEL_ENDPOINT = "/api/pull";
|
||||||
|
// 删除模型
|
||||||
|
private static final String DELETE_MODEL_ENDPOINT = "/api/delete";
|
||||||
|
// 复制模型
|
||||||
|
private static final String COPY_MODEL_ENDPOINT = "/api/copy";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造函数
|
||||||
|
*
|
||||||
|
* @param config AI配置
|
||||||
|
*/
|
||||||
|
public OllamaServiceImpl(final AIConfig config) {
|
||||||
|
super(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String chat(final List<Message> messages) {
|
||||||
|
final String paramJson = buildChatRequestBody(messages);
|
||||||
|
final Response response = sendPost(CHAT_ENDPOINT, paramJson);
|
||||||
|
final JSONObject responseJson = JSONUtil.parseObj(response.body());
|
||||||
|
final Object errorMessage = BeanPath.of("error").getValue(responseJson);
|
||||||
|
if(errorMessage!=null){
|
||||||
|
throw new RuntimeException(errorMessage.toString());
|
||||||
|
}
|
||||||
|
return BeanPath.of("message.content").getValue(responseJson).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void chat(final List<Message> messages, final Consumer<String> callback) {
|
||||||
|
final Map<String, Object> paramMap = buildChatStreamRequestBody(messages);
|
||||||
|
ThreadUtil.newThread(() -> sendPostStream(CHAT_ENDPOINT, paramMap, callback::accept), "ollama-chat-sse").start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generate(final String prompt) {
|
||||||
|
final String paramJson = buildGenerateRequestBody(prompt, null);
|
||||||
|
final Response response = sendPost(GENERATE_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(final String prompt, final Consumer<String> callback) {
|
||||||
|
final Map<String, Object> paramMap = buildGenerateStreamRequestBody(prompt, null);
|
||||||
|
ThreadUtil.newThread(() -> sendPostStream(GENERATE_ENDPOINT, paramMap, callback::accept), "ollama-generate-sse").start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generate(final String prompt, final String format) {
|
||||||
|
final String paramJson = buildGenerateRequestBody(prompt, format);
|
||||||
|
final Response response = sendPost(GENERATE_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generate(final String prompt, final String format, final Consumer<String> callback) {
|
||||||
|
final Map<String, Object> paramMap = buildGenerateStreamRequestBody(prompt, format);
|
||||||
|
ThreadUtil.newThread(() -> sendPostStream(GENERATE_ENDPOINT, paramMap, callback::accept), "ollama-generate-sse").start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String embeddings(final String prompt) {
|
||||||
|
final String paramJson = buildEmbeddingsRequestBody(prompt);
|
||||||
|
final Response response = sendPost(EMBEDDINGS_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String listModels() {
|
||||||
|
final Response response = sendGet(LIST_MODELS_ENDPOINT);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String showModel(final String modelName) {
|
||||||
|
final String paramJson = buildShowModelRequestBody(modelName);
|
||||||
|
final Response response = sendPost(SHOW_MODEL_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String pullModel(final String modelName) {
|
||||||
|
final String paramJson = buildPullModelRequestBody(modelName);
|
||||||
|
final Response response = sendPost(PULL_MODEL_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String deleteModel(final String modelName) {
|
||||||
|
final String paramJson = buildDeleteModelRequestBody(modelName);
|
||||||
|
final Response response = sendDeleteRequest(DELETE_MODEL_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String copyModel(final String source, final String destination) {
|
||||||
|
final String paramJson = buildCopyModelRequestBody(source, destination);
|
||||||
|
final Response response = sendPost(COPY_MODEL_ENDPOINT, paramJson);
|
||||||
|
return response.bodyStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建chat请求体
|
||||||
|
private String buildChatRequestBody(final List<Message> messages) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("stream",false);
|
||||||
|
paramMap.put("model", config.getModel());
|
||||||
|
paramMap.put("messages", messages);
|
||||||
|
// 合并其他参数
|
||||||
|
paramMap.putAll(config.getAdditionalConfigMap());
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建chatStream请求体
|
||||||
|
private Map<String, Object> buildChatStreamRequestBody(final List<Message> messages) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("stream", true);
|
||||||
|
paramMap.put("model", config.getModel());
|
||||||
|
paramMap.put("messages", messages);
|
||||||
|
// 合并其他参数
|
||||||
|
paramMap.putAll(config.getAdditionalConfigMap());
|
||||||
|
|
||||||
|
return paramMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建generate请求体
|
||||||
|
private String buildGenerateRequestBody(final String prompt, final String format) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("model", config.getModel());
|
||||||
|
paramMap.put("prompt", prompt);
|
||||||
|
if (StrUtil.isNotBlank(format)) {
|
||||||
|
paramMap.put("format", format);
|
||||||
|
}
|
||||||
|
// 合并其他参数
|
||||||
|
paramMap.putAll(config.getAdditionalConfigMap());
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建generateStream请求体
|
||||||
|
private Map<String, Object> buildGenerateStreamRequestBody(final String prompt, final String format) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("stream", true);
|
||||||
|
paramMap.put("model", config.getModel());
|
||||||
|
paramMap.put("prompt", prompt);
|
||||||
|
if (StrUtil.isNotBlank(format)) {
|
||||||
|
paramMap.put("format", format);
|
||||||
|
}
|
||||||
|
// 合并其他参数
|
||||||
|
paramMap.putAll(config.getAdditionalConfigMap());
|
||||||
|
|
||||||
|
return paramMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建embeddings请求体
|
||||||
|
private String buildEmbeddingsRequestBody(final String prompt) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("model", config.getModel());
|
||||||
|
paramMap.put("prompt", prompt);
|
||||||
|
// 合并其他参数
|
||||||
|
paramMap.putAll(config.getAdditionalConfigMap());
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建showModel请求体
|
||||||
|
private String buildShowModelRequestBody(final String modelName) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("name", modelName);
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建pullModel请求体
|
||||||
|
private String buildPullModelRequestBody(final String modelName) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("name", modelName);
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建deleteModel请求体
|
||||||
|
private String buildDeleteModelRequestBody(final String modelName) {
|
||||||
|
final Map<String, Object> paramMap = new HashMap<>();
|
||||||
|
paramMap.put("name", modelName);
|
||||||
|
|
||||||
|
return JSONUtil.toJsonStr(paramMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送DELETE请求
|
||||||
|
*
|
||||||
|
* @param endpoint 请求端点
|
||||||
|
* @param paramJson 请求参数JSON
|
||||||
|
* @return 响应结果
|
||||||
|
*/
|
||||||
|
private Response sendDeleteRequest(final String endpoint, final String paramJson) {
|
||||||
|
try {
|
||||||
|
return Request.of(config.getApiUrl() + endpoint)
|
||||||
|
.method(Method.DELETE)
|
||||||
|
.header(HeaderName.CONTENT_TYPE, "application/json")
|
||||||
|
.header(HeaderName.ACCEPT, "application/json")
|
||||||
|
.body(paramJson)
|
||||||
|
.send();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
throw new AIException("Failed to send DELETE request: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建copyModel请求体
|
||||||
|
private String buildCopyModelRequestBody(final String source, final String destination) {
|
||||||
|
final Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
requestBody.put("source", source);
|
||||||
|
requestBody.put("destination", destination);
|
||||||
|
return JSONUtil.toJsonStr(requestBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对Ollama的封装实现.
|
||||||
|
* <p>
|
||||||
|
* 使用方法:
|
||||||
|
* // 创建AI服务
|
||||||
|
* <pre>{@code
|
||||||
|
* OllamaService aiService = AIServiceFactory.getAIService(
|
||||||
|
* new AIConfigBuilder(ModelName.OLLAMA.getValue())
|
||||||
|
* .setApiUrl("http://localhost:11434")
|
||||||
|
* .setModel("qwen2.5-coder:32b")
|
||||||
|
* .build(),
|
||||||
|
* OllamaService.class
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* // 构造上下文
|
||||||
|
* List<Message> messageList=new ArrayList<>();
|
||||||
|
* messageList.add(new Message("system","你是一个疯疯癫癫的机器人"));
|
||||||
|
* messageList.add(new Message("user","你能帮我做什么"));
|
||||||
|
*
|
||||||
|
* // 输出对话结果
|
||||||
|
* System.out.println(aiService.chat(messageList));
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* openai公共类
|
* openai公共类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.BaseConfig;
|
import cn.hutool.v7.ai.core.BaseConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* openai配置类,初始化API接口地址,设置默认的模型
|
* openai配置类,初始化API接口地址,设置默认的模型
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.AIServiceProvider;
|
import cn.hutool.v7.ai.core.AIServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建Openai服务实现类
|
* 创建Openai服务实现类
|
||||||
@@ -14,10 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfig;
|
import cn.hutool.v7.ai.core.AIConfig;
|
||||||
import org.dromara.hutool.ai.core.BaseAIService;
|
import cn.hutool.v7.ai.core.BaseAIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.http.client.Response;
|
import cn.hutool.v7.http.client.Response;
|
||||||
import org.dromara.hutool.json.JSONUtil;
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model;
|
package cn.hutool.v7.ai.model;
|
||||||
@@ -21,4 +21,4 @@
|
|||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
cn.hutool.v7.ai.model.hutool.HutoolConfig
|
||||||
|
cn.hutool.v7.ai.model.deepseek.DeepSeekConfig
|
||||||
|
cn.hutool.v7.ai.model.openai.OpenaiConfig
|
||||||
|
cn.hutool.v7.ai.model.doubao.DoubaoConfig
|
||||||
|
cn.hutool.v7.ai.model.grok.GrokConfig
|
||||||
|
cn.hutool.v7.ai.model.ollama.OllamaConfig
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
cn.hutool.v7.ai.model.hutool.HutoolProvider
|
||||||
|
cn.hutool.v7.ai.model.deepseek.DeepSeekProvider
|
||||||
|
cn.hutool.v7.ai.model.openai.OpenaiProvider
|
||||||
|
cn.hutool.v7.ai.model.doubao.DoubaoProvider
|
||||||
|
cn.hutool.v7.ai.model.grok.GrokProvider
|
||||||
|
cn.hutool.v7.ai.model.ollama.OllamaProvider
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
org.dromara.hutool.ai.model.hutool.HutoolConfig
|
|
||||||
org.dromara.hutool.ai.model.deepseek.DeepSeekConfig
|
|
||||||
org.dromara.hutool.ai.model.openai.OpenaiConfig
|
|
||||||
org.dromara.hutool.ai.model.doubao.DoubaoConfig
|
|
||||||
org.dromara.hutool.ai.model.grok.GrokConfig
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
org.dromara.hutool.ai.model.hutool.HutoolProvider
|
|
||||||
org.dromara.hutool.ai.model.deepseek.DeepSeekProvider
|
|
||||||
org.dromara.hutool.ai.model.openai.OpenaiProvider
|
|
||||||
org.dromara.hutool.ai.model.doubao.DoubaoProvider
|
|
||||||
org.dromara.hutool.ai.model.grok.GrokProvider
|
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.model.deepseek.DeepSeekService;
|
import cn.hutool.v7.ai.model.deepseek.DeepSeekService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai;
|
package cn.hutool.v7.ai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.AIService;
|
import cn.hutool.v7.ai.core.AIService;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.ai.model.deepseek.DeepSeekService;
|
import cn.hutool.v7.ai.model.deepseek.DeepSeekService;
|
||||||
import org.dromara.hutool.ai.model.doubao.DoubaoService;
|
import cn.hutool.v7.ai.model.doubao.DoubaoService;
|
||||||
import org.dromara.hutool.ai.model.grok.GrokService;
|
import cn.hutool.v7.ai.model.grok.GrokService;
|
||||||
import org.dromara.hutool.ai.model.hutool.HutoolService;
|
import cn.hutool.v7.ai.model.hutool.HutoolService;
|
||||||
import org.dromara.hutool.ai.model.openai.OpenaiService;
|
import cn.hutool.v7.ai.model.openai.OpenaiService;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -14,13 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.deepseek;
|
package cn.hutool.v7.ai.model.deepseek;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIServiceFactory;
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
import org.dromara.hutool.ai.ModelName;
|
import cn.hutool.v7.ai.ModelName;
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.doubao;
|
package cn.hutool.v7.ai.model.doubao;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIServiceFactory;
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
import org.dromara.hutool.ai.ModelName;
|
import cn.hutool.v7.ai.ModelName;
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.swing.img.ImgUtil;
|
import cn.hutool.v7.swing.img.ImgUtil;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.grok;
|
package cn.hutool.v7.ai.model.grok;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIServiceFactory;
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
import org.dromara.hutool.ai.ModelName;
|
import cn.hutool.v7.ai.ModelName;
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.swing.img.ImgUtil;
|
import cn.hutool.v7.swing.img.ImgUtil;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.hutool;
|
package cn.hutool.v7.ai.model.hutool;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIException;
|
import cn.hutool.v7.ai.AIException;
|
||||||
import org.dromara.hutool.ai.AIServiceFactory;
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
import org.dromara.hutool.ai.ModelName;
|
import cn.hutool.v7.ai.ModelName;
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.io.file.FileUtil;
|
import cn.hutool.v7.core.io.file.FileUtil;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.dromara.hutool.swing.img.ImgUtil;
|
import cn.hutool.v7.swing.img.ImgUtil;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2025 Hutool Team and hutool.cn
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package cn.hutool.v7.ai.model.ollama;
|
||||||
|
|
||||||
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
|
import cn.hutool.v7.ai.ModelName;
|
||||||
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
|
import cn.hutool.v7.ai.core.Message;
|
||||||
|
import cn.hutool.v7.core.text.split.SplitUtil;
|
||||||
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
|
import cn.hutool.v7.json.JSON;
|
||||||
|
import cn.hutool.v7.json.JSONArray;
|
||||||
|
import cn.hutool.v7.json.JSONUtil;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OllamaService
|
||||||
|
*
|
||||||
|
* @author yangruoyu-yumeisoft
|
||||||
|
* @since 5.8.40
|
||||||
|
*/
|
||||||
|
class OllamaServiceTest {
|
||||||
|
// 创建service
|
||||||
|
OllamaService ollamaService = AIServiceFactory.getAIService(
|
||||||
|
new AIConfigBuilder(ModelName.OLLAMA.getValue())
|
||||||
|
// 这里填写Ollama服务的地址
|
||||||
|
.setApiUrl("http://127.0.0.1:11434")
|
||||||
|
// 这里填写使用的模型
|
||||||
|
.setModel("qwen2.5-coder:32b")
|
||||||
|
.build(),
|
||||||
|
OllamaService.class
|
||||||
|
);
|
||||||
|
|
||||||
|
// 假设有一个Java工程师的Agent提示词
|
||||||
|
String javaEngineerPrompt= """
|
||||||
|
# 角色
|
||||||
|
你是一位精通Spring Boot 3.0的资深Java全栈工程师,具备以下核心能力:
|
||||||
|
- 精通Spring Boot 3.0新特性与最佳实践
|
||||||
|
- 熟练整合Hutool工具包、Redis数据访问、Feign远程调用、FreeMarker模板引擎
|
||||||
|
- 能输出符合工程规范的代码结构和配置文件
|
||||||
|
- 注重代码可读性与注释规范
|
||||||
|
|
||||||
|
# 任务
|
||||||
|
请完成以下编程任务(按优先级排序):
|
||||||
|
1. **核心要求**
|
||||||
|
- 使用Spring Boot 3.0构建项目
|
||||||
|
- 必须包含以下依赖:
|
||||||
|
- `cn.hutool:hutool-all`(最新版)
|
||||||
|
- `org.springframework.boot:spring-boot-starter-data-redis`
|
||||||
|
- `org.springframework.cloud:spring-cloud-starter-openfeign`
|
||||||
|
- `org.springframework.boot:spring-boot-starter-freemarker`
|
||||||
|
2. **约束条件**
|
||||||
|
- 代码需符合Java 17语法规范
|
||||||
|
- 每个类必须包含Javadoc风格的类注释
|
||||||
|
- 关键方法需添加`@Api`/`@ApiOperation`注解(若涉及接口)
|
||||||
|
- Redis操作需使用`RedisTemplate`实现
|
||||||
|
3. **实现流程**
|
||||||
|
```
|
||||||
|
1. 生成pom.xml依赖配置
|
||||||
|
2. 创建基础配置类(如RedisConfig)
|
||||||
|
3. 编写Feign客户端接口
|
||||||
|
4. 实现FreeMarker模板渲染服务
|
||||||
|
5. 提供完整Controller示例
|
||||||
|
```
|
||||||
|
|
||||||
|
# 输出要求
|
||||||
|
请以严格Markdown格式输出,每个模块独立代码块:
|
||||||
|
```markdown
|
||||||
|
## 1. 项目依赖配置(pom.xml片段)
|
||||||
|
```xml
|
||||||
|
<dependency>...</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Redis配置类
|
||||||
|
```java
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. Feign客户端示例
|
||||||
|
```java
|
||||||
|
@FeignClient(name = "...")
|
||||||
|
public interface ... { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
## 4. FreeMarker模板服务
|
||||||
|
```java
|
||||||
|
@Service
|
||||||
|
public class TemplateService { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
## 5. 控制器示例
|
||||||
|
```java
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/example")
|
||||||
|
public class ExampleController { ... }
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
||||||
|
# 示例片段(供格式参考)
|
||||||
|
```java
|
||||||
|
/**
|
||||||
|
* 示例Feign客户端
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
@FeignClient(name = "demo-service", url = "${demo.service.url}")
|
||||||
|
public interface DemoClient {
|
||||||
|
|
||||||
|
@GetMapping("/data/{id}")
|
||||||
|
@ApiOperation("获取示例数据")
|
||||||
|
ResponseEntity<String> getData(@PathVariable("id") Long id);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
请按此规范输出完整代码结构,确保自动化程序可直接解析生成项目文件。""";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步方式调用
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testSimple() {
|
||||||
|
final String answer = ollamaService.chat("写一个疯狂星期四广告词");
|
||||||
|
assertNotNull(answer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按流方式输出
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testStream() {
|
||||||
|
final AtomicBoolean isDone = new AtomicBoolean(false);
|
||||||
|
final AtomicReference<String> errorMessage = new AtomicReference<>();
|
||||||
|
ollamaService.chat("写一个疯狂星期四广告词", data -> {
|
||||||
|
// 输出到控制台
|
||||||
|
final JSON streamData = JSONUtil.parse(data);
|
||||||
|
if (streamData.getByPath("error") != null) {
|
||||||
|
isDone.set(true);
|
||||||
|
errorMessage.set(streamData.getByPath("error").toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("true".equals(streamData.getByPath("done").toString())) {
|
||||||
|
isDone.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 轮询检查结束标志
|
||||||
|
while (!isDone.get()) {
|
||||||
|
ThreadUtil.sleep(100);
|
||||||
|
}
|
||||||
|
if (errorMessage.get() != null) {
|
||||||
|
throw new RuntimeException(errorMessage.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带历史上下文的同步方式调用
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testSimpleWithHistory(){
|
||||||
|
final List<Message> messageList=new ArrayList<>();
|
||||||
|
messageList.add(new Message("system",javaEngineerPrompt));
|
||||||
|
messageList.add(new Message("user","帮我写一个Java通过Post方式发送JSON给HTTP接口,请求头带有token"));
|
||||||
|
final String result = ollamaService.chat(messageList);
|
||||||
|
assertNotNull(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testStreamWithHistory(){
|
||||||
|
final List<Message> messageList=new ArrayList<>();
|
||||||
|
messageList.add(new Message("system",javaEngineerPrompt));
|
||||||
|
messageList.add(new Message("user","帮我写一个Java通过Post方式发送JSON给HTTP接口,请求头带有token"));
|
||||||
|
final AtomicBoolean isDone = new AtomicBoolean(false);
|
||||||
|
final AtomicReference<String> errorMessage = new AtomicReference<>();
|
||||||
|
ollamaService.chat(messageList, data -> {
|
||||||
|
// 输出到控制台
|
||||||
|
final JSON streamData = JSONUtil.parse(data);
|
||||||
|
if (streamData.getByPath("error") != null) {
|
||||||
|
isDone.set(true);
|
||||||
|
errorMessage.set(streamData.getByPath("error").toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("true".equals(streamData.getByPath("done").toString())) {
|
||||||
|
isDone.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 轮询检查结束标志
|
||||||
|
while (!isDone.get()) {
|
||||||
|
ThreadUtil.sleep(100);
|
||||||
|
}
|
||||||
|
if (errorMessage.get() != null) {
|
||||||
|
throw new RuntimeException(errorMessage.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列出所有已经拉取到服务器上的模型
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testListModels(){
|
||||||
|
final String models = ollamaService.listModels();
|
||||||
|
final JSONArray modelList = JSONUtil.parse(models).getByPath("models", JSONArray.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 让Ollama拉取模型
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testPullModel(){
|
||||||
|
final String result = ollamaService.pullModel("qwen2.5:0.5b");
|
||||||
|
final List<String> lines = SplitUtil.splitTrim(result, "\n");
|
||||||
|
for (final String line : lines) {
|
||||||
|
if(line.contains("error")){
|
||||||
|
throw new RuntimeException(JSONUtil.parse(line).getByPath("error").toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 让Ollama删除已经存在的模型
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
|
void testDeleteModel(){
|
||||||
|
// 不会返回任何信息
|
||||||
|
ollamaService.deleteModel("qwen2.5:0.5b");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.ai.model.openai;
|
package cn.hutool.v7.ai.model.openai;
|
||||||
|
|
||||||
import org.dromara.hutool.ai.AIServiceFactory;
|
import cn.hutool.v7.ai.AIServiceFactory;
|
||||||
import org.dromara.hutool.ai.ModelName;
|
import cn.hutool.v7.ai.ModelName;
|
||||||
import org.dromara.hutool.ai.Models;
|
import cn.hutool.v7.ai.Models;
|
||||||
import org.dromara.hutool.ai.core.AIConfigBuilder;
|
import cn.hutool.v7.ai.core.AIConfigBuilder;
|
||||||
import org.dromara.hutool.ai.core.Message;
|
import cn.hutool.v7.ai.core.Message;
|
||||||
import org.dromara.hutool.core.io.file.FileUtil;
|
import cn.hutool.v7.core.io.file.FileUtil;
|
||||||
import org.dromara.hutool.core.thread.ThreadUtil;
|
import cn.hutool.v7.core.thread.ThreadUtil;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -23,9 +23,9 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-parent</artifactId>
|
<artifactId>hutool-parent</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<description>
|
<description>
|
||||||
Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、HTTP客户端等一系列操作,可以满足各种不同的开发需求。
|
Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、HTTP客户端等一系列操作,可以满足各种不同的开发需求。
|
||||||
</description>
|
</description>
|
||||||
<url>https://github.com/dromara/hutool</url>
|
<url>https://github.com/chinabugotech/hutool</url>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool;
|
package cn.hutool.v7;
|
||||||
|
|
||||||
import org.dromara.hutool.core.lang.ConsoleTable;
|
import cn.hutool.v7.core.lang.ConsoleTable;
|
||||||
import org.dromara.hutool.core.reflect.ClassUtil;
|
import cn.hutool.v7.core.reflect.ClassUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class Hutool {
|
|||||||
* @since 5.5.2
|
* @since 5.5.2
|
||||||
*/
|
*/
|
||||||
public static Set<Class<?>> getAllUtils() {
|
public static Set<Class<?>> getAllUtils() {
|
||||||
return ClassUtil.scanPackage("org.dromara.hutool",
|
return ClassUtil.scanPackage("cn.hutool.v7",
|
||||||
(clazz) -> (!clazz.isInterface()) && StrUtil.endWith(clazz.getSimpleName(), "Util"));
|
(clazz) -> (!clazz.isInterface()) && StrUtil.endWith(clazz.getSimpleName(), "Util"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,4 +23,4 @@
|
|||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
package org.dromara.hutool;
|
package cn.hutool.v7;
|
||||||
@@ -23,15 +23,15 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-parent</artifactId>
|
<artifactId>hutool-parent</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>hutool-bom</artifactId>
|
<artifactId>hutool-bom</artifactId>
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>提供丰富的Java工具方法,此模块为Hutool所有模块汇总,最终形式为拆分开的多个jar包,可以通过exclude方式排除不需要的模块</description>
|
<description>提供丰富的Java工具方法,此模块为Hutool所有模块汇总,最终形式为拆分开的多个jar包,可以通过exclude方式排除不需要的模块</description>
|
||||||
<url>https://github.com/dromara/hutool</url>
|
<url>https://github.com/chinabugotech/hutool</url>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.dromara.hutool</groupId>
|
<groupId>cn.hutool.v7</groupId>
|
||||||
<artifactId>hutool-parent</artifactId>
|
<artifactId>hutool-parent</artifactId>
|
||||||
<version>6.0.0-M23</version>
|
<version>7.0.0-M2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>hutool-core</artifactId>
|
<artifactId>hutool-core</artifactId>
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<description>Hutool核心,包括集合、字符串、Bean等工具</description>
|
<description>Hutool核心,包括集合、字符串、Bean等工具</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<Automatic-Module-Name>org.dromara.hutool.core</Automatic-Module-Name>
|
<Automatic-Module-Name>cn.hutool.v7.core</Automatic-Module-Name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.elements.HierarchicalAnnotatedElements;
|
import cn.hutool.v7.core.annotation.elements.HierarchicalAnnotatedElements;
|
||||||
import org.dromara.hutool.core.annotation.elements.MetaAnnotatedElement;
|
import cn.hutool.v7.core.annotation.elements.MetaAnnotatedElement;
|
||||||
import org.dromara.hutool.core.annotation.elements.RepeatableMetaAnnotatedElement;
|
import cn.hutool.v7.core.annotation.elements.RepeatableMetaAnnotatedElement;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
|
import cn.hutool.v7.core.map.reference.WeakConcurrentMap;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import cn.hutool.v7.core.util.ObjUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.Inherited;
|
import java.lang.annotation.Inherited;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -14,11 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.map.concurrent.SafeConcurrentHashMap;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
@@ -28,6 +27,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -96,7 +96,7 @@ public final class AnnotationMappingProxy<T extends Annotation> implements Invoc
|
|||||||
private AnnotationMappingProxy(final AnnotationMapping<T> annotation) {
|
private AnnotationMappingProxy(final AnnotationMapping<T> annotation) {
|
||||||
final int methodCount = annotation.getAttributes().length;
|
final int methodCount = annotation.getAttributes().length;
|
||||||
this.methods = new HashMap<>(methodCount + 5);
|
this.methods = new HashMap<>(methodCount + 5);
|
||||||
this.valueCache = new SafeConcurrentHashMap<>(methodCount);
|
this.valueCache = new ConcurrentHashMap<>(methodCount);
|
||||||
this.mapping = annotation;
|
this.mapping = annotation;
|
||||||
loadMethods();
|
loadMethods();
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationHandler;
|
import java.lang.reflect.InvocationHandler;
|
||||||
@@ -34,6 +35,7 @@ import java.util.Map;
|
|||||||
* @since 5.7.23
|
* @since 5.7.23
|
||||||
*/
|
*/
|
||||||
public class AnnotationProxy<T extends Annotation> implements Annotation, InvocationHandler, Serializable {
|
public class AnnotationProxy<T extends Annotation> implements Annotation, InvocationHandler, Serializable {
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,21 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.elements.CombinationAnnotatedElement;
|
import cn.hutool.v7.core.annotation.elements.CombinationAnnotatedElement;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.classloader.ClassLoaderUtil;
|
import cn.hutool.v7.core.classloader.ClassLoaderUtil;
|
||||||
import org.dromara.hutool.core.exception.HutoolException;
|
import cn.hutool.v7.core.exception.HutoolException;
|
||||||
import org.dromara.hutool.core.func.LambdaInfo;
|
import cn.hutool.v7.core.func.LambdaInfo;
|
||||||
import org.dromara.hutool.core.func.LambdaUtil;
|
import cn.hutool.v7.core.func.LambdaUtil;
|
||||||
import org.dromara.hutool.core.func.SerFunction;
|
import cn.hutool.v7.core.func.SerFunction;
|
||||||
import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
|
import cn.hutool.v7.core.map.reference.WeakConcurrentMap;
|
||||||
import org.dromara.hutool.core.reflect.FieldUtil;
|
import cn.hutool.v7.core.reflect.FieldUtil;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.text.StrUtil;
|
import cn.hutool.v7.core.text.StrUtil;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import cn.hutool.v7.core.util.ObjUtil;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.reflect.ClassUtil;
|
import cn.hutool.v7.core.reflect.ClassUtil;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@@ -14,13 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import cn.hutool.v7.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.map.reference.WeakConcurrentMap;
|
import cn.hutool.v7.core.map.reference.WeakConcurrentMap;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.Repeatable;
|
import java.lang.annotation.Repeatable;
|
||||||
@@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.elements.MetaAnnotatedElement;
|
import cn.hutool.v7.core.annotation.elements.MetaAnnotatedElement;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import cn.hutool.v7.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.lang.Assert;
|
import cn.hutool.v7.core.lang.Assert;
|
||||||
import org.dromara.hutool.core.map.multi.Graph;
|
import cn.hutool.v7.core.map.multi.Graph;
|
||||||
import org.dromara.hutool.core.reflect.ClassUtil;
|
import cn.hutool.v7.core.reflect.ClassUtil;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
@@ -14,12 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation.elements;
|
package cn.hutool.v7.core.annotation.elements;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.v7.core.annotation.AnnotationUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.collection.set.SetUtil;
|
import cn.hutool.v7.core.collection.set.SetUtil;
|
||||||
import org.dromara.hutool.core.map.TableMap;
|
import cn.hutool.v7.core.map.TableMap;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation.elements;
|
package cn.hutool.v7.core.annotation.elements;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.v7.core.annotation.AnnotationUtil;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import cn.hutool.v7.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.collection.set.SetUtil;
|
import cn.hutool.v7.core.collection.set.SetUtil;
|
||||||
import org.dromara.hutool.core.reflect.ClassUtil;
|
import cn.hutool.v7.core.reflect.ClassUtil;
|
||||||
import org.dromara.hutool.core.reflect.method.MethodUtil;
|
import cn.hutool.v7.core.reflect.method.MethodUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation.elements;
|
package cn.hutool.v7.core.annotation.elements;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.AnnotationMapping;
|
import cn.hutool.v7.core.annotation.AnnotationMapping;
|
||||||
import org.dromara.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.v7.core.annotation.AnnotationUtil;
|
||||||
import org.dromara.hutool.core.annotation.ResolvedAnnotationMapping;
|
import cn.hutool.v7.core.annotation.ResolvedAnnotationMapping;
|
||||||
import org.dromara.hutool.core.stream.EasyStream;
|
import cn.hutool.v7.core.stream.EasyStream;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
import org.dromara.hutool.core.util.ObjUtil;
|
import cn.hutool.v7.core.util.ObjUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.Inherited;
|
import java.lang.annotation.Inherited;
|
||||||
@@ -14,14 +14,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.dromara.hutool.core.annotation.elements;
|
package cn.hutool.v7.core.annotation.elements;
|
||||||
|
|
||||||
import org.dromara.hutool.core.annotation.AnnotationMapping;
|
import cn.hutool.v7.core.annotation.AnnotationMapping;
|
||||||
import org.dromara.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.v7.core.annotation.AnnotationUtil;
|
||||||
import org.dromara.hutool.core.annotation.RepeatableAnnotationCollector;
|
import cn.hutool.v7.core.annotation.RepeatableAnnotationCollector;
|
||||||
import org.dromara.hutool.core.collection.CollUtil;
|
import cn.hutool.v7.core.collection.CollUtil;
|
||||||
import org.dromara.hutool.core.text.CharSequenceUtil;
|
import cn.hutool.v7.core.text.CharSequenceUtil;
|
||||||
import org.dromara.hutool.core.array.ArrayUtil;
|
import cn.hutool.v7.core.array.ArrayUtil;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
@@ -19,4 +19,4 @@
|
|||||||
*
|
*
|
||||||
* @author Looly, huangchengxing
|
* @author Looly, huangchengxing
|
||||||
*/
|
*/
|
||||||
package org.dromara.hutool.core.annotation.elements;
|
package cn.hutool.v7.core.annotation.elements;
|
||||||
@@ -26,4 +26,4 @@
|
|||||||
* @author Looly
|
* @author Looly
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.dromara.hutool.core.annotation;
|
package cn.hutool.v7.core.annotation;
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user