Skip to content

Commit

Permalink
Fix/update readme (#26)
Browse files Browse the repository at this point in the history
* add tutorials and paper in readme

* add dataset and model link

* add training framework in readme

* add news section

* upload MSAgent-Bench image

* add contact

* add how to use modelscope notebook

* add new model

* update model

---------

Co-authored-by: 拿辰 <lcl193798@alibaba-inc.com>
  • Loading branch information
lcl6679292 and 拿辰 authored Sep 14, 2023
1 parent eaf9db5 commit cb5d177
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 37 deletions.
104 changes: 93 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<p>

<p align="center">
<a href="https://modelscope.cn/home">Modelscope Hub</a>
<a href="https://modelscope.cn/home">Modelscope Hub</a> | <a href="https://arxiv.org/abs/2309.00986">Paper</a> | <a href="https://modelscope.cn/studios/damo/ModelScopeGPT/summary">Demo</a>
<br>
<a href="README_CN.md">中文</a>&nbsp | &nbspEnglish
</p>

## Introduction

**ModelScope-Agent**, a general and customizable agent framework for real-world applications, based on open-source LLMs as controllers. It provides a user-friendly system library that are:
- **cutomizable and comprehensive framework**: customizable engine design to spanning over tool-use data collection, tool retrieval, tool registration, memory control, customized model training, and evaluation for practical real-world applications.
- **opensourced LLMs as controllers**: support model training on multiple open-source LLMs of ModelScope Community
Expand All @@ -22,6 +23,14 @@

To equip the LLMs with tool-use abilities, a comprehensive framework has been proposed spanning over tool-use data collection, tool retrieval, tool registration, memory control, customized model training, and evaluation for practical real-world applications.

## News

* Sep 4, 2023: Three demos, [demo_qwen](demo/demo_qwen_agent.ipynb), [demo_retrieval_agent](demo/demo_retrieval_agent.ipynb) and [demo_register_tool](demo/demo_register_new_tool.ipynb), have been added, along with detailed tutorials provided.
* Sep 2, 2023: The [preprint paper](https://arxiv.org/abs/2309.00986) associated with this project was published.
* Aug 22, 2023: Support accessing various AI model APIs using ModelScope tokens.
* Aug 7, 2023: The initial version of the modelscope-agent repository was released.


## Installation

clone repo and install dependency:
Expand All @@ -30,10 +39,22 @@ git clone https://github.com/modelscope/modelscope-agent.git
cd modelscope-agent && pip install -r requirements.txt
```

### ModelScope notebook【recommended】

The ModelScope Notebook offers a free-tier that allows ModelScope user to run the FaceChain application with minimum setup, refer to [ModelScope Notebook](https://modelscope.cn/my/mynotebook/preset)

```shell
# Step1: 我的notebook -> PAI-DSW -> GPU环境

# Step2: Download the [demo file](https://github.com/modelscope/modelscope-agent/blob/master/demo/demo_qwen_agent.ipynb) and upload it to the GPU.

# Step3: Execute the demo notebook in order.
```


## Quickstart

To use modelscope-agent, all you need is to instantiate an `AgentExecutor` object, and use `run()` to execute your task. For faster agent implementation, please refer to [demo_agent](demo/demo_qwen_agent.ipynb)
To use modelscope-agent, all you need is to instantiate an `AgentExecutor` object, and use `run()` to execute your task. For faster agent implementation, please refer to [demo_agent](demo/demo_qwen_agent.ipynb). Online demo is available on [ModelScope](https://modelscope.cn/studios/damo/ModelScopeGPT/summary)

```Python
import os
Expand All @@ -50,7 +71,7 @@ tool_cfg = Config.from_file(tool_cfg_file)


# instantiation LLM
model_name = 'modelscope-agent-qwen-7b'
model_name = 'modelscope-agent-7b'
llm = LLMFactory.build_llm(model_name, model_cfg)

# prompt generator
Expand Down Expand Up @@ -114,7 +135,7 @@ Concretely, We provide an `.env.template` file and corresponding config files in
### LLM
We offer a plug-and-play LLM for users to easily utilize. The specific model details are as follows:

* modelscope-agent-qwen-7b: [modelscope-agent-qwen-7b](https://modelscope.cn/models/damo/MSAgent-Qwen-7B/summary) is a core open-source model that drives the ModelScope-Agent framework, fine-tuned based on Qwen-7B. It can be directly downloaded for local use.
* modelscope-agent-7b: [modelscope-agent-7b](https://modelscope.cn/models/damo/ModelScope-Agent-7B/summary) is a core open-source model that drives the ModelScope-Agent framework. It can be directly downloaded for local use.
* modelscope-agent: A ModelScope-Agent service deployed on [DashScope](http://dashscope.aliyun.com). No local GPU resources are required. Follow the steps below to apply for the use of modelscope-agent:
1. Apply to activate the DashScope service, go to `模型广场` -> `通义千问开源系列` -> apply for a trial of `通义千问7B`. The free quota is 100,000 tokens.
2. Create an API-KEY in `API-kEY管理`, and configure it in the `config/.env` file.
Expand All @@ -136,12 +157,12 @@ from modelscope.utils.config import Config
from modelscope_agent.llm import LLMFactory
from modelscope_agent.agent import AgentExecutor

model_name = 'modelscope-agent-qwen-7b'
model_name = 'modelscope-agent-7b'
model_cfg = {
'modelscope-agent-qwen-7b':{
'modelscope-agent-7b':{
'type': 'modelscope',
'model_id': 'damo/MSAgent-Qwen-7B',
'model_revision': 'v1.0.2',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
Expand Down Expand Up @@ -236,13 +257,74 @@ print(shell_tool(commands=["echo 'Hello World!'", "ls"]))

```

## Training Framework

We provide a training framework in the [demo/tool_agent_finetune_swift](demo/tool_agent_finetune_swift), which mainly integrates the [SWIFT](https://github.com/modelscope/swift) training framework from ModelScope. Additionally, we release a large-scale tool instruction fine-tuning dataset MSAgent-Bench.

### MSAgent-Bench
[MSAgent-Bench](https://modelscope.cn/datasets/damo/MSAgent-Bench/summary), which is a comprehensive tool dataset encompassing 598k dialogues, including Common API, Model API, API-Oriented QA, and API-agnostic Instructions. You can directly download it on the dataset [link](https://modelscope.cn/datasets/damo/MSAgent-Bench/files) or access it through sdk:

```python
from modelscope.msdatasets import MsDataset

ds = MsDataset.load('damo/MSAgent-Bench', split='train')
one_ds = next(iter(ds))
```

![image](resource/MSAgent-Bench.png)

### Training

The training samples are orgnized in the following format, the content included between <|startofthink|> and <|endofthink|> represents the generated API request. The content included between <|startofexec|> and <|endofexec|> represents the API execution result.

```json
{
"id":"MS_Agent_Bench_20",
"conversations":[
{
"from":"system",
"value": "你是达摩院xxxx"
},
{
"from":"user",
"value":"按照给定的schema抽取出下面文本对应的信息\nschema:{\"人物\": null, \"地理位置\": null, \"组织机构\": null}\n近日,美国政府宣布将对中国1000多种商品加征关税,并威胁进一步加征关税。"
},
{
"from":"assistant",
"value":"<|startofthink|>```JSON\n{\"api_name\": \"modelscope_text-ie\", \"url\": \"http://9.32.64.200:5873/damo/nlp_structbert_siamese-uie_chinese-base\", \"parameters\": {\"text\": \"近日,美国政府宣布将对中国1000多种商品加征关税,并威胁进一步加征关税。\", \"schema\": \"{\\\"人物\\\": null, \\\"地理位置\\\": null, \\\"组织机构\\\": null}\"}}\n```<|endofthink|>\n\n<|startofexec|>```JSON\n{\"人物\": [], \"地理位置\": [\"中国\", \"美国\"], \"组织机构\": []}\n```<|endofexec|>\n信息抽取结果:{\"人物\": [], \"地理位置\": [\"中国\", \"美国\"], \"组织机构\": []}。"
}
]
}
```

Execute the training script.

```
cd demo/tool_agent_finetune_swift
PYTHONPATH=./ bash scripts/train/run_qwen_ddp.sh
```


## Related Tutorials

If you would like to learn more about the practical details of Agent, you can refer to our articles and video tutorials:

* [Article Tutorial](https://mp.weixin.qq.com/s/L3GiV2QHeybhVZSg_g_JRw)
* [Video Tutorial](https://b23.tv/AGIzmHM)

## Share Your Agent

We appreciate your enthusiasm in participating in our open-source ModelScope-Agent project. If you encounter any issues, please feel free to report them to us. If you have built a new Agent demo and are ready to share your work with us, please create a pull request at any time! If you need any further assistance, please contact us via email at [contact@modelscope.cn](mailto:contact@modelscope.cn) or [communication group](https://modelscope.cn/docs/%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC)!

## Citation
If you found this work useful, consider giving this repository a star and citing our paper as followed:
```
@misc{modelscope-agent,
@misc{li2023modelscopeagent,
title={ModelScope-Agent: Building Your Customizable Agent System with Open-source Large Language Models},
howpublished = {\url{https://github.com/ModelScope/modelscope-agent}},
year={2023}
author={Chenliang Li and Hehong Chen and Ming Yan and Weizhou Shen and Haiyang Xu and Zhikai Wu and Zhicheng Zhang and Wenmeng Zhou and Yingda Chen and Chen Cheng and Hongzhu Shi and Ji Zhang and Fei Huang and Jingren Zhou},
year={2023},
eprint={2309.00986},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```
106 changes: 95 additions & 11 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p>

<p align="center">
<a href="https://modelscope.cn/home">魔搭社区</a>
<a href="https://modelscope.cn/home">魔搭社区</a> | <a href="https://arxiv.org/abs/2309.00986">论文</a> | <a href="https://modelscope.cn/studios/damo/ModelScopeGPT/summary">Demo体验</a>
<br>
中文&nbsp | &nbsp<a href="README.md">English</a>
</p>
Expand All @@ -23,6 +23,13 @@

为了赋予LLMs工具使用能力,提出了一个全面的框架,涵盖了数据收集、工具检索、工具注册、存储管理、定制模型训练和实际应用的方方面面。

## 新闻

* 2023.9.4: 三个基于Agent开发的应用,[demo_qwen](demo/demo_qwen_agent.ipynb), [demo_retrieval_agent](demo/demo_retrieval_agent.ipynb) and [demo_register_tool](demo/demo_register_new_tool.ipynb) 已添加,并提供了详细的教程。
* 2023.9.2: 与该项目相关的[论文](https://arxiv.org/abs/2309.00986) 已发布到arxiv。
* 2023.8.22: 支持使用 ModelScope 令牌访问各种 AI 模型 API。
* 2023.8.7: modelscope-lagent仓库的初始版本已发布。

## 安装

克隆repo并安装依赖:
Expand All @@ -32,11 +39,26 @@ cd modelscope-agent && pip install -r requirements.txt
```


### 使用ModelScope提供的notebook环境【推荐】
ModelScope(魔搭社区)提供给新用户初始的免费计算资源,参考[ModelScope Notebook](https://modelscope.cn/my/mynotebook/preset)

Notebook环境使用简单,您只需要按以下步骤操作(注意:目前暂不提供永久存储,实例重启后数据会丢失):

```shell
# Step1: 我的notebook -> PAI-DSW -> GPU环境

# Step2: 下载[demo文件](https://github.com/modelscope/modelscope-agent/blob/master/demo/demo_qwen_agent.ipynb)并把它上传到打开的notebook机器上

# Step3: 按顺序执行demo里面的代码块
```



## 快速入门

使用 ModelScope-Agent,您只需要实例化一个 `AgentExecutor` 对象,并使用 `run()` 来执行您的任务即可。

如下简单示例,更多细节可参考[demo_agent](demo/demo_qwen_agent.ipynb)
如下简单示例,更多细节可参考[demo_agent](demo/demo_qwen_agent.ipynb)也可通过魔搭社区在线Demo直接体验[ModelScope](https://modelscope.cn/studios/damo/ModelScopeGPT/summary).

```Python
import os
Expand All @@ -52,7 +74,7 @@ tool_cfg_file = os.getenv('TOOL_CONFIG_FILE', 'config/cfg_tool_template.json')
tool_cfg = Config.from_file(tool_cfg_file)

# instantiation LLM
model_name = 'modelscope-agent-qwen-7b'
model_name = 'modelscope-agent-7b'
llm = LLMFactory.build_llm(model_name, model_cfg)

# prompt generator
Expand Down Expand Up @@ -120,7 +142,7 @@ agent.run('给这个故事配一张图', remote=True)
### LLM

我们提供了开箱即用的LLM方便用户使用,具体模型如下:
* modelscope-agent-qwen-7b: [modelscope-agent-qwen-7b](https://modelscope.cn/models/damo/MSAgent-Qwen-7B/summary)是基于Qwen-7B基础上微调训练后的,驱动ModelScope-Agent框架的核心开源模型,可以直接下载到本地使用。
* modelscope-agent-7b: [modelscope-agent-7b](https://modelscope.cn/models/damo/ModelScope-Agent-7B/summary)是驱动ModelScope-Agent框架的核心开源模型,可以直接下载到本地使用。
* modelscope-agent: 部署在[DashScope](http://dashscope.aliyun.com)上的ModelScope-Agent服务,不需要本地GPU资源,在DashScope平台执行如下操作:
1. 申请开通DashScope服务,进入`模型广场`-> `通义千问开源系列` -> 申请试用`通义千问7B`, 免费额度为10万token
2. `API-kEY管理`中创建API-KEY,在`config/.env`文件中配置
Expand All @@ -140,12 +162,12 @@ from modelscope.utils.config import Config
from modelscope_agent.llm import LLMFactory
from modelscope_agent.agent import AgentExecutor

model_name = 'modelscope-agent-qwen-7b'
model_name = 'modelscope-agent-7b'
model_cfg = {
'modelscope-agent-qwen-7b':{
'modelscope-agent-7b':{
'type': 'modelscope',
'model_id': 'damo/MSAgent-Qwen-7B',
'model_revision': 'v1.0.2',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
Expand Down Expand Up @@ -244,12 +266,74 @@ print(shell_tool(commands=["echo 'Hello World!'", "ls"]))

```

## 训练框架

我们在[demo/tool_agent_finetune_swift](demo/tool_agent_finetune_swift)中提供了一个开源大模型训练框架,主要集成了来自ModelScope的SWIFT训练框架。此外,我们还发布了一个大规模的工具指令微调数据集MSAgent-Bench。

### MSAgent-Bench数据集

[MSAgent-Bench](https://modelscope.cn/datasets/damo/MSAgent-Bench/summary)是一个包含598k个对话的综合工具数据集,包括通用API、模型API、面向API的问答和与API无关的指令。您可以直接在数据集[链接](https://modelscope.cn/datasets/damo/MSAgent-Bench/files)上下载它,或通过SDK访问:

```python
from modelscope.msdatasets import MsDataset

ds = MsDataset.load('damo/MSAgent-Bench', split='train')
one_ds = next(iter(ds))
```

![image](resource/MSAgent-Bench.png)

### 训练微调

训练样本可以组织成以下形式,其中:<|startofthink|>和<|endofthink|>之间包含的是API请求生成内容,<|startofexec|>和<|endofexec|>之间包含的是API执行结果。

```json
{
"id":"MS_Agent_Bench_20",
"conversations":[
{
"from":"system",
"value": "你是达摩院xxxx"
},
{
"from":"user",
"value":"按照给定的schema抽取出下面文本对应的信息\nschema:{\"人物\": null, \"地理位置\": null, \"组织机构\": null}\n近日,美国政府宣布将对中国1000多种商品加征关税,并威胁进一步加征关税。"
},
{
"from":"assistant",
"value":"<|startofthink|>```JSON\n{\"api_name\": \"modelscope_text-ie\", \"url\": \"http://9.32.64.200:5873/damo/nlp_structbert_siamese-uie_chinese-base\", \"parameters\": {\"text\": \"近日,美国政府宣布将对中国1000多种商品加征关税,并威胁进一步加征关税。\", \"schema\": \"{\\\"人物\\\": null, \\\"地理位置\\\": null, \\\"组织机构\\\": null}\"}}\n```<|endofthink|>\n\n<|startofexec|>```JSON\n{\"人物\": [], \"地理位置\": [\"中国\", \"美国\"], \"组织机构\": []}\n```<|endofexec|>\n信息抽取结果:{\"人物\": [], \"地理位置\": [\"中国\", \"美国\"], \"组织机构\": []}。"
}
]
}
```

执行下面这个脚本训练模型

```
cd demo/tool_agent_finetune_swift
PYTHONPATH=./ bash scripts/train/run_qwen_ddp.sh
```

## 相关教程

如果您还想进一步了解Agent细节,可以参考我们的文章和视频教程

* [文章教程](https://mp.weixin.qq.com/s/L3GiV2QHeybhVZSg_g_JRw)
* [视频教程](https://b23.tv/AGIzmHM)

## 分享您的Agent

我们感谢您对参与我们的开源ModelScope-Agent项目的热情。如果您遇到任何问题,请随时向我们提问。如果您已经构建了一个新的Agent Demo并准备与我们分享您的工作,请随时创建一个pull请求!如果您需要任何进一步的帮助,请邮件[contact@modelscope.cn](mailto:contact@modelscope.cn)或者交流群[联系我们](https://modelscope.cn/docs/%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC)

## 引用
如果您觉得这个工作很有用,请考虑给这个项目加星,并引用我们的论文,感谢:
```
@misc{modelscope-agent,
@misc{li2023modelscopeagent,
title={ModelScope-Agent: Building Your Customizable Agent System with Open-source Large Language Models},
howpublished = {\url{https://github.com/ModelScope/modelscope-agent}},
year={2023}
author={Chenliang Li and Hehong Chen and Ming Yan and Weizhou Shen and Haiyang Xu and Zhikai Wu and Zhicheng Zhang and Wenmeng Zhou and Yingda Chen and Chen Cheng and Hongzhu Shi and Ji Zhang and Fei Huang and Jingren Zhou},
year={2023},
eprint={2309.00986},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```
6 changes: 3 additions & 3 deletions config/cfg_model_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"type": "openai",
"model": "gpt-3.5-turbo"
},
"modelscope-agent-qwen-7b":{
"modelscope-agent-7b":{
"type": "modelscope",
"model_id": "damo/MSAgent-Qwen-7B",
"model_revision": "v1.0.2",
"model_id": "damo/ModelScope-Agent-7B",
"model_revision": "v1.0.0",
"use_raw_generation_config": true,
"custom_chat": true
}
Expand Down
Loading

0 comments on commit cb5d177

Please sign in to comment.