Skip to content

Commit

Permalink
add multi language support. (#109)
Browse files Browse the repository at this point in the history
The DB-GPT interface supports multiple language modes, and the language
can be set in the configuration file _.env.template_ (currently supports
Chinese [zh] and English [en])
  • Loading branch information
csunny authored May 28, 2023
2 parents 81e7533 + 6182c89 commit d114d13
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ VECTOR_STORE_TYPE=Chroma
#MILVUS_USERNAME
#MILVUS_PASSWORD
#MILVUS_SECURE=


LANGUAGE=en
#LANGUAGE=zh
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,7 @@ dmypy.json
logs
nltk_data
.vectordb
pilot/data/
pilot/data/

logswebserver.log.*
.history/*
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ We provide a user interface for Gradio, which allows you to use DB-GPT through o

To use multiple models, modify the LLM_MODEL parameter in the .env configuration file to switch between the models.

### Multi Language Usage
To use multiple language model, modify the LLM_MODEL parameter in the .env configuration file to switch between the models.

In the .env configuration file, modify the LANGUAGE parameter to switch between different languages, the default is English (Chinese zh, English en, other languages ​​to be added)

### Create your own knowledge repository:

1.Place personal knowledge files or folders in the pilot/datasets directory.
Expand Down Expand Up @@ -239,8 +244,8 @@ This project is standing on the shoulders of giants and is not going to work wit

## Contributors

|[<img src="https://avatars.githubusercontent.com/u/17919400?v=4" width="100px;"/><br/><sub><b>csunny</b></sub>](https://github.com/csunny)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/7636723?s=96&v=4" width="100px;"/><br/><sub><b>明天</b></sub>](https://github.com/yhjun1026)<br/> | [<img src="https://avatars.githubusercontent.com/u/13723926?v=4" width="100px;"/><br/><sub><b>Aries-ckt</b></sub>](https://github.com/Aries-ckt)<br/>|[<img src="https://avatars.githubusercontent.com/u/95130644?v=4" width="100px;"/><br/><sub><b>thebigbone</b></sub>](https://github.com/thebigbone)<br/>|
| :---: | :---: | :---: | :---: |:---: |
|[<img src="https://avatars.githubusercontent.com/u/17919400?v=4" width="100px;"/><br/><sub><b>csunny</b></sub>](https://github.com/csunny)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/7636723?s=96&v=4" width="100px;"/><br/><sub><b>明天</b></sub>](https://github.com/yhjun1026)<br/> | [<img src="https://avatars.githubusercontent.com/u/13723926?v=4" width="100px;"/><br/><sub><b>Aries-ckt</b></sub>](https://github.com/Aries-ckt)<br/>|[<img src="https://avatars.githubusercontent.com/u/95130644?v=4" width="100px;"/><br/><sub><b>thebigbone</b></sub>](https://github.com/thebigbone)<br/>|[<img src="https://avatars.githubusercontent.com/u/26043513?v=4" width="100px;"/><br/><sub><b>Shinexy</b></sub>](https://github.com/xuyuan23)<br/> |
| :---: | :---: | :---: | :---: |:---: |:---: |


This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Fri May 19 2023 00:24:18 GMT+0800`.
Expand Down
7 changes: 5 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ $ python webserver.py
### 多模型使用
在.env 配置文件当中, 修改LLM_MODEL参数来切换使用的模型。

### 多语言用户界面模式
在.env 配置文件当中,修改LANGUAGE参数来切换使用不同的语言,默认是英文(中文zh, 英文en, 其他语言待补充)

### 打造属于你的知识库:

1.将个人知识文件或者文件夹放入pilot/datasets目录中
Expand Down Expand Up @@ -246,8 +249,8 @@ Run the Python interpreter and type the commands:

## 贡献者

|[<img src="https://avatars.githubusercontent.com/u/17919400?v=4" width="100px;"/><br/><sub><b>csunny</b></sub>](https://github.com/csunny)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/7636723?s=96&v=4" width="100px;"/><br/><sub><b>明天</b></sub>](https://github.com/yhjun1026)<br/> | [<img src="https://avatars.githubusercontent.com/u/13723926?v=4" width="100px;"/><br/><sub><b>Aries-ckt</b></sub>](https://github.com/Aries-ckt)<br/>|[<img src="https://avatars.githubusercontent.com/u/95130644?v=4" width="100px;"/><br/><sub><b>thebigbone</b></sub>](https://github.com/thebigbone)<br/>|
| :---: | :---: | :---: | :---: |:---: |
|[<img src="https://avatars.githubusercontent.com/u/17919400?v=4" width="100px;"/><br/><sub><b>csunny</b></sub>](https://github.com/csunny)<br/>|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/7636723?s=96&v=4" width="100px;"/><br/><sub><b>明天</b></sub>](https://github.com/yhjun1026)<br/> | [<img src="https://avatars.githubusercontent.com/u/13723926?v=4" width="100px;"/><br/><sub><b>Aries-ckt</b></sub>](https://github.com/Aries-ckt)<br/>|[<img src="https://avatars.githubusercontent.com/u/95130644?v=4" width="100px;"/><br/><sub><b>thebigbone</b></sub>](https://github.com/thebigbone)<br/>|[<img src="https://avatars.githubusercontent.com/u/26043513?v=4" width="100px;"/><br/><sub><b>Shinexy</b></sub>](https://github.com/xuyuan23)<br/> |
| :---: | :---: | :---: | :---: |:---: |:---: |


[git-contributor 说明](https://github.com/xudafeng/git-contributor),自动生成时间:`Fri May 19 2023 00:24:18 GMT+0800`
Expand Down
3 changes: 3 additions & 0 deletions pilot/configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class Config(metaclass=Singleton):
def __init__(self) -> None:
"""Initialize the Config class"""

# Gradio language version: en, cn
self.LANGUAGE = os.getenv("LANGUAGE", "en")

self.debug_mode = False
self.skip_reprompt = False
self.temperature = float(os.getenv("TEMPERATURE", 0.7))
Expand Down
15 changes: 9 additions & 6 deletions pilot/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uuid
from enum import auto, Enum
from typing import List, Any
from pilot.language.translation_handler import get_lang_text

from pilot.configs.config import Config

Expand Down Expand Up @@ -263,15 +264,17 @@ def gen_sqlgen_conversation(dbname):
default_conversation = conv_one_shot

conversation_sql_mode = {
"auto_execute_ai_response": "直接执行结果",
"dont_execute_ai_response": "不直接执行结果",
"auto_execute_ai_response": get_lang_text("sql_generate_mode_direct"),
"dont_execute_ai_response": get_lang_text("sql_generate_mode_none"),
}

conversation_types = {
"native": "LLM原生对话",
"default_knownledge": "默认知识库对话",
"custome": "新增知识库对话",
"auto_execute_plugin": "对话使用插件",
"native": get_lang_text("knowledge_qa_type_llm_native_dialogue"),
"default_knownledge": get_lang_text(
"knowledge_qa_type_default_knowledge_base_dialogue"
),
"custome": get_lang_text("knowledge_qa_type_add_knowledge_base_dialogue"),
"auto_execute_plugin": get_lang_text("dialogue_use_plugin"),
}

conv_templates = {
Expand Down
74 changes: 74 additions & 0 deletions pilot/language/lang_content_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## 短期内在该文件中配置,长期考虑将会存储在默认的数据库中存储,并可以支持多种语言的配置

lang_dicts = {
"zh": {
"unique_id": "中文内容",
"db_gpt_introduction": "[DB-GPT](https://github.com/csunny/DB-GPT) 是一个开源的以数据库为基础的GPT实验项目,使用本地化的GPT大模型与您的数据和环境进行交互,无数据泄露风险,100% 私密,100% 安全。",
"learn_more_markdown": "该服务是仅供非商业用途的研究预览。受 Vicuna-13B 模型 [License](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) 的约束",
"model_control_param": "模型参数",
"sql_generate_mode_direct": "直接执行结果",
"sql_generate_mode_none": "不直接执行结果",
"max_input_token_size": "最大输出Token数",
"please_choose_database": "请选择数据",
"sql_generate_diagnostics": "SQL生成与诊断",
"knowledge_qa_type_llm_native_dialogue": "LLM原生对话",
"knowledge_qa_type_default_knowledge_base_dialogue": "默认知识库对话",
"knowledge_qa_type_add_knowledge_base_dialogue": "新增知识库对话",
"dialogue_use_plugin": "对话使用插件",
"create_knowledge_base": "新建知识库",
"sql_schema_info": "数据库{}的Schema信息如下: {}\n",
"current_dialogue_mode": "当前对话模式",
"database_smart_assistant": "数据库智能助手",
"sql_vs_setting": "自动执行模式下, DB-GPT可以具备执行SQL、从网络读取知识自动化存储学习的能力",
"knowledge_qa": "知识问答",
"configure_knowledge_base": "配置知识库",
"new_klg_name": "新知识库名称",
"add_as_new_klg": "添加为新知识库",
"add_file_to_klg": "向知识库中添加文件",
"upload_file": "上传文件",
"add_file": "添加文件",
"upload_and_load_to_klg": "上传并加载到知识库",
"upload_folder": "上传文件夹",
"add_folder": "添加文件夹",
"send": "发送",
"regenerate": "重新生成",
"clear_box": "清理",
},
"en": {
"unique_id": "English Content",
"db_gpt_introduction": "[DB-GPT](https://github.com/csunny/DB-GPT) is an experimental open-source project that uses localized GPT large models to interact with your data and environment. With this solution, you can be assured that there is no risk of data leakage, and your data is 100% private and secure.",
"learn_more_markdown": "The service is a research preview intended for non-commercial use only. subject to the model [License](https://github.com/facebookresearch/llama/blob/main/MODEL_CARD.md) of Vicuna-13B",
"model_control_param": "Model Parameters",
"sql_generate_mode_direct": "Execute directly",
"sql_generate_mode_none": "Execute without model",
"max_input_token_size": "Maximum output token size",
"please_choose_database": "Please choose database",
"sql_generate_diagnostics": "SQL Generation & Diagnostics",
"knowledge_qa_type_llm_native_dialogue": "LLM native dialogue",
"knowledge_qa_type_default_knowledge_base_dialogue": "Default documents",
"knowledge_qa_type_add_knowledge_base_dialogue": "Added documents",
"dialogue_use_plugin": "Dialogue Extension",
"create_knowledge_base": "Create Knowledge Base",
"sql_schema_info": "the schema information of database {}: {}\n",
"current_dialogue_mode": "Current dialogue mode",
"database_smart_assistant": "Database smart assistant",
"sql_vs_setting": "In the automatic execution mode, DB-GPT can have the ability to execute SQL, read data from the network, automatically store and learn",
"knowledge_qa": "Documents QA",
"configure_knowledge_base": "Configure Documents",
"new_klg_name": "New document name",
"add_as_new_klg": "Add as new documents",
"add_file_to_klg": "Add file to documents",
"upload_file": "Upload file",
"add_file": "Add file",
"upload_and_load_to_klg": "Upload and load to documents",
"upload_folder": "Upload folder",
"add_folder": "Add folder",
"send": "Send",
"regenerate": "Regenerate",
"clear_box": "Clear",
},
}


def get_lang_content(key, language="zh"):
return lang_dicts.get(language, {}).get(key, "")
8 changes: 8 additions & 0 deletions pilot/language/translation_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pilot.configs.config import Config
from pilot.language.lang_content_mapping import get_lang_content

CFG = Config()


def get_lang_text(key):
return get_lang_content(key, CFG.LANGUAGE)
Loading

0 comments on commit d114d13

Please sign in to comment.