ModelScope-Agent-14B
模型简介
ModelScope-Agent是魔搭社区推出的智能体Agent框架。ModelScope-Agent-14B是驱动该Agent框架的核心模型。模型是基于Transformer的大语言模型, 在超大规模的预训练数据上进行训练得到。预训练数据类型多样,覆盖广泛,包括大量网络文本、专业书籍、代码等。在Qwen-14B模型的基础上,我们使用MSAgent-Bench数据集训练增强其作为Agent中枢的调用AI模型,工具和利用检索知识问答的能力。
如果您想了解更多关于ModelScope-Agent的细节,我们建议您参阅ModelScope-Agent Github代码库。
依赖项(Dependency)
运行请确保机器环境pytorch版本不低于1.12,再执行以下pip命令安装依赖库
pip install modelscope
pip install transformers_stream_generator
另外,推荐安装flash-attention
库,以实现更高的效率和更低的显存占用。
In addition, it is recommended to install the flash-attention
library for higher efficiency and lower memory usage.
git clone -b v1.0.8 https://github.com/Dao-AILab/flash-attention
cd flash-attention && pip install .
pip install csrc/layer_norm
pip install csrc/rotary
快速使用
下面我们展示了一个使用Model模型,进行多轮对话交互的样例(非流式):
from modelscope import AutoModelForCausalLM, AutoTokenizer
from modelscope import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("damo/ModelScope-Agent-14B", revision = 'v1.0.0',trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("damo/ModelScope-Agent-14B", revision = 'v1.0.0',device_map="auto", trust_remote_code=True,fp16=True).eval()
model.generation_config = GenerationConfig.from_pretrained("damo/ModelScope-Agent-14B",revision = 'v1.0.0', trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
system = """
<|system|>:当前对话可以使用的插件信息如下,请自行判断是否需要调用插件来解决当前用户问题。若需要调用插件,则需要将插件调用请求按
照json格式给出,必须包含api_name、url、parameters字段,并在其前后使用<|startofthink|>和<|endofthink|>作为标志。然后你需要根据插
件API调用结果生成合理的答复;若无需调用插件,则直接给出对应回复即可:
1. {"name": "modelscope_image-generation", "description": "图片生成服务,针对文本输入,生成对应的图片,插图等", "parameters": [{"name": "text", "description": "用户输入的文本信息", "required": true}]}
2. {"name": "modelscope_speech-generation", "description": "朗读文本内容,将文本转语音服务,将文字转换为自然而逼真的语音,可配置男声/女声", "parameters": [{"name": "input", "description": "要转成语音的文本", "required": true}, {"name": "gender", "description": "用户身份", "required": true}]}
"""
response, history = model.chat(tokenizer, "生成一张插图,关于狐狸和猎人的。", history=None, system=system)
print(response)
response, history = model.chat(tokenizer, "假如你是李清照,现在和我对话,你最喜欢的词是哪一首,语音回复我。", history=history, system=system)
print(response)
使用协议(License Agreement)
我们的代码和模型权重对学术研究完全开放,并支持商用。请查看LICENSE了解具体的开源协议细节。
Our code and checkpoints are open to research purpose, and they are allowed for commercial purposes. Check LICENSE for more details about the license.
评论