diff --git a/.github/ISSUE_TEMPLATE/suggest.md b/.github/ISSUE_TEMPLATE/suggest.md index 2e869ab58..075e393ab 100644 --- a/.github/ISSUE_TEMPLATE/suggest.md +++ b/.github/ISSUE_TEMPLATE/suggest.md @@ -1,6 +1,6 @@ --- name: "💌 Suggest" about: suggest template -title: '建议: ' +title: 'suggest: ' labels: 'suggest' ---- \ No newline at end of file +--- diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61b492976..cca88c92a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,6 +62,7 @@ jobs: java-version: "17" distribution: "temurin" java-package: "jre" + architecture: "x64" # Install jre MacOS arm64 - name: Install Jre MacOS arm64 @@ -86,7 +87,7 @@ jobs: - name: Enable tls1 if: ${{ runner.os == 'Windows' }} run: | - # sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\( TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "${{ env.JAVA_HOME }}/conf/security/java.security" + # sed -i '' "s/\(^jdk.tls.disabledAlgorithms=\)\(.*\)\( TLSv1, TLSv1.1,\)\(.*\)/\1\2\4/" "${{ env.JAVA_HOME }}\conf\security\java.security" $filePath = "${{ env.JAVA_HOME }}\conf\security\java.security" $content = Get-Content $filePath -Raw $updatedContent = $content -replace '^(jdk.tls.disabledAlgorithms=)(.*)( TLSv1, TLSv1.1,)(.*)', '$1$2$4' @@ -210,7 +211,7 @@ jobs: run: | xcrun notarytool store-credentials "Chat2DB" --apple-id "${{secrets.MAC_APPLE_ID}}" --password "${{secrets.MAC_APPLE_PASSWORD}}" --team-id "${{secrets.MAC_TEAM_ID}}" xcrun notarytool submit chat2db-client/release/Chat2DB-${{ steps.chat2db_version.outputs.substring }}.dmg --keychain-profile "Chat2DB" - + # macos arm64 - name: Build/release Electron app for MacOS arm64 if: ${{ runner.os == 'macOS' && matrix.arch == 'arm64' }} @@ -346,4 +347,4 @@ jobs: { "title": "Linux-test-打包完成通知", "text": "# Linux-test-打包完成通知 \n ![bang](https://oss.sqlgpt.cn/static/happy100.jpg) \n ### 任务id:[${{ github.run_id }}](https://github.com/chat2db/Chat2DB/actions/runs/${{ github.run_id }}) \n ### Linux下载地址:[https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}.AppImage](https://oss.sqlgpt.cn/release/${{ steps.chat2db_version.outputs.substring }}/Chat2DB-${{ steps.chat2db_version.outputs.substring }}.AppImage)" - } + } \ No newline at end of file diff --git a/Chat2DB_LICENSE b/Chat2DB_LICENSE index fe37e14f8..cb817b0f4 100644 --- a/Chat2DB_LICENSE +++ b/Chat2DB_LICENSE @@ -16,8 +16,6 @@ The Chat2DB License 您不得出于任何商业、军事或非法目的使用、复制、修改、合并、发布、分发、复制或创建本软件的全部或部分衍生作品。 -您不得利用本软件从事任何危害国家安全和国家统一、危害社会公共利益、侵犯人身权益的行为。 - 4.免责声明 本软件“按原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、特定用途的适用性和非侵权性的保证。 在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,无论是在合同诉讼、侵权行为还是其他方面,由软件或软件的使用或其他交易引起、由软件引起或与之相关 软件。 @@ -49,8 +47,6 @@ The above copyright notice and this permission notice shall be included in all c You will not use, copy, modify, merge, publish, distribute, reproduce, or create derivative works of the Software, in whole or in part, for any commercial, military, or illegal purposes. -You will not use the Software for any act that may undermine China's national security and national unity, harm the public interest of society, or infringe upon the rights and interests of human beings. - 4. Disclaimer THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 0e5565753..81402a844 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,299 @@ -# Chat2DB -Coming soon on 10.25 for offline version, please get notified on Product Hunt! -Chat2DB Local - Make everyone a database expert and data analyst. | Product Hunt +
+ CodePhiliaX%2FChat2DB | Trendshift +
+
+

+ + chat on Discord + +Share on Telegram + +Share on Reddit + -**English** | [中文](README_CN.md)· 🏆 Top 100 Open Project! - -## Download and Install Chat2DB(Pro) - -[Download](https://chat2db.ai/download) -Double click package to install - -#### AI-driven intelligent SQL development - - Chat2DB - - - Chat2DB - - -Chat2DB - - -#### AI-driven Intelligent Reports - - Chat2DB - - -#### AI-driven Data Exploration - -Chat2DB - - -### We have also open-sourced our first GLM, [Chat2DB-SQL-7B](https://github.com/chat2db/Chat2DB-GLM). You can refer more details from below links. - -- github: [Chat2DB-SQL-7B](https://github.com/chat2db/Chat2DB-GLM) -- huggingface🤗:[Chat2DB-SQL-7B](https://huggingface.co/Chat2DB/Chat2DB-SQL-7B) -- modelscope:[Chat2DB-SQL-7B](https://modelscope.cn/models/Chat2DB/Chat2DB-SQL-7B/summary) - -### Deploy the InternLM model on Chat2DB - -Thanks to [InternLM](https://github.com/InternLM/InternLM) for the strong support for this project. In the custom models of this project, multiple model weights from InternLM can be integrated. For more details, please refer to [chat2db-internlm-deploy](https://github.com/chat2db/chat2db-internlm-deploy) - -## Supported databases -Chat2DB Pro supports all the following databases, including the most requested Redis feature. -- MySQL -- PostgreSQL -- H2 -- Oracle -- SQLServer -- SQLite -- MariaDB -- ClickHouse -- DM -- Presto -- DB2 -- OceanBase -- Hive -- KingBase -- MongoDB -- Redis -- Snowflake - - -## Using Chat2DB -Refer to the [Quick Start Guide](https://docs.chat2db.ai/) to get started with Chat2DB. - - -## Contribution Guide -We welcome and encourage community members to contribute to the Chat2DB project. Whether it's by reporting issues, proposing new features, or directly submitting code fixes and improvements, your help is invaluable. -If you're interested in contributing, please follow our contribution guidelines: - -- Report Issues: Report any issues or bugs encountered via GitHub Issues. -- Submit Pull Requests: If you wish to contribute directly to the codebase, please fork the repository and submit a pull request (PR). -- Improve Documentation: Contributions to best practices, example code, documentation improvements, etc., are welcome. - -## Stargazers - -[![Stargazers repo roster for @chat2db/Chat2DB](https://reporoster.com/stars/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/stargazers) - -## Forkers - -[![Forkers repo roster for @chat2db/Chat2DB](https://reporoster.com/forks/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/network/members) - -## 👋 Join Us - -### On WeChat - - - -### On Discord - -[![Discord](https://img.shields.io/badge/-Join%20us%20on%20Discord-%237289DA.svg?style=flat&logo=discord&logoColor=white)](https://discord.com/invite/uNjb3n5JVN) - -## LICENSE - -The primary license used by this software is the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), supplemented by the [Chat2DB License](./Chat2DB_LICENSE). - - -## ❤️ Acknowledgements +

+
+ README in English + 简体中文版自述文件 + 日本語のREADME + +
+ + +https://github.com/user-attachments/assets/4ae824cf-7d14-4d5b-9ceb-66481bcefc19 + + +Chat2DB is an intelligent, universal SQL client and data reporting tool that integrates AI capabilities. Chat2DB helps you write SQL queries faster, manage databases, generate reports, explore data, and interact with multiple databases. Chat2DB is an open-source project, and we welcome your contributions. + +**1. Intelligent SQL Generation**: +Chat2DB Pro supports AI-driven intelligent SQL development to help you write SQL queries faster. + +**2. Database Management**: +Supports more than 10 databases, including MySQL, PostgreSQL, H2, Oracle, SQLServer, SQLite, MariaDB, ClickHouse, DM, Presto, DB2, OceanBase, Hive, KingBase, MongoDB, Redis, Snowflake, and more. + +**3. Intelligent Report Generation**: +Chat2DB Pro supports AI-driven intelligent data reporting to help you generate dashboards faster. + +**4. Data Structure Synchronization**: +Chat2DB Pro supports database table structure synchronization to help you sync database table structures faster. + +## Feature Comparison + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureCommunity Open SourceLocalPro
Database Types16+Target 100+Target 100+
Supported AIRequires AI ConfigurationAI ready on installationAI ready on installation
AI CapabilitiesBasicVariedVaried
Visual Table Editor
SQL Console
SQL Formatting
Save Query Records
Theme Color Settings
Data Structure Sync
Database Grouping
Database Structure Import/Export
Data Import/Export
Data Migration
Copy/Clear Table
Open and Run SQL Files
UML DiagramIn DevelopmentIn Development
Generate Code
Copy Results as Insert/Update
Modify Query Results
Intelligent SQL Editor
AI Table Creation
AI Data Sets
Chat2Excel
Intelligent Dashboard
Editor Settings
Custom Shortcuts
Cross-device Usage
+ +## Download and Installation +Chat2DB is a cross-platform application that supports Windows, MacOS, and Linux. You can download Chat2DB from the following links: +- [Download Pro Version](https://chat2db.ai/download) +- [Download Local Version](https://chat2db.ai/download) +- [Download Open Source Version](https://github.com/CodePhiliaX/Chat2DB/releases/tag/v0.3.6) + +## Community Edition Docker Installation + +### System Requirements + +Before installing Chat2DB, ensure your system meets the following requirements: +- Docker 19.03.0 or later +- Docker Compose 1.25.0 or later +- CPU >= 2 Cores +- RAM >= 4 GiB + +```bash + docker rm chat2db + + docker run --name=chat2db -ti -p 10824:10824 -v ~/.chat2db-docker:/root/.chat2db chat2db/chat2db:latest + + docker start chat2db + +``` +## Code Debugging + +## Runtime Environment + +Note: +If local debugging is needed: + +- Java runtime: Open JDK 17 +- Node.js runtime: Node 16 Node.js. + +**Clone the repository locally** + +```bash +$ git clone git@github.com:chat2db/Chat2DB.git +``` + +**Frontend Debugging** + +```bash +Node version must be 16 or higher +Use yarn only, npm is not supported +$ cd Chat2DB/chat2db-client +$ yarn +$ yarn run start:web +``` + +**Backend Debugging** + +```bash +$ cd ../chat2db-server +$ mvn clean install # Maven version 3.8 or higher is required +$ cd chat2db-server/chat2db-server-start/target/ +$ java -jar -Dloader.path=./lib -Dchatgpt.apiKey=xxxxx chat2db-server-start.jar # 需要安装java 17以上版本,启动应用 chatgpt.apiKey 需要输入ChatGPT的key,如果不输入无法使用AIGC功能 +``` +**Standalone Deployment** +```bash +# chat2db-client +$ npm run build:web:prod +$ cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front +$ cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resources/thymeleaf +``` + +## Contact Us + +- Email: Chat2DB@ch2db.com +- Discord: [Join our Discord server](https://discord.gg/JDkwB6JS8A) +- Twitter: [@Chat2DB](https://x.com/Chat2DB_AI) +- YouTube: [Chat2DB Channel](https://www.youtube.com/@chat2db.tutorial) +- GitHub: [Chat2DB GitHub](https://github.com/codePhiliaX/chat2db) + + +## Acknowledgments + + +Thanks to everyone who has contributed to Chat2DB~~ -Thanks to all who contributed to Chat2DB~~ @@ -109,7 +301,7 @@ Thanks to all who contributed to Chat2DB~~ ## Star History - + @@ -117,9 +309,6 @@ Thanks to all who contributed to Chat2DB~~ -## link -

- - sa-token - -

+## License +The primary license used by this software is the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), supplemented by the [Chat2DB License](./Chat2DB_LICENSE). + diff --git a/README_CN.md b/README_CN.md index 402bd9ec7..846494937 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,136 +1,312 @@ - - - -加群前请先 Star 和 Fork,谢谢~关注微信公众号可加入微信、钉钉、QQ 群一起讨论,并可以获取 Chat2DB 最新动态和更新。 - - -# Chat2DB - -**中文** | [English](README.md)· [更新日志](CHANGELOG.md) · [文档](https://docs.chat2db-ai.com/) · [报告问题](https://github.com/chat2db/Chat2DB/issues) · [提交PR](https://github.com/chat2db/Chat2DB/pulls) - -[![License](https://img.shields.io/github/license/alibaba/fastjson2?color=4D7A97&logo=apache)](https://www.apache.org/licenses/LICENSE-2.0.html) -[![Java support](https://img.shields.io/badge/Java-17+-green?logo=java&logoColor=white)](https://openjdk.java.net/) -[![GitHub release](https://img.shields.io/github/release/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/releases) -[![GitHub Stars](https://img.shields.io/github/stars/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/stargazers) -[![GitHub Forks](https://img.shields.io/github/forks/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/fork) -[![GitHub Contributors](https://img.shields.io/github/contributors/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/graphs/contributors) - -
-

分享Chat2DB仓库

+ CodePhiliaX%2FChat2DB | Trendshift +
+

- + + chat on Discord + Share on Telegram Share on Reddit -

- - -
- 如果你觉得Chat2DB有帮助,请点击右上角的⭐Stargithub star和Fork,你的支持是Chat2DB变得更好的最大动力 -
+

+
+ README in English + 简体中文版自述文件 + 日本語のREADME +
-## ⏬ 下载和安装Chat2DB(Pro) - -- 从[官网](https://chat2db-ai.com/download)下载安装包 -- 双击安装包进行安装 - -# 最近更新 - -### 期待已久的Chat2DB Pro版本终于来了,新增了以下几个核心亮点。 -#### AI驱动的智能SQL开发 - - Chat2DB - - - Chat2DB - - -Chat2DB - - -#### AI驱动的智能报告 - - Chat2DB - - -#### AI驱动的数据探索 - -Chat2DB - - -### 我们还开源了我们的第一个GLM,[Chat2DB-SQL-7B](https://github.com/chat2db/Chat2DB-GLM)。你可以从下面的链接了解更多详情。 - -- GitHub: [Chat2DB-SQL-7B](https://github.com/chat2db/Chat2DB-GLM) -- huggingface🤗:[Chat2DB-SQL-7B](https://huggingface.co/Chat2DB/Chat2DB-SQL-7B) -- modelscope:[Chat2DB-SQL-7B](https://modelscope.cn/models/Chat2DB/Chat2DB-SQL-7B/summary) - -### 在Chat2DB上即成InternLM模型 - -感谢InternLM对本项目的大力支持,在本项目中的自定义模型中,可以集成InternLM的多个模型权重,具体请参考[chat2db-internlm-deploy](https://github.com/chat2db/chat2db-internlm-deploy) - -## 支持的数据库 -Chat2DB Pro支持以下所有数据库,包括备受期待的Redis功能。 -- MySQL -- PostgreSQL -- H2 -- Oracle -- SQLServer -- SQLite -- MariaDB -- ClickHouse -- DM -- Presto -- DB2 -- OceanBase -- Hive -- KingBase -- MongoDB -- Redis -- Snowflake - - -## 使用Chat2DB -参考[快速开始指南](https://docs.chat2db-ai.com/),开始使用Chat2DB。 - -## 常见问题 - -### 1、无法获取数据源驱动:getJDBCDriver error: null -问题原因:无法联网导致下载数据库驱动包失败。 -解决办法:手动下载相关驱动放入到 ~/.chat2db/jdbc-lib 目录下 -下载链接 参考:Application jdbc-jar-downLoad-urls - -- https://cdn.chat2db-ai.com/lib/mysql-connector-java-8.0.30.jar -- https://cdn.chat2db-ai.com/lib/mysql-connector-java-5.1.47.jar -- https://cdn.chat2db-ai.com/lib/clickhouse-jdbc-0.3.2-patch8-http.jar -- https://cdn.chat2db-ai.com/lib/mariadb-java-client-3.0.8.jar -- https://cdn.chat2db-ai.com/lib/mssql-jdbc-11.2.1.jre17.jar -- https://cdn.chat2db-ai.com/lib/oceanbase-client-2.4.2.jar -- https://cdn.chat2db-ai.com/lib/postgresql-42.5.1.jar -- https://cdn.chat2db-ai.com/lib/sqlite-jdbc-3.39.3.0.jar -- https://cdn.chat2db-ai.com/lib/ojdbc11.jar - -## Stargazers - -[![Stargazers repo roster for @chat2db/Chat2DB](https://reporoster.com/stars/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/stargazers) - -## Forkers - -[![Forkers repo roster for @chat2db/Chat2DB](https://reporoster.com/forks/chat2db/Chat2DB)](https://github.com/chat2db/Chat2DB/network/members) - -## ☎️ 加入我们 - - -## ❤️ 致谢 +https://github.com/user-attachments/assets/3c857883-8153-4bda-92b8-d25c6adb5b13 + + + +# +Chat2DB 是一个智能的通用SQL客户端和数据报表工具,它集成了AI的能力。Chat2DB可以帮助您更快地编写SQL查询、管理数据库、生成报告、探索数据、并且可以与多种数据库进行交互。Chat2DB是一个开源项目,我们欢迎您的贡献。 + +**1. 智能生成SQL**: +Chat2DB Pro支持AI驱动的智能SQL开发,可以帮助您更快地编写SQL查询。 + + +**2. 数据库管理**: + 支持多种10+数据库,包括MySQL、PostgreSQL、H2、Oracle、SQLServer、SQLite、MariaDB、ClickHouse、DM、Presto、DB2、OceanBase、Hive、KingBase、MongoDB、Redis、Snowflake等。 + + + +**3. 智能生成报表**: + Chat2DB Pro支持AI驱动的智能数据报表,可以帮助您更快地生成看板。 + +**4. 数据结构同步**: + Chat2DB Pro支持数据库表结构同步,可以帮助您更快地同步数据库表结构。 + +## 功能比较 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
功能社区开源版Local版(收费)Pro版(收费)
数据库类型16+目标100+目标100+
支持的 AI需要配置AI安装即可使用AI安装即可使用AI
AI 能力简单多样多样
可视化编辑表
SQL控制台
SQL格式化
保存查询记录
主题颜色设置
数据结构同步
数据库分组
数据库结构导入导出
数据导入导出
数据迁移
复制/清空表
打开运行SQL文件
UML图开发中开发中
生成代码
复制结果为 +Insert/update +
修改查询结果
智能SQL编辑器
AI建表
AI数据集
Chat2Excel
智能看板
编辑器设置
自定义快捷键
跨多设备使用
+ +## 下载安装 +Chat2DB 是一个跨平台的应用程序,支持Windows、MacOS和Linux。您可以从以下链接下载Chat2DB。 +- [下载 Pro 版](https://chat2db.ai/download) +- [下载 Local 版](https://chat2db.ai/download) +- [下载开源版](https://github.com/CodePhiliaX/Chat2DB/releases/tag/v0.3.6) + +## 社区版 Docker 安装 + +### 系统要求 + +在安装 Chat2DB 之前,请确保您的系统满足以下要求: +- Docker 19.03.0 或更高版本 +- Docker Compose 1.25.0 或更高版本 +- CPU >= 2 Core +- RAM >= 4 GiB + + +```bash + // 拉取最新客户端,然后运行docker,名字是 `chat2db` , 并且将 `/root/.chat2db` 挂载到 `~/.chat2db-docker` + docker run --name=chat2db -ti -p 10824:10824 -v ~/.chat2db-docker:/root/.chat2db chat2db/chat2db:latest + // 这里正常会提示`Tomcat started on port(s): 10824 (http) with context path` 就可以结束了 + + // 如果这里提示 `The container name "/chat2db" is already in use by container`, 代表已经存在容器了 运行 + docker start chat2db + // 如果想更新chat2db 则需要先rm + docker rm chat2db +``` +## 代码调试 + + +## 运行环境 + +注意: +如果需要本地调试 + +- java 运行 Open JDK 17 +- Node 运行环境 Node16 Node.js. + +**git clone 到本地** + +```bash +$ git clone git@github.com:chat2db/Chat2DB.git +``` + +**前端调试** + +```bash +node版本必须为16及以上 +一定要用yarn +$ cd Chat2DB/chat2db-client +$ yarn +$ yarn run start:web +``` + +**后端调试** + +```bash +$ cd ../chat2db-server +$ mvn clean install # 需要安装maven 3.8以上版本 +$ cd chat2db-server/chat2db-server-start/target/ +$ java -jar -Dloader.path=./lib -Dchatgpt.apiKey=xxxxx chat2db-server-start.jar # 需要安装java 17以上版本,启动应用 chatgpt.apiKey 需要输入ChatGPT的key,如果不输入无法使用AIGC功能 +``` +**独立部署** +```bash +# chat2db-client +$ npm run build:web:prod +$ cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front +$ cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resources/thymeleaf + +# 再打包后端服务 +``` + +## 联系我们 + + + +- Email: Chat2DB@ch2db.com +- Discord: [Join our Discord server](https://discord.gg/JDkwB6JS8A) +- Twitter: [@Chat2DB](https://x.com/Chat2DB_AI) +- YouTube: [Chat2DB Channel](https://www.youtube.com/@chat2db.tutorial) +- GitHub: [Chat2DB GitHub](https://github.com/codePhiliaX/chat2db) + + +## 致谢 感谢所有为 Chat2DB 贡献力量的同学们~~ @@ -140,18 +316,16 @@ Chat2DB Pro支持以下所有数据库,包括备受期待的Redis功能。 ## Star History - + - - - Star History Chart + + + Star History Chart -## 友情链接 -

- - sa-token - -

+## License +The primary license used by this software is the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0), supplemented by the [Chat2DB License](./Chat2DB_LICENSE). + + diff --git a/README_JA.md b/README_JA.md new file mode 100644 index 000000000..d440e22a5 --- /dev/null +++ b/README_JA.md @@ -0,0 +1,315 @@ + + + +
+ CodePhiliaX%2FChat2DB | Trendshift +
+
+

+ + chat on Discord + +Share on Telegram + +Share on Reddit + + +

+
+ README in English + 简体中文版自述文件 + 日本語のREADME +
+ + + +https://github.com/user-attachments/assets/bd5d5f64-540f-4793-a801-17fa96c4766e + + + + +Chat2DBはAI機能を統合したインテリジェントで汎用的なSQLクライアントおよびデータ報告ツールです。Chat2DBは、SQLクエリの作成を迅速化し、データベースの管理、レポートの生成、データの探索、および複数のデータベースとのインタラクションをサポートします。Chat2DBはオープンソースプロジェクトであり、皆様の貢献を歓迎します。 + +**1. インテリジェントSQL生成**: +Chat2DB Proは、AI駆動によるインテリジェントなSQL開発をサポートし、SQLクエリをより速く作成する手助けをします。 + +**2. データベース管理**: +MySQL、PostgreSQL、H2、Oracle、SQLServer、SQLite、MariaDB、ClickHouse、DM、Presto、DB2、OceanBase、Hive、KingBase、MongoDB、Redis、Snowflakeなど、10種類以上のデータベースをサポートしています。 + +**3. インテリジェントレポート生成**: +Chat2DB Proは、AI駆動によるインテリジェントなデータ報告をサポートし、ダッシュボードの作成を迅速に行う手助けをします。 + +**4. データ構造の同期**: +Chat2DB Proは、データベーステーブル構造の同期をサポートし、データベーステーブルの構造を迅速に同期する手助けをします。 + +## 機能比較 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
機能コミュニティ オープンソースローカルPro
データベースの種類16種類以上100種類以上を対象100種類以上を対象
サポートされているAIAI設定が必要インストール時にAIが利用可能インストール時にAIが利用可能
AI機能基本的多様多様
視覚的テーブルエディタ
SQLコンソール
SQLフォーマット
クエリ記録の保存
テーマカラー設定
データ構造の同期
データベースのグループ化
データベース構造のインポート/エクスポート
データのインポート/エクスポート
データ移行
テーブルのコピー/削除
SQLファイルのオープンと実行
UMLダイアグラム開発中開発中
コード生成
インサート/アップデートとして結果をコピー
クエリ結果の修正
インテリジェントSQLエディタ
AIによるテーブル作成
AIデータセット
Chat2Excel
インテリジェントダッシュボード
エディタ設定
カスタムショートカット
クロスデバイス使用
+ + +## ダウンロードとインストール +Chat2DBは、Windows、MacOS、Linuxをサポートするクロスプラットフォームアプリケーションです。以下のリンクからChat2DBをダウンロードできます: +- [Proバージョンのダウンロード](https://chat2db.ai/download) +- [ローカルバージョンのダウンロード](https://chat2db.ai/download) +- [オープンソースバージョンのダウンロード](https://github.com/CodePhiliaX/Chat2DB/releases/tag/v0.3.6) + +## コミュニティエディションのDockerインストール + +### システム要件 + +Chat2DBをインストールする前に、システムが以下の要件を満たしていることを確認してください: +- Docker 19.03.0以上 +- Docker Compose 1.25.0以上 +- CPU >= 2コア +- RAM >= 4 GiB + +```bash + docker rm chat2db + + docker run --name=chat2db -ti -p 10824:10824 -v ~/.chat2db-docker:/root/.chat2db chat2db/chat2db:latest + + docker start chat2db +``` +## コードデバッグ + +## 実行環境 + +注意: ローカルデバッグが必要な場合: + +- Java runtime: Open JDK 17 +- Node.js runtime: Node 16 Node.js. + +**リポジトリをローカルにクローン** + +```bash +$ git clone git@github.com:chat2db/Chat2DB.git +``` + +**フロントエンドデバッグ** + +```bash +Node version must be 16 or higher +Use yarn only, npm is not supported +$ cd Chat2DB/chat2db-client +$ yarn +$ yarn run start:web +``` + +**バックエンドデバッグ** + +```bash +$ cd ../chat2db-server +$ mvn clean install # Maven version 3.8 or higher is required +$ cd chat2db-server/chat2db-server-start/target/ +$ java -jar -Dloader.path=./lib -Dchatgpt.apiKey=xxxxx chat2db-server-start.jar # 需要安装java 17以上版本,启动应用 chatgpt.apiKey 需要输入ChatGPT的key,如果不输入无法使用AIGC功能 +``` +**スタンドアロンデプロイ** +```bash +# chat2db-client +$ npm run build:web:prod +$ cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front +$ cp -r dist/index.html ../chat2db-server/chat2db-server-start/src/main/resources/thymeleaf +``` + +## お問い合わせ + +- メール: Chat2DB@ch2db.com +- Discord: [Discordサーバーに参加](https://discord.gg/JDkwB6JS8A) +- Twitter: [@Chat2DB](https://x.com/Chat2DB_AI) +- YouTube: [Chat2DB チャンネル](https://www.youtube.com/@chat2db.tutorial) +- GitHub: [Chat2DB GitHub](https://github.com/codePhiliaX/chat2db) + +## 謝辞 + +Chat2DBに貢献してくださったすべての方々に感謝します~~ + + + + + + + +## Star History + + + + + + Star History Chart + + + +## License +このソフトウェアで使用されている主なライセンスは[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)であり、[Chat2DB License](./Chat2DB_LICENSE)が補完されています。 + + diff --git a/chat2db-client/src/blocks/Setting/UpdateDetection/index.tsx b/chat2db-client/src/blocks/Setting/UpdateDetection/index.tsx index 38ecfc756..e2c1e7880 100644 --- a/chat2db-client/src/blocks/Setting/UpdateDetection/index.tsx +++ b/chat2db-client/src/blocks/Setting/UpdateDetection/index.tsx @@ -41,9 +41,9 @@ const UpdateDetection = memo( const [notificationApi, notificationDom] = notification.useNotification(); const timesRef = React.useRef(0); - useEffect(() => { - checkUpdate(); - }, []); + // useEffect(() => { + // checkUpdate(); + // }, []); const close = () => {}; diff --git a/chat2db-client/src/typings/ai.ts b/chat2db-client/src/typings/ai.ts index 0ed1d7b2e..da79e4b7f 100644 --- a/chat2db-client/src/typings/ai.ts +++ b/chat2db-client/src/typings/ai.ts @@ -1,5 +1,5 @@ export enum AIType { - // CHAT2DBAI = 'CHAT2DBAI', + CHAT2DBAI = 'CHAT2DBAI', ZHIPUAI = 'ZHIPUAI', BAICHUANAI='BAICHUANAI', WENXINAI='WENXINAI', diff --git a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java index 9f313c27c..0eef415af 100644 --- a/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-clickhouse/src/main/java/ai/chat2db/plugin/clickhouse/builder/ClickHouseSqlBuilder.java @@ -10,6 +10,8 @@ import ai.chat2db.spi.model.TableIndex; import org.apache.commons.lang3.StringUtils; +import java.util.List; + public class ClickHouseSqlBuilder extends DefaultSqlBuilder { @Override diff --git a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java index 1b1cc2fd6..05f938c3b 100644 --- a/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java +++ b/chat2db-server/chat2db-plugins/chat2db-h2/src/main/java/ai/chat2db/plugin/h2/H2Meta.java @@ -3,6 +3,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; +import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; diff --git a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/builder/HiveSqlBuilder.java b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/builder/HiveSqlBuilder.java index 02a761df7..a3ca677dd 100644 --- a/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/builder/HiveSqlBuilder.java +++ b/chat2db-server/chat2db-plugins/chat2db-hive/src/main/java/ai/chat2db/plugin/hive/builder/HiveSqlBuilder.java @@ -2,6 +2,7 @@ import ai.chat2db.plugin.hive.type.HiveColumnTypeEnum; import ai.chat2db.plugin.hive.type.HiveIndexTypeEnum; +import ai.chat2db.spi.SqlBuilder; import ai.chat2db.spi.jdbc.DefaultSqlBuilder; import ai.chat2db.spi.model.Database; import ai.chat2db.spi.model.Table; @@ -9,6 +10,7 @@ import ai.chat2db.spi.model.TableIndex; import org.apache.commons.lang3.StringUtils; +import java.util.List; public class HiveSqlBuilder extends DefaultSqlBuilder implements SqlBuilder { diff --git a/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_10__REMOVEdEMO.sql b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_10__REMOVEdEMO.sql new file mode 100644 index 000000000..b0f5f6300 --- /dev/null +++ b/chat2db-server/chat2db-server-domain/chat2db-server-domain-repository/src/main/resources/db/migration/V2_1_10__REMOVEdEMO.sql @@ -0,0 +1,7 @@ +delete from DATA_SOURCE where ALIAS ='DEMO@db.sqlgpt.cn'; + +delete from DASHBOARD where id =ID; + +delete from CHART where id<=3; + +delete from DASHBOARD_CHART_RELATION where CHART_ID<=3; diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java index 7b2a5ca69..8010a1258 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/ChatController.java @@ -235,7 +235,7 @@ public SseEmitter distributeAISql(ChatQueryRequest queryRequest, SseEmitter sseE case CHAT2DBAI: return chatWithChat2dbAi(queryRequest, sseEmitter, uid); case RESTAI : - return chatWithRestAi(queryRequest, sseEmitter); + return chatWithRestAi(queryRequest, sseEmitter, uid); case FASTCHATAI: return chatWithFastChatAi(queryRequest, sseEmitter, uid); case AZUREAI : @@ -261,9 +261,15 @@ public SseEmitter distributeAISql(ChatQueryRequest queryRequest, SseEmitter sseE * @param sseEmitter * @return */ - private SseEmitter chatWithRestAi(ChatQueryRequest prompt, SseEmitter sseEmitter) { - RestAIEventSourceListener eventSourceListener = new RestAIEventSourceListener(sseEmitter); - RestAIClient.getInstance().restCompletions(buildPrompt(prompt), eventSourceListener); + private SseEmitter chatWithRestAi(ChatQueryRequest queryRequest, SseEmitter sseEmitter, String uid) throws IOException { + String prompt = buildPrompt(queryRequest); + List messages = getFastChatMessage(uid, prompt); + + buildSseEmitter(sseEmitter, uid); + + RestAIEventSourceListener restAIEventSourceListener = new RestAIEventSourceListener(sseEmitter); + RestAIClient.getInstance().streamCompletions(messages, restAIEventSourceListener); + LocalCache.CACHE.put(uid, JSONUtil.toJsonStr(messages), LocalCache.TIMEOUT); return sseEmitter; } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java index b95c09348..ab13f07c4 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIClient.java @@ -6,6 +6,7 @@ import ai.chat2db.server.web.api.util.ApplicationContextUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; /** * @author moji @@ -19,6 +20,11 @@ public class RestAIClient { */ public static final String AI_SQL_SOURCE = "ai.sql.source"; + /** + * Customized AI interface KEY + */ + public static final String REST_AI_API_KEY = "rest.ai.apiKey"; + /** * Customized AI interface address */ @@ -29,9 +35,16 @@ public class RestAIClient { */ public static final String REST_AI_STREAM_OUT = "rest.ai.stream"; - private static RestAiStreamClient REST_AI_STREAM_CLIENT; + /** + * Custom AI interface model + */ + public static final String REST_AI_MODEL = "rest.ai.model"; - public static RestAiStreamClient getInstance() { + + + private static RestAIStreamClient REST_AI_STREAM_CLIENT; + + public static RestAIStreamClient getInstance() { if (REST_AI_STREAM_CLIENT != null) { return REST_AI_STREAM_CLIENT; } else { @@ -39,7 +52,7 @@ public static RestAiStreamClient getInstance() { } } - private static RestAiStreamClient singleton() { + private static RestAIStreamClient singleton() { if (REST_AI_STREAM_CLIENT == null) { synchronized (RestAIClient.class) { if (REST_AI_STREAM_CLIENT == null) { @@ -55,17 +68,23 @@ private static RestAiStreamClient singleton() { */ public static void refresh() { String apiUrl = ""; - Boolean stream = Boolean.TRUE; + String apiKey = ""; + String model = ""; ConfigService configService = ApplicationContextUtil.getBean(ConfigService.class); Config apiHostConfig = configService.find(REST_AI_URL).getData(); if (apiHostConfig != null) { apiUrl = apiHostConfig.getContent(); } - Config config = configService.find(REST_AI_STREAM_OUT).getData(); + Config config = configService.find(REST_AI_API_KEY).getData(); if (config != null) { - stream = Boolean.valueOf(config.getContent()); + apiKey = config.getContent(); + } + Config deployConfig = configService.find(REST_AI_MODEL).getData(); + if (deployConfig != null && StringUtils.isNotBlank(deployConfig.getContent())) { + model = deployConfig.getContent(); } - REST_AI_STREAM_CLIENT = new RestAiStreamClient(apiUrl, stream); + REST_AI_STREAM_CLIENT = RestAIStreamClient.builder().apiKey(apiKey).apiHost(apiUrl).model(model) + .build(); } } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIStreamClient.java new file mode 100644 index 000000000..55ab922d7 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAIStreamClient.java @@ -0,0 +1,180 @@ +package ai.chat2db.server.web.api.controller.ai.rest.client; + +import ai.chat2db.server.tools.common.exception.ParamBusinessException; +import ai.chat2db.server.web.api.controller.ai.fastchat.interceptor.FastChatHeaderAuthorizationInterceptor; +import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatCompletionsOptions; +import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatMessage; +import cn.hutool.http.ContentType; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.sse.EventSource; +import okhttp3.sse.EventSourceListener; +import okhttp3.sse.EventSources; +import org.apache.commons.collections4.CollectionUtils; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * Custom AI interface client + * @author moji + */ +@Slf4j +public class RestAIStreamClient { + /** + * apikey + */ + @Getter + @NotNull + private String apiKey; + + /** + * apiHost + */ + @Getter + @NotNull + private String apiHost; + + /** + * model + */ + @Getter + private String model; + /** + * okHttpClient + */ + @Getter + private OkHttpClient okHttpClient; + + /** + * Construct instance object + * + * @param builder + */ + public RestAIStreamClient(Builder builder) { + this.apiKey = builder.apiKey; + this.apiHost = builder.apiHost; + this.model = builder.model; + this.okHttpClient = new OkHttpClient + .Builder() + .addInterceptor(new FastChatHeaderAuthorizationInterceptor(this.apiKey)) + .connectTimeout(10, TimeUnit.SECONDS) + .writeTimeout(50, TimeUnit.SECONDS) + .readTimeout(50, TimeUnit.SECONDS) + .build(); + } + + /** + * structure + * + * @return + */ + public static RestAIStreamClient.Builder builder() { + return new RestAIStreamClient.Builder(); + } + + /** + * builder + */ + public static final class Builder { + private String apiKey; + + private String apiHost; + + private String model; + + + /** + * OkhttpClient + */ + private OkHttpClient okHttpClient; + + public Builder() { + } + + public RestAIStreamClient.Builder apiKey(String apiKeyValue) { + this.apiKey = apiKeyValue; + return this; + } + + /** + * @param apiHostValue + * @return + */ + public RestAIStreamClient.Builder apiHost(String apiHostValue) { + this.apiHost = apiHostValue; + return this; + } + + /** + * @param modelValue + * @return + */ + public RestAIStreamClient.Builder model(String modelValue) { + this.model = modelValue; + return this; + } + + + public RestAIStreamClient.Builder okHttpClient(OkHttpClient val) { + this.okHttpClient = val; + return this; + } + + public RestAIStreamClient build() { + return new RestAIStreamClient(this); + } + + } + + + /** + * Q&A interface stream form + * + * @param chatMessages + * @param eventSourceListener + */ + public void streamCompletions(List chatMessages, EventSourceListener eventSourceListener) { + if (CollectionUtils.isEmpty(chatMessages)) { + log.error("param error:Rest AI Prompt cannot be empty"); + throw new ParamBusinessException("prompt"); + } + if (Objects.isNull(eventSourceListener)) { + log.error("param error:RestAIEventSourceListener cannot be empty"); + throw new ParamBusinessException(); + } + log.info("Rest AI, prompt:{}", chatMessages.get(chatMessages.size() - 1).getContent()); + try { + + FastChatCompletionsOptions chatCompletionsOptions = new FastChatCompletionsOptions(chatMessages); + chatCompletionsOptions.setStream(true); + chatCompletionsOptions.setModel(this.model); + + EventSource.Factory factory = EventSources.createFactory(this.okHttpClient); + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + String requestBody = mapper.writeValueAsString(chatCompletionsOptions); + Request request = new Request.Builder() + .url(apiHost) + .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) + .build(); + //Create event + EventSource eventSource = factory.newEventSource(request, eventSourceListener); + log.info("finish invoking rest ai"); + } catch (Exception e) { + log.error("rest ai error", e); + eventSourceListener.onFailure(null, e, null); + throw new ParamBusinessException(); + } + } + + +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java deleted file mode 100644 index 7d5164e5b..000000000 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/client/RestAiStreamClient.java +++ /dev/null @@ -1,166 +0,0 @@ -package ai.chat2db.server.web.api.controller.ai.rest.client; - -import java.io.IOException; -import java.util.Objects; -import java.util.concurrent.TimeUnit; - -import ai.chat2db.server.tools.common.exception.ParamBusinessException; -import ai.chat2db.server.web.api.controller.ai.rest.model.RestAiCompletion; -import cn.hutool.http.ContentType; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.unfbx.chatgpt.sse.ConsoleEventSourceListener; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; -import okhttp3.ResponseBody; -import okhttp3.sse.EventSource; -import okhttp3.sse.EventSourceListener; -import okhttp3.sse.EventSources; -import org.apache.commons.lang3.StringUtils; - -/** - * Custom AI interface client - * @author moji - */ -@Slf4j -public class RestAiStreamClient { - /** - * rest api url - */ - @Getter - private String apiUrl; - - /** - * Whether to stream interface - */ - @Getter - private Boolean stream; - /** - * okHttpClient - */ - @Getter - private OkHttpClient okHttpClient; - - /** - * Construct instance object - * - * @param url - */ - public RestAiStreamClient(String url, Boolean stream) { - this.apiUrl = url; - this.stream = stream; - this.okHttpClient = new OkHttpClient - .Builder() - .connectTimeout(10, TimeUnit.SECONDS) - .writeTimeout(50, TimeUnit.SECONDS) - .readTimeout(50, TimeUnit.SECONDS) - .build(); - } - - /** - * Request RESTAI interface - * - * @param prompt - * @param eventSourceListener - */ - public void restCompletions(String prompt, - EventSourceListener eventSourceListener) { - log.info("Start calling the custom AI, prompt:{}", prompt); - RestAiCompletion completion = new RestAiCompletion(); - completion.setPrompt(prompt); - if (Objects.isNull(stream) || stream) { - streamCompletions(completion, eventSourceListener); - log.info("End calling streaming output custom AI"); - return; - } - nonStreamCompletions(completion, eventSourceListener); - log.info("End calling non-streaming output custom AI"); - } - - /** - * Q&A interface stream form - * - * @param completion open ai parameter - * @param eventSourceListener sse listener - * @see ConsoleEventSourceListener - */ - public void streamCompletions(RestAiCompletion completion, EventSourceListener eventSourceListener) { - if (Objects.isNull(eventSourceListener)) { - log.error("Parameter exception: EventSourceListener cannot be empty"); - throw new ParamBusinessException(); - } - if (StringUtils.isBlank(completion.getPrompt())) { - log.error("Parameter exception: Prompt cannot be empty"); - throw new ParamBusinessException(); - } - try { - EventSource.Factory factory = EventSources.createFactory(this.okHttpClient); - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - String requestBody = mapper.writeValueAsString(completion); - Request request = new Request.Builder() - .url(this.apiUrl) - .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) - .build(); - //Create event - EventSource eventSource = factory.newEventSource(request, eventSourceListener); - } catch (Exception e) { - log.error("Request parameter parsing exception", e); - throw new ParamBusinessException(); - } - } - - /** - * Request non-streaming output interface - * - * @param completion - * @param eventSourceListener - */ - public void nonStreamCompletions(RestAiCompletion completion, EventSourceListener eventSourceListener) { - if (StringUtils.isBlank(completion.getPrompt())) { - log.error("Parameter exception: Prompt cannot be empty"); - throw new ParamBusinessException(); - } - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - String requestBody = mapper.writeValueAsString(completion); - Request request = new Request.Builder() - .url(this.apiUrl) - .post(RequestBody.create(MediaType.parse(ContentType.JSON.getValue()), requestBody)) - .build(); - - this.okHttpClient.newCall(request).enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - eventSourceListener.onFailure(null, e, null); - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - try (ResponseBody responseBody = response.body()) { - if (responseBody != null) { - String content = responseBody.string(); - eventSourceListener.onEvent(null, "[DATA]", null, content); - eventSourceListener.onEvent(null, "[DONE]", null, "[DONE]"); - } - } catch (IOException e) { - eventSourceListener.onFailure(null, e, response); - } - } - }); - - } catch (Exception e) { - log.error("Request parameter parsing exception", e); - throw new ParamBusinessException(); - } - } - -} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java index bb5524783..0509ac6fe 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/listener/RestAIEventSourceListener.java @@ -1,7 +1,12 @@ package ai.chat2db.server.web.api.controller.ai.rest.listener; +import java.io.IOException; import java.util.Objects; +import ai.chat2db.server.web.api.controller.ai.rest.model.RestAIChatCompletions; +import ai.chat2db.server.web.api.controller.ai.zhipu.model.ZhipuChatCompletions; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.unfbx.chatgpt.entity.chat.Message; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @@ -27,6 +32,7 @@ public RestAIEventSourceListener(SseEmitter sseEmitter) { this.sseEmitter = sseEmitter; } + private ObjectMapper mapper = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); /** * {@inheritDoc} */ @@ -54,9 +60,11 @@ public void onEvent(EventSource eventSource, String id, String type, String data } Message message = new Message(); if (StringUtils.isNotBlank(data)) { - data = data.replaceAll("^\"|\"$", ""); - data = data.replaceAll("\\\\n", "\n"); - message.setContent(data); + RestAIChatCompletions chatCompletions = mapper.readValue(data, RestAIChatCompletions.class); + String text = chatCompletions.getChoices().get(0).getDelta()==null? + chatCompletions.getChoices().get(0).getText() + :chatCompletions.getChoices().get(0).getDelta().getContent(); + message.setContent(text); sseEmitter.send(SseEmitter.event() .id(id) .data(message) @@ -68,10 +76,14 @@ public void onEvent(EventSource eventSource, String id, String type, String data @Override public void onClosed(EventSource eventSource) { log.info("REST AI close sse connection..."); - sseEmitter.send(SseEmitter.event() - .id("[DONE]") - .data("[DONE]") - .reconnectTime(3000)); + try { + sseEmitter.send(SseEmitter.event() + .id("[DONE]") + .data("[DONE]") + .reconnectTime(3000)); + } catch (IOException e) { + throw new RuntimeException(e); + } sseEmitter.complete(); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAIChatCompletions.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAIChatCompletions.java new file mode 100644 index 000000000..6d3915322 --- /dev/null +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/ai/rest/model/RestAIChatCompletions.java @@ -0,0 +1,96 @@ +package ai.chat2db.server.web.api.controller.ai.rest.model; + +import ai.chat2db.server.web.api.controller.ai.fastchat.model.FastChatChoice; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class RestAIChatCompletions { + + /* + * A unique identifier associated with this chat completions response. + */ + private String id; + + /* + * The first timestamp associated with generation activity for this completions response, + * represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970. + */ + private int created; + + /** + * model + */ + private String model; + + /** + * object + */ + private String object; + + /* + * The collection of completions choices associated with this completions response. + * Generally, `n` choices are generated per provided prompt with a default value of 1. + * Token limits and other settings may limit the number of choices generated. + */ + @JsonProperty(value = "choices") + private List choices; + + + /** + * Creates an instance of ChatCompletions class. + * + * @param id the id value to set. + * @param created the created value to set. + * @param choices the choices value to set. + */ + @JsonCreator + private RestAIChatCompletions( + @JsonProperty(value = "id") String id, + @JsonProperty(value = "created") int created, + @JsonProperty(value = "model") String model, + @JsonProperty(value = "object") String object, + @JsonProperty(value = "choices") List choices) { + this.id = id; + this.created = created; + this.model = model; + this.object = object; + this.choices = choices; + } + + /** + * Get the id property: A unique identifier associated with this chat completions response. + * + * @return the id value. + */ + public String getId() { + return this.id; + } + + /** + * Get the created property: The first timestamp associated with generation activity for this completions response, + * represented as seconds since the beginning of the Unix epoch of 00:00 on 1 Jan 1970. + * + * @return the created value. + */ + public int getCreated() { + return this.created; + } + + /** + * Get the choices property: The collection of completions choices associated with this completions response. + * Generally, `n` choices are generated per provided prompt with a default value of 1. Token limits and other + * settings may limit the number of choices generated. + * + * @return the choices value. + */ + public List getChoices() { + return this.choices; + } + + + +} diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java index 0d8625cd9..92f5eb360 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/config/ConfigController.java @@ -83,7 +83,7 @@ public ActionResult addChatGptSystemConfig(@RequestBody AIConfigCreateRequest re saveChat2dbAIConfig(request); break; case RESTAI: - saveFastChatAIConfig(request); + saveRestAIConfig(request); break; case AZUREAI: saveAzureAIConfig(request); @@ -152,12 +152,15 @@ private void saveOpenAIConfig(AIConfigCreateRequest request) { * @param request */ private void saveRestAIConfig(AIConfigCreateRequest request) { + SystemConfigParam param = SystemConfigParam.builder().code(RestAIClient.REST_AI_API_KEY).content( + request.getApiKey()).build(); + configService.createOrUpdate(param); SystemConfigParam restParam = SystemConfigParam.builder().code(RestAIClient.REST_AI_URL).content( request.getApiHost()).build(); configService.createOrUpdate(restParam); - SystemConfigParam methodParam = SystemConfigParam.builder().code(RestAIClient.REST_AI_STREAM_OUT).content( - request.getStream().toString()).build(); - configService.createOrUpdate(methodParam); + SystemConfigParam modelParam = SystemConfigParam.builder().code(RestAIClient.REST_AI_MODEL) + .content(request.getModel()).build(); + configService.createOrUpdate(modelParam); RestAIClient.refresh(); } diff --git a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java index f9c529a5b..7881cf93a 100644 --- a/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java +++ b/chat2db-server/chat2db-server-web/chat2db-server-web-api/src/main/java/ai/chat2db/server/web/api/controller/rdb/converter/RdbWebConverter.java @@ -42,6 +42,8 @@ public abstract class RdbWebConverter { public abstract DlExecuteParam request2param(DmlRequest request); + + public abstract GroupByParam request2param(GroupByRequest request); /** * Parameter conversion *