diff --git a/.env.template b/.env.template index 69840cb..71915ad 100644 --- a/.env.template +++ b/.env.template @@ -4,7 +4,7 @@ EMBEDDINGS_MODEL_NAME='infgrad/stella-large-zh-v2' #mongodb 配置 MONGODB_URI="mongodb://localhost:27017" MONGODB_DB_NAME='airda' -MONGODB_USERNAME='' +MONGODB_USERNAME='admin' MONGODB_PASSWORD='' # openai 配置 diff --git a/README.md b/README.md index b856002..97a6bc1 100644 --- a/README.md +++ b/README.md @@ -22,34 +22,82 @@ airda(Air Data Agent)是面向数据分析的多智能体,能够理解数据 - [ ] 任务规划 ## ✨ 快速开始 -### airda部署 -[https://www.yuque.com/biehuitou/dasgwp/gxii4gkkvudskf4k?singleDoc#](https://www.yuque.com/biehuitou/dasgwp/gxii4gkkvudskf4k?singleDoc#) 《airda部署》 -### 模型部署 -[https://www.yuque.com/biehuitou/dasgwp/nhvzgnpyq7cmy590?singleDoc#](https://www.yuque.com/biehuitou/dasgwp/nhvzgnpyq7cmy590?singleDoc#) 《模型部署》 -### 相关配置命令 -添加你的数据源 + +### 环境要求 + +Python>=3.10 + +### 安装 airda + +pip安装 + ``` -airda datasource add +pip install airda -i https://pypi.python.org/simple/ ``` -训练数据源的schema + +### 依赖安装 + +使用airda需要用到mongodb,可采用docker安装mongodb + ``` -airda datasource sync +#拉取mongo镜像 +docker pull mongo +docker run -itd --name mongo -v /{path_of_mongo_data}:/data/db -p 27017:27017 mongo + ``` -启用要使用的数据源 + +### 自定义配置 + +环境变量 + +下载https://github.com/hitsz-ids/airda/blob/main/.env.template文件,自定义embedding模型,mongo配置,以及openai配置 + ``` -airda datasource enable +airda env load -p {your_path}/.env_template ``` -禁用要使用的数据源 + +日志文件(非必须) + +下载https://github.com/hitsz-ids/airda/blob/main/log_config.yml.template文件,自定义日志配置 + ``` -airda datasource disable +airda log load -p {your_path}/log_config.yml.template +``` + + + +### 相关配置命令 + +添加你的数据源 +``` +airda datasource add -n {datasource_name} -h {host} -p {port} -k MYSQL -d {database} -u {username} -w {password} +#当前只支持kind为MYSQL的数据源 +``` +训练数据源的schema + +``` +airda datasource sync -n {datasource_name} ``` 查询当前可用的数据源 ``` airda datasource ls ``` +### 开始问答 + +``` +airda run cli -n {datasource_name} +#输入你的问题: +``` + + + + + + ## 👏 贡献 + 我们欢迎各种贡献和建议,共同努力,使本项目更上一层楼!麻烦遵循以下步骤: - **步骤1:** 如果您想添加任何额外的功能、增强功能或在使用过程中遇到任何问题,请发布一个 [问题](https://github.com/hitsz-ids/SQLAgent/issues) 。如果您能遵循 [问题模板](https://github.com/hitsz-ids/SQLAgent/issues/1) 我们将不胜感激。问题将在那里被讨论和分配。 diff --git a/airda/agent/action/searcher.py b/airda/agent/action/searcher.py index d0845ee..49f23ca 100644 --- a/airda/agent/action/searcher.py +++ b/airda/agent/action/searcher.py @@ -19,6 +19,7 @@ class SearcherParams(BaseModel, ActionParams): question: str + datasource_name: str class SearcherResult(BaseModel, ActionResult): @@ -48,11 +49,11 @@ def execute(self, context: "Context") -> SearcherResult: datasource_repository = data_agent_context.get_repository(StorageKey.DATASOURCE).convert( DatasourceRepository ) - datasource = datasource_repository.find_enable() + datasource = datasource_repository.find_one(self.params.datasource_name) if datasource is None: logger.debug("No datasource found") return SearcherResult( - knowledge="", tables_description="", tables_schema="", few_shot_example="" + knowledge="", tables_description="", tables_schema="", few_shot_example="", kind="" ) limit_score_result, top_k_result = data_agent_context.get_rag().search( self.params.question, datasource.id, datasource.database diff --git a/airda/agent/assistants/sql_assistant/sql_assistant.py b/airda/agent/assistants/sql_assistant/sql_assistant.py index dccb4f9..885de3b 100644 --- a/airda/agent/assistants/sql_assistant/sql_assistant.py +++ b/airda/agent/assistants/sql_assistant/sql_assistant.py @@ -28,6 +28,7 @@ class SqlAssistantParams(BaseModel, AssistantParams): question: str + datasource_name: str class SqlAssistant(Assistant[SqlAssistantParams]): diff --git a/airda/agent/planner/data_agent_planner_params.py b/airda/agent/planner/data_agent_planner_params.py index 2ac1a1a..949be3c 100644 --- a/airda/agent/planner/data_agent_planner_params.py +++ b/airda/agent/planner/data_agent_planner_params.py @@ -6,3 +6,4 @@ class DataAgentPlannerParams(BaseModel, PlannerParams, PipelineParams): question: str + datasource_name: str diff --git a/airda/cli/startup.py b/airda/cli/startup.py index 69714d7..d25ed72 100644 --- a/airda/cli/startup.py +++ b/airda/cli/startup.py @@ -24,7 +24,6 @@ { "prompt": "bold #a68a0d", "output": "#3993d4", - "enabled": "#5c962c", "success": "#4fc414", "error": "#f0524f bold", } @@ -71,13 +70,20 @@ def run(): @run.command() -def cli(): +@click.option( + "-n", + "--name", + type=str, + required=True, + help="数据源名称", +) +def cli(name: str): context = DataAgent().run() while True: user_input = session.prompt("输入你的问题:") if user_input.lower() == "exit": break - params = {"question": "查询任务列表"} + params = {"question": user_input, "datasource_name": name} pipeline = context.plan(DataAgentPlannerParams(**params)) async def execute(): @@ -235,46 +241,6 @@ def ls(): output_colored_text("========================", color) -@datasource.command(help="指定Agent使用的数据源") -@click.option( - "-n", - "--name", - type=str, - required=True, - help="数据源名称", -) -def enable(name: str): - context = DataAgent(DataAgentKey.STORAGE).run() - datasource_repository = context.get_repository(StorageKey.DATASOURCE).convert( - DatasourceRepository - ) - success = datasource_repository.enable(name) - if success: - output_colored_text("执行成功", "success") - else: - output_colored_text(f"执行失败, [{name}]数据源不存在", "error") - - -@datasource.command(help="取消Agent使用的数据源") -@click.option( - "-n", - "--name", - type=str, - required=True, - help="数据源名称", -) -def disable(name: str): - context = DataAgent(DataAgentKey.STORAGE).run() - datasource_repository = context.get_repository(StorageKey.DATASOURCE).convert( - DatasourceRepository - ) - success = datasource_repository.disable(name) - if success: - output_colored_text("执行成功", "success") - else: - output_colored_text(f"执行失败, [{name}]数据源不存在", "error") - - @datasource.command(help="删除已存在的数据源") @click.option( "-n", diff --git a/airda/connector/mysql.py b/airda/connector/mysql.py index 55927b1..13cb992 100644 --- a/airda/connector/mysql.py +++ b/airda/connector/mysql.py @@ -29,6 +29,7 @@ def __init__(self, datasource: Datasource, context: "DataAgentContext"): "user": datasource.username, "password": datasource.password, "host": datasource.host, + "port": datasource.port, "database": datasource.database, } ) diff --git a/log_config.yml.template b/log_config.yml.template index 0eb70ae..ba9cb78 100644 --- a/log_config.yml.template +++ b/log_config.yml.template @@ -25,7 +25,7 @@ loggers: level: INFO propagate: false handlers: [ console ] - data_agent: + airda: level: INFO propagate: false handlers: [ console ]