From ed7296fa550d2a9d9150bfd92ed90b645f758e26 Mon Sep 17 00:00:00 2001 From: moyangzhan Date: Mon, 8 Apr 2024 23:07:23 +0800 Subject: [PATCH] update readme --- README.md | 6 +- README_en.md | 170 ++++++++++++++++++ .../adi/common/service/SearchService.java | 7 + .../common/service/UserDayCostService.java | 6 + 4 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 README_en.md diff --git a/README.md b/README.md index 2e97e88..73b7a3b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ ## Getting Started +[READ THIS IN ENGLISH](README_en.md) + **LangChain4j-AIDeepin** -基于 ChatGPT 等大语言模型与 Langchain4j 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。 +基于 ChatGPT 等大语言模型与 Langchain4j 等应用框架实现,开源、可离线部署的检索增强生成(RAG)项目。 > **该项目如对您有帮助,欢迎点赞** @@ -167,4 +169,4 @@ docker run -d \ **额度统计:** -![1691583329105.png](image%2FREADME%2F1691583329105.png) +!![1691583329105.png](image%2FREADME%2F1691583329105.png) diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000..993a80e --- /dev/null +++ b/README_en.md @@ -0,0 +1,170 @@ +## Getting Started + +[中文](README.md) + +**LangChain4j-AIDeepin** +Langchain4j-aideepin is an open source, offline deployable Retrieval Enhancement Generation (RAG) project based on large language models such as ChatGPT and application frameworks such as Langchain4j. + +## Website + +[http://www.aideepin.com](http://www.aideepin.com/) + +## Feature + +* Login & Register +* Multiple Conversation | Multiple character +* AI Draw +* Prompt +* Quota +* Knowledge base(RAG) +* AI Search(RAG) +* Multiple models switch at will +* Multiple search engine switch at will + +## Support Models + +* ChatGPT 3.5 +* 通义千问 +* 文心一言 +* ollama +* DALL-E 2 + +## Support Search Engines + +Google + +Bing (TODO) + +百度 (TODO) + +## Introduction + +This repository is a back-end project, front-end project in [langchain4j-aideepin-web](https://github.com/moyangzhan/langchain4j-aideepin-web) + +Backend: + +jdk17 + +springboot3.0.5 + +[langchain4j(Java version of LangChain)](https://github.com/langchain4j/langchain4j) + +**Postgresql(需要安装[pgvector](https://github.com/pgvector/pgvector)扩展)** + +Frontend: + +vue3+typescript+pnpm + +## Build and run this project + +### Init + +**a. Init database** + +* Create database schema: aideepin +* Run: docs/create.sql +* Update language model config: + +Openai setting + +```plaintext +update adi_sys_config set value = '{"secret_key":"my_openai_secret_key","models":["gpt-3.5-turbo"]}' where name = 'openai_setting'; +``` + +Dashscope setting + +```plaintext +update adi_sys_config set value = '{"api_key":"my_dashcope_api_key","models":["my model name,eg:qwen-max"]}' where name = 'dashscope_setting'; +``` + +Qianfan setting + +```plaintext +update adi_sys_config set value = '{"api_key":"my_qianfan_api_key","secret_key":"my_qianfan_secret_key","models":["my model name,eg:ERNIE-Bot"]}' where name = 'qianfan_setting'; +``` + +Ollama setting + +``` +update adi_sys_config set value = '{"base_url":"my_ollama_base_url","models":["my model name,eg:tinydolphin"]}' where name = 'ollama_setting'; +``` + +* Search engine setting + +Google: + +``` +update adi_sys_config set value = '{"url":"https://www.googleapis.com/customsearch/v1","key":"my key from cloud.google.com","cx":"my cx from programmablesearchengine.google.com"}' where name = 'google_setting'; +``` + + +**b. Init properties** + +* postgresql: spring.datasource in application-[dev|prod].xml +* redis: spring.data.redis in application-[dev|prod].xml +* mail: spring.mail in application.xml + +### Compile & Run + +* Enter the project root directory: + +```plaintext +cd langchain4j-aideepin +``` + +* Package: + +``` +mvn clean package -Dmaven.test.skip=true +``` + +* Run: + +a. Run by jar: + +```plaintext +cd adi-bootstrap/target +nohup java -jar -Xms768m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError adi-chat-0.0.1-SNAPSHOT.jar --spring.profiles.active=[dev|prod] dev/null 2>&1 & +``` + +b. Run by docker + +```plaintext +cd adi-bootstrap +docker build . -t aideepin:0.0.1 +docker run -d \ + --name=aideepin \ + -e APP_PROFILE=[dev|prod] \ + -v="/data/aideepin/logs:/data/logs" \ + aideepin:0.0.1 +``` + +## TODO: + +Enhance RAG + +More search engine(BING、百度) + +## Screenshot + +**AI Chat:** +![1691583184761](image/README/1691583184761.png) + +**AI Draw:** + +![1691583124744](image/README/1691583124744.png "AI绘图") + +**Knowlege base:** +![kbindex](image/README/kbidx.png) + +![kb01](image/README/kb01.png) + +**Embedding:** + +![kb02](image/README/kb02.png) + +![kb03](image/README/kb03.png) + +**Quota:** + +!![1691583329105.png](image%2FREADME%2F1691583329105.png) diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java b/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java index f3be1d1..7d033df 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/SearchService.java @@ -54,6 +54,9 @@ public class SearchService { @Resource private AiSearchRecordService aiSearchRecordService; + @Resource + private UserDayCostService userDayCostService; + @Resource private AsyncTaskExecutor mainExecutor; @@ -136,6 +139,8 @@ public class SearchService { newRecord.setUserUuid(user.getUuid()); newRecord.setUserId(user.getId()); aiSearchRecordService.save(newRecord); + + userDayCostService.appendCostToUser(user, promptMeta.getTokens() + answerMeta.getTokens()); }); } @@ -225,6 +230,8 @@ public class SearchService { updateRecord.setAnswer(response); updateRecord.setAnswerTokens(answerMeta.getTokens()); aiSearchRecordService.updateById(updateRecord); + + userDayCostService.appendCostToUser(user, promptMeta.getTokens() + answerMeta.getTokens()); }); } diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/UserDayCostService.java b/adi-common/src/main/java/com/moyz/adi/common/service/UserDayCostService.java index b4d470b..c3d1ba2 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/UserDayCostService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/UserDayCostService.java @@ -18,6 +18,12 @@ import java.util.List; @Service public class UserDayCostService extends ServiceImpl { + /** + * Append token cost + * + * @param user + * @param tokens The number of tokens + */ public void appendCostToUser(User user, int tokens) { UserDayCost userDayCost = getTodayCost(user); UserDayCost saveOrUpdateInst = new UserDayCost();