Skip to content

Commit

Permalink
Merge pull request #11 from hitsz-ids/developing
Browse files Browse the repository at this point in the history
Developing
  • Loading branch information
iokk3732 authored Apr 26, 2024
2 parents 7b95001 + a9fdd51 commit 14c5e0e
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 配置
Expand Down
74 changes: 61 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) 我们将不胜感激。问题将在那里被讨论和分配。
Expand Down
5 changes: 3 additions & 2 deletions airda/agent/action/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

class SearcherParams(BaseModel, ActionParams):
question: str
datasource_name: str


class SearcherResult(BaseModel, ActionResult):
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions airda/agent/assistants/sql_assistant/sql_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

class SqlAssistantParams(BaseModel, AssistantParams):
question: str
datasource_name: str


class SqlAssistant(Assistant[SqlAssistantParams]):
Expand Down
1 change: 1 addition & 0 deletions airda/agent/planner/data_agent_planner_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

class DataAgentPlannerParams(BaseModel, PlannerParams, PipelineParams):
question: str
datasource_name: str
52 changes: 9 additions & 43 deletions airda/cli/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
{
"prompt": "bold #a68a0d",
"output": "#3993d4",
"enabled": "#5c962c",
"success": "#4fc414",
"error": "#f0524f bold",
}
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions airda/connector/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
Expand Down
2 changes: 1 addition & 1 deletion log_config.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ loggers:
level: INFO
propagate: false
handlers: [ console ]
data_agent:
airda:
level: INFO
propagate: false
handlers: [ console ]
Expand Down

0 comments on commit 14c5e0e

Please sign in to comment.