Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor with new framework #267

Merged
merged 125 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 112 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
9090538
update
wangyijunlyy Dec 2, 2023
3fce704
update
wangyijunlyy Dec 2, 2023
649c3ae
add style_repaint
wangyijunlyy Dec 12, 2023
3b48baf
恢复
wangyijunlyy Dec 12, 2023
5d73f22
恢复
wangyijunlyy Dec 12, 2023
9259188
解决合并冲突
wangyijunlyy Dec 12, 2023
e2c8a67
add style_repaint tool
wangyijunlyy Dec 12, 2023
c67430d
modify style_repaint
wangyijunlyy Dec 14, 2023
df77577
fix error
wangyijunlyy Dec 14, 2023
81ac82c
fix
wangyijunlyy Dec 14, 2023
cbe8236
fix rate limit
wangyijunlyy Dec 15, 2023
092a914
improve stability
wangyijunlyy Dec 15, 2023
b2ebd10
use dashscope to convert url
wangyijunlyy Dec 19, 2023
81866ff
update
wangyijunlyy Dec 19, 2023
a0cf87f
modify and better
wangyijunlyy Dec 19, 2023
6d29120
fix
wangyijunlyy Dec 19, 2023
f375ff0
refact framework: add base class for llm, tool, and agent
tuhahaha Jan 3, 2024
0d0dc8d
refact llm
tuhahaha Jan 4, 2024
31aeb30
refact llm for custom
tuhahaha Jan 4, 2024
4609cb2
add role_play agent
tuhahaha Jan 4, 2024
80cfa38
add unittest for role-play agent
tuhahaha Jan 4, 2024
b60db37
refactor/tool/image_gen
Jan 4, 2024
fd6537e
fix pre-commit
Jan 4, 2024
d4b68fc
add agent_builder agent
tuhahaha Jan 4, 2024
4689856
revert modelscope_agent/agent.py
Jan 5, 2024
b4bb3b8
Merge pull request #247 from suluyana/refactor/tool/image_gen
tuhahaha Jan 5, 2024
388e152
update agent and add react prompt
tuhahaha Jan 5, 2024
6cb1217
adapt agentbuilder in apps
tuhahaha Jan 8, 2024
41f6854
Merge remote-tracking branch 'upstream/refactor0103' into new_version
wangyijunlyy Jan 8, 2024
10c78f1
update style_repaint
wangyijunlyy Jan 8, 2024
4ad14ca
update style_repaint
wangyijunlyy Jan 8, 2024
053ad15
Merge pull request #250 from wangyijunlyy/new_version
tuhahaha Jan 8, 2024
b5f2a0b
change pipeline plugin tool (#248)
mushenL Jan 8, 2024
deba841
refactor ms agent
Jan 9, 2024
3e38201
save system to history
Jan 9, 2024
ddbf6e4
avoid duplicated system in roleplay
Jan 9, 2024
716aec8
builder with history running
Jan 9, 2024
079e85a
test case
wangyijunlyy Jan 9, 2024
5fbaf67
update tool
wangyijunlyy Jan 9, 2024
316931b
update
wangyijunlyy Jan 9, 2024
0c966d0
modify import method
wangyijunlyy Jan 9, 2024
812fe8d
Merge pull request #251 from wangyijunlyy/new_version
tuhahaha Jan 9, 2024
181b07d
code interpreter and knowledge
Jan 10, 2024
a3bf326
running code interpreter with file
Jan 10, 2024
c3efe6b
Refactor/citest (#257)
zzhangpurdue Jan 10, 2024
2a3b43d
add modelscope tool (#258)
mushenL Jan 11, 2024
7abdbd3
unittest-web search web browser
Jan 11, 2024
d968bf0
Merge branch 'refactor0103' of github.com:modelscope/modelscope-agent…
Jan 11, 2024
5dd2975
update tool and unittest
Jan 11, 2024
5346fe2
Refactor/gradio4 (#260)
suluyana Jan 12, 2024
9f97e1a
update reame and tool cfg
tuhahaha Jan 12, 2024
42f94cd
Merge branch 'refactor0103' of https://github.com/modelscope/modelsco…
tuhahaha Jan 12, 2024
92467e1
Refactor/unittest (#264)
zzhangpurdue Jan 13, 2024
ef7711f
Merge remote-tracking branch 'origin/master' into refactor0103
Jan 13, 2024
148a423
merge origin master
Jan 13, 2024
ace5831
fix bugs
Jan 13, 2024
17d9a0d
fix video-to-image
Jan 13, 2024
09dc91d
add qwen-max
Jan 15, 2024
408bd92
fix apps/agentfabric & update release version
Jan 15, 2024
fefdf54
apps/agentfabric/user_core.py
Jan 15, 2024
d0e11f1
fix pre-commit
Jan 15, 2024
79cfacc
Merge branch 'refactor0103' into release/0.3.0
Jan 15, 2024
2e72081
fix bugs & add video play for code interpreter
Jan 15, 2024
f5f4a89
comment out translate
Jan 15, 2024
3ccf308
Refactor log (#268)
lylalala Jan 15, 2024
9500ec7
Refactor/knowledgeretrieval (#271)
zzhangpurdue Jan 15, 2024
694154a
Merge remote-tracking branch 'origin/release/0.3.0' into refactor0103
Jan 15, 2024
5fce22c
add logger (#272)
zzhangpurdue Jan 15, 2024
36d250f
pass code unittest
Jan 15, 2024
7ecaf91
Merge branch 'release/0.3.0' into refactor0103
Jan 15, 2024
3b0f236
fix publish for missing MODELSCOPE_API_TOKEN alert & rm translation tool
Jan 16, 2024
8c8b611
fix bugs
Jan 16, 2024
deb2825
update log
Jan 16, 2024
93e2cda
fix bugs
Jan 17, 2024
c69bc5c
fix instruction
Jan 17, 2024
8437504
fix tool log
Jan 17, 2024
7dc36d1
fix bugs
Jan 19, 2024
a042aa0
fix pre-commit
Jan 19, 2024
517ff5f
Zhipu-glm4 (#276)
suluyana Jan 19, 2024
2bb40f3
add zhipuai to requirements.txt
Jan 19, 2024
caa1af9
make sure .md file is parsed by nltk
zzhangpurdue Jan 19, 2024
84c38e3
Update demo 20240118 (#275)
mushenL Jan 19, 2024
e671b63
add zhipuai
zzhangpurdue Jan 19, 2024
c23d191
Merge branch 'release/0.3.0' into refactor0103
zzhangpurdue Jan 21, 2024
be9777b
update retrieval knowledge logic to not load in agent fabric
zzhangpurdue Jan 22, 2024
53f92ca
update name
zzhangpurdue Jan 22, 2024
9097520
Merge branch 'release/0.3.0' of github.com:modelscope/modelscope-agen…
Jan 22, 2024
c275142
fix bugs
Jan 22, 2024
43ed672
fix pre-commit
Jan 22, 2024
5979950
fix ci
Jan 22, 2024
786a947
update max_token setting
zzhangpurdue Jan 22, 2024
2df7096
Merge remote-tracking branch 'origin/release/0.3.0' into release/0.3.0
zzhangpurdue Jan 22, 2024
da9e7e4
fix doc list extend method
zzhangpurdue Jan 23, 2024
6b91f14
fix ci
zzhangpurdue Jan 23, 2024
6388e69
fix ci
zzhangpurdue Jan 23, 2024
53d40c8
add docstr
tuhahaha Jan 24, 2024
befd8c5
rm useless agent: function call, react, react_chat
tuhahaha Jan 24, 2024
5ebc687
bugfix
tuhahaha Jan 24, 2024
1094f14
bugfix
tuhahaha Jan 24, 2024
5f7292e
bugfix: change _detect_tool for role_play
tuhahaha Jan 24, 2024
00515dc
remove uuid related log in ms
zzhangpurdue Jan 24, 2024
6c38563
fix publish avatar
Jan 25, 2024
6c1d023
version 0.3.0rc0
Jan 26, 2024
7e3bb66
fix bugs
zzhangpurdue Jan 26, 2024
938aac2
fix bug
Jan 26, 2024
bbc572b
fix audio->video
Jan 26, 2024
ad8abbc
Merge remote-tracking branch 'origin/release/0.3.0' into refactor0103
zzhangpurdue Jan 28, 2024
209d3da
update demo
zzhangpurdue Jan 30, 2024
e0a232a
bug fixed by comment
zzhangpurdue Jan 30, 2024
3a930ff
lint pass
zzhangpurdue Jan 30, 2024
82aefed
bug fixed
zzhangpurdue Jan 30, 2024
5cc2110
bug fixed
zzhangpurdue Jan 30, 2024
760d4dd
merge master
wenmengzhou Feb 3, 2024
df1415f
fix ci (not complete)
Feb 4, 2024
5d06ba4
add hf tool unit test
zzhangpurdue Feb 4, 2024
8a7451e
Openapi (#287)
suluyana Feb 4, 2024
db4354c
bug fixed
zzhangpurdue Feb 4, 2024
2287855
pass lint
zzhangpurdue Feb 4, 2024
ea81126
fix ci
Feb 5, 2024
858170c
update ci_env
Feb 5, 2024
dbe53a2
fix ci
Feb 5, 2024
53ffd1e
fix ci
Feb 5, 2024
3d696ad
fix pre-commit
Feb 5, 2024
e15391b
update ci
Feb 5, 2024
7808cc7
fix pre-commit
Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .dev_scripts/dockerci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash


# install dependencies for ci
pip install torch
export CODE_INTERPRETER_WORK_DIR=${GITHUB_WORKSPACE}
echo "${CODE_INTERPRETER_WORK_DIR}"

# cp file
cp tests/samples/luoli15.jpg "${CODE_INTERPRETER_WORK_DIR}/luoli15.jpg"
ls "${CODE_INTERPRETER_WORK_DIR}"

# run ci
pytest
72 changes: 72 additions & 0 deletions .github/workflows/citest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: citest

on:
push:
branches:
- master
- "release/**"
paths-ignore:
- "setup.*"
- "requirements.txt"
- "apps/**"
- "docs/**"
- "demo/**"
- "config/**"
- "resource/**"
- "README.md"
- "README_zh-CN.md"
- "NOTICE"
- ".github/workflows/lint.yaml"

pull_request:
paths-ignore:
- "setup.*"
- "requirements.txt"
- "apps/**"
- "docs/**"
- "demo/**"
- "config/**"
- "resource/**"
- "README.md"
- "README_zh-CN.md"
- "NOTICE"
- ".github/workflows/lint.yaml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unittest:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 20
environment: testci
steps:
- uses: actions/checkout@v3

# - name: Cache Python dependencies
# uses: actions/cache@v3
# id: cache
# with:
# path: ~/.cache/pip
# key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}

- name: Set up Python 3.10.13
uses: actions/setup-python@v3
with:
python-version: "3.10.13"

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: pip install -r requirements.txt

- name: Run tests
env:
AMAP_TOKEN: ${{ secrets.AMAP_TOKEN }}
BING_SEARCH_V7_SUBSCRIPTION_KEY: ${{ secrets.BING_SEARCH_V7_SUBSCRIPTION_KEY }}
DASHSCOPE_API_KEY: ${{ secrets.DASHSCOPE_API_KEY }}
MODELSCOPE_API_TOKEN: ${{ secrets.MODELSCOPE_API_TOKEN }}

shell: bash
run: bash .dev_scripts/dockerci.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ wheels/
*.egg
/package
/temp
**/tmp/
/apps/agentfabric/tmp/
MANIFEST

# PyInstaller
Expand Down
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
recursive-include modelscope_agent/tools/code_interpreter_utils *.ttf
recursive-include modelscope_agent/tools/code_interpreter *.ttf
recursive-include modelscope_agent/utils *.tiktoken
recursive-include modelscope_agent/utils/nltk *.zip
73 changes: 35 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

## 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:
- **customizable 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
- **Diversified and Comprehensive APIs**: enabling seamless integration with both model APIs and common APIs in a unified way.
Modelscope-Agent is a customizable and scalable Agent framework. A single agent has abilities such as role-playing, LLM calling, tool usage, planning, and memory.
It mainly has the following characteristics:

![image](resource/modelscope-agent.png)
- **Simple Agent Implementation Process**: Simply specify the role instruction, LLM name, and tool name list to implement an Agent application. The framework automatically arranges workflows for tool usage, planning, and memory.
- **Rich models and tools**: The framework is equipped with rich LLM interfaces, such as Dashscope and Modelscope model interfaces, OpenAI model interfaces, etc. Built in rich tools, such as **code interpreter**, **weather query**, **text to image**, **web browsing**, etc., make it easy to customize exclusive agents.
- **Unified interface and high scalability**: The framework has clear tools and LLM registration mechanism, making it convenient for users to expand more diverse Agent applications.
- **Low coupling**: Developers can easily use built-in tools, LLM, memory, and other components without the need to bind higher-level agents.

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
* Nov 26, 2023: [AgentFabric](https://github.com/modelscope/modelscope-agent/tree/master/apps/agentfabric) now supports collaborative use in ModelScope's [Creation Space](https://modelscope.cn/studios/modelscope/AgentFabric/summary), allowing for the sharing of custom applications in the Creation Space. The update also includes the latest [GTE](https://modelscope.cn/models/damo/nlp_gte_sentence-embedding_chinese-base/summary) text embedding integration.
Expand Down Expand Up @@ -58,32 +58,28 @@ The ModelScope Notebook offers a free-tier that allows ModelScope user to run th

## 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). Online demo is available on [ModelScope](https://modelscope.cn/studios/damo/ModelScopeGPT/summary)
To use modelscope-agent, all you need is to instantiate an `Agent` 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the demo to agentfabric/agentscope


```Python
import os

from modelscope.utils.config import Config
from modelscope_agent.llm import LLMFactory
from modelscope_agent.agent import AgentExecutor

# get cfg from file, refer the example in config folder
model_cfg_file = os.getenv('MODEL_CONFIG_FILE', 'config/cfg_model_template.json')
model_cfg = Config.from_file(model_cfg_file)
tool_cfg_file = os.getenv('TOOL_CONFIG_FILE', 'config/cfg_tool_template.json')
tool_cfg = Config.from_file(tool_cfg_file)
from modelscope_agent.agents import RolePlay

# instantiation LLM
model_name = 'qwen-72b'
# config
role_template = '你扮演一个天气预报助手,你需要查询相应地区的天气,并调用给你的画图工具绘制一张城市的图。'
llm_config = {'model': 'qwen-max', 'model_server': 'dashscope'}
function_list = ['amap_weather', 'image_gen']

print('To use qwen-72b model, you need to enter DashScope Token, which can be obtained from here: 1. Register and log in to https://dashscope.aliyun.com 2. Open the model square and select Tongyi Qianwen 72b. It is expected to take half a day to pass')
os.environ['DASHSCOPE_API_KEY'] = input()
# init agent
bot = RolePlay(function_list=function_list, llm=llm_config, instruction=role_template)

llm = LLMFactory.build_llm(model_name, model_cfg)
# run agent
response = bot.run('朝阳区天气怎样?')

# instantiation agent
# result processing
text = ''
for chunk in response:
text += chunk
print(text)

agent = AgentExecutor(llm, tool_cfg)
```

- Single-step & Multi-step tool-use
Expand All @@ -101,8 +97,8 @@ agent.run('写一篇关于Vision Pro VR眼镜的20字宣传文案,并用女声
```

<div style="display: flex;">
<img src="resource/modelscopegpt_case_single-step.png" alt="Image 1" style="width: 45%;">
<img src="resource/modelscopegpt_case_video-generation.png" alt="Image 2" style="width: 45%;">
<img src="resources/modelscopegpt_case_single-step.png" alt="Image 1" style="width: 45%;">
<img src="resources/modelscopegpt_case_video-generation.png" alt="Image 2" style="width: 45%;">
</div>

- Multi-turn tool-use and knowledge-qa
Expand All @@ -116,8 +112,8 @@ agent.run('给这个故事配一张图', remote=True)
```

<div style="display: flex;">
<img src="resource/modelscopegpt_case_multi-turn.png" alt="Image 1" style="width: 45%;">
<img src="resource/modelscopegpt_case_knowledge-qa.png" alt="Image 2" style="width: 45%;">
<img src="resources/modelscopegpt_case_multi-turn.png" alt="Image 1" style="width: 45%;">
<img src="resources/modelscopegpt_case_knowledge-qa.png" alt="Image 2" style="width: 45%;">
</div>


Expand Down Expand Up @@ -166,13 +162,13 @@ from modelscope_agent.agent import AgentExecutor

model_name = 'modelscope-agent-7b'
model_cfg = {
'modelscope-agent-7b':{
'type': 'modelscope',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
'modelscope-agent-7b': {
'type': 'modelscope',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
}

tool_cfg_file = os.getenv('TOOL_CONFIG_FILE', 'config/cfg_tool_template.json')
Expand All @@ -197,6 +193,7 @@ from modelscope_agent.tools import ModelscopePipelineTool
from modelscope.utils.constant import Tasks
from modelscope_agent.output_wrapper import AudioWrapper


class TexttoSpeechTool(ModelscopePipelineTool):
default_model = 'damo/speech_sambert-hifigan_tts_zh-cn_16k'
description = '文本转语音服务,将文字转换为自然而逼真的语音,可配置男声/女声'
Expand All @@ -221,7 +218,6 @@ class TexttoSpeechTool(ModelscopePipelineTool):
return kwargs

def _parse_output(self, origin_result, remote=True):

audio = origin_result['output_wav']
return {'result': AudioWrapper(audio)}
```
Expand All @@ -232,6 +228,7 @@ class TexttoSpeechTool(ModelscopePipelineTool):
from modelscope_agent.tools import ModelscopePipelineTool
from modelscope.utils.constant import Tasks


class TextAddressTool(ModelscopePipelineTool):
default_model = 'damo/mgeo_geographic_elements_tagging_chinese_base'
description = '地址解析服务,针对中文地址信息,识别出里面的元素,包括省、市、区、镇、社区、道路、路号、POI、楼栋号、户室号等'
Expand Down Expand Up @@ -278,7 +275,7 @@ ds = MsDataset.load('damo/MSAgent-Bench', split='train')
one_ds = next(iter(ds))
```

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

### Training

Expand Down
72 changes: 34 additions & 38 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@

## 简介

**ModelScope-Agent**是一个通用的、可定制的Agent框架,用于实际应用程序,其基于开源的大语言模型 (LLMs) 作为核心。它提供了一个用户友好的系统库,
具有以下特点:
- **可定制且功能全面的框架**:提供可定制的引擎设计,涵盖了数据收集、工具检索、工具注册、存储管理、定制模型训练和实际应用等功能,可用于快速实现实际场景中的应用。
- **开源LLMs作为核心组件**:支持在 ModelScope 社区的多个开源LLMs上进行模型训练。
- **多样化且全面的API**:以统一的方式实现与模型API和常见的功能API的无缝集成。
Modelscope-Agent是一个可定制的、可扩展的Agent代码框架。单Agent具有角色扮演、LLM调用、工具使用、规划、记忆等能力。 主要具有以下特点:

![图片](resource/modelscope-agent.png)
- 简单的Agent实现流程:仅需指定角色描述、LLM名称、工具名列表,即可实现一个Agent应用,框架内部自动实现工具使用、规划、记忆等工作流的编排。
- 丰富的模型和工具:框架内置丰富的LLM接口,例如Dashscope和Modelscope模型接口,OpenAI模型接口等。内置丰富的工具,例如**代码运行**、**天气查询**、**文生图**、**网页解析**等,方便定制专属Agent。
- 统一的接口和高扩展性:框架具有清晰的工具、LLM注册机制,方便用户扩展能力更加丰富的Agent应用。
- 低耦合性:开发者可以方便的直接使用内置的工具、LLM、记忆等组件,而不需要绑定更上层的Agent。

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

## 新闻
* 2023.11.26: [AgentFabric](https://github.com/modelscope/modelscope-agent/tree/master/apps/agentfabric)支持ModelScope[创空间](https://modelscope.cn/studios/modelscope/AgentFabric/summary)多人使用,支持分享定制应用到创空间,更新到最新的[GTE](https://modelscope.cn/models/damo/nlp_gte_sentence-embedding_chinese-base/summary) text embedding。
Expand Down Expand Up @@ -60,34 +58,31 @@ Notebook环境使用简单,您只需要按以下步骤操作(注意:目前

## 快速入门

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

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

```Python
import os

from modelscope.utils.config import Config
from modelscope_agent.llm import LLMFactory
from modelscope_agent.agent import AgentExecutor
from modelscope_agent.agents import RolePlay

# get cfg from file, refer the example in config folder
model_cfg_file = os.getenv('MODEL_CONFIG_FILE', 'config/cfg_model_template.json')
model_cfg = Config.from_file(model_cfg_file)
tool_cfg_file = os.getenv('TOOL_CONFIG_FILE', 'config/cfg_tool_template.json')
tool_cfg = Config.from_file(tool_cfg_file)
# config
role_template = '你扮演一个天气预报助手,你需要查询相应地区的天气,并调用给你的画图工具绘制一张城市的图。'
llm_config = {'model': 'qwen-max', 'model_server': 'dashscope'}
function_list = ['amap_weather', 'image_gen']

# instantiation LLM
model_name = 'qwen-72b'
# init agent
bot = RolePlay(function_list=function_list, llm=llm_config, instruction=role_template)

print('To use qwen-72b model, you need to enter DashScope Token, which can be obtained from here: 1. Register and log in to https://dashscope.aliyun.com 2. Open the model square and select Tongyi Qianwen 72b. It is expected to take half a day to pass')
os.environ['DASHSCOPE_API_KEY'] = input()
# run agent
response = bot.run('朝阳区天气怎样?')

llm = LLMFactory.build_llm(model_name, model_cfg)
# result processing
text = ''
for chunk in response:
text += chunk
print(text)

# instantiation agent

agent = AgentExecutor(llm, tool_cfg)
```

- 单步 & 多步工具使用
Expand All @@ -105,8 +100,8 @@ agent.run('写一篇关于Vision Pro VR眼镜的20字宣传文案,并用女声
```

<div style="display: flex;">
<img src="resource/modelscopegpt_case_single-step.png" alt="Image 1" style="width: 45%;">
<img src="resource/modelscopegpt_case_video-generation.png" alt="Image 2" style="width: 45%;">
<img src="resources/modelscopegpt_case_single-step.png" alt="Image 1" style="width: 45%;">
<img src="resources/modelscopegpt_case_video-generation.png" alt="Image 2" style="width: 45%;">
</div>

- 多轮工具使用和知识问答
Expand All @@ -120,8 +115,8 @@ agent.run('给这个故事配一张图', remote=True)
```

<div style="display: flex;">
<img src="resource/modelscopegpt_case_multi-turn.png" alt="Image 1" style="width: 45%;">
<img src="resource/modelscopegpt_case_knowledge-qa.png" alt="Image 2" style="width: 45%;">
<img src="resources/modelscopegpt_case_multi-turn.png" alt="Image 1" style="width: 45%;">
<img src="resources/modelscopegpt_case_knowledge-qa.png" alt="Image 2" style="width: 45%;">
</div>

### 主要组件
Expand Down Expand Up @@ -173,13 +168,13 @@ from modelscope_agent.agent import AgentExecutor

model_name = 'modelscope-agent-7b'
model_cfg = {
'modelscope-agent-7b':{
'type': 'modelscope',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
'modelscope-agent-7b': {
'type': 'modelscope',
'model_id': 'damo/ModelScope-Agent-7B',
'model_revision': 'v1.0.0',
'use_raw_generation_config': True,
'custom_chat': True
}
}

tool_cfg_file = os.getenv('TOOL_CONFIG_FILE', 'config/cfg_tool_template.json')
Expand Down Expand Up @@ -208,6 +203,7 @@ from modelscope_agent.tools import ModelscopePipelineTool
from modelscope.utils.constant import Tasks
from modelscope_agent.output_wrapper import AudioWrapper


class TexttoSpeechTool(ModelscopePipelineTool):
default_model = 'damo/speech_sambert-hifigan_tts_zh-cn_16k'
description = '文本转语音服务,将文字转换为自然而逼真的语音,可配置男声/女声'
Expand All @@ -232,7 +228,6 @@ class TexttoSpeechTool(ModelscopePipelineTool):
return kwargs

def _parse_output(self, origin_result, remote=True):

audio = origin_result['output_wav']
return {'result': AudioWrapper(audio)}
```
Expand All @@ -243,6 +238,7 @@ class TexttoSpeechTool(ModelscopePipelineTool):
from modelscope_agent.tools import ModelscopePipelineTool
from modelscope.utils.constant import Tasks


class TextAddressTool(ModelscopePipelineTool):
default_model = 'damo/mgeo_geographic_elements_tagging_chinese_base'
description = '地址解析服务,针对中文地址信息,识别出里面的元素,包括省、市、区、镇、社区、道路、路号、POI、楼栋号、户室号等'
Expand Down Expand Up @@ -290,7 +286,7 @@ ds = MsDataset.load('damo/MSAgent-Bench', split='train')
one_ds = next(iter(ds))
```

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

### 训练微调

Expand Down
4 changes: 0 additions & 4 deletions apps/agentfabric/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
from .builder_prompt import BuilderPromptGenerator
from .builder_prompt_zh import ZhBuilderPromptGenerator
from .custom_prompt import CustomPromptGenerator
from .custom_prompt_zh import ZhCustomPromptGenerator
Loading
Loading