update readme

This commit is contained in:
moyangzhan 2024-04-08 23:07:23 +08:00
parent d392682d20
commit ed7296fa55
4 changed files with 187 additions and 2 deletions

View File

@ -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)

170
README_en.md Normal file
View File

@ -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 engineBING、百度
## 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)

View File

@ -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());
});
}

View File

@ -18,6 +18,12 @@ import java.util.List;
@Service
public class UserDayCostService extends ServiceImpl<UserDayCostMapper, UserDayCost> {
/**
* 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();