modelscope / modelscope-agent

ModelScope-Agent: An agent framework connecting models in ModelScope with the world
https://modelscope.cn/studios/agent
Apache License 2.0
2.2k stars 244 forks source link

[tool] openapi工具代码示例运行失败:TypeError: argument of type 'OpenAPIPluginTool' is not iterable #450

Closed jacnmm4 closed 1 month ago

jacnmm4 commented 1 month ago

Initial Checks

What happened + What you expected to happen

根据官方使用openapi的示例:https://github.com/modelscope/modelscope-agent/blob/master/examples/tools/openapi_schema_tool.ipynb,本地运行报错,相关的dashscopen已改为自己的,报错如下: 2024-05-21 12:10:04,212 - modelscope - INFO - PyTorch version 2.3.0 Found. 2024-05-21 12:10:04,217 - modelscope - INFO - TensorFlow version 2.16.1 Found. 2024-05-21 12:10:04,217 - modelscope - INFO - Loading ast index from C:\Users\Yang.cache\modelscope\ast_indexer 2024-05-21 12:10:04,363 - modelscope - INFO - Loading done! Current index file version is 1.12.0, with md5 bae340a52ccfa76c45f06e341a861891 and a total number of 964 components indexed import wanx-v1_text2image failed, details: 'wanx-v1_text2image' Traceback (most recent call last): File "D:\test2023\modelscope-agent310\openapi_test.py", line 209, in bot = RolePlay(function_list=function_list,llm=llm_config, instruction=role_template) File "D:\test2023\modelscope-agent310\venv\lib\site-packages\modelscope_agent\agents\role_play.py", line 144, in init Agent.init(self, function_list, llm, storage_path, name, File "D:\test2023\modelscope-agent310\venv\lib\site-packages\modelscope_agent\agent.py", line 53, in init self._register_tool(function) File "D:\test2023\modelscope-agent310\venv\lib\site-packages\modelscope_agent\agent.py", line 127, in _register_tool if tenant_id in tool_class_with_tenant and self.use_tool_api: TypeError: argument of type 'OpenAPIPluginTool' is not iterable

Versions / Dependencies

modelscope-agent版本:0.5.2

Reproduction script

schema_openAPI = { "schema": { "openapi":"3.1.0", "info":{ "title":"wanx-v1 Generation API", "description":"API for generating image with wanx-v1", "version":"v1.0.0" }, "servers":[ { "url":"https://dashscope.aliyuncs.com" } ], "paths":{ "/api/v1/services/aigc/text2image/image-synthesis":{ "post":{ "summary":"wanx-v1 text2image", "operationId":"wanx_v1_text2image", "tags":[ "wanx-v1 text2image" ], "requestBody":{ "required":True, "X-DashScope-Async":"enable", "content":{ "application/json":{ "schema":{ "$ref":"#/components/schemas/wanx_v1_text2imageRequest" } } } }, "responses":{ "200":{ "description":"Successful Response", "content":{ "application/json":{ "schema":{ "$ref":"#/components/schemas/wanx_v1_text2imageResponse" } } } } }, "security":[ { "BearerAuth":[] } ] } }, "/api/v1/tasks/{task_id}":{ "get":{ "summary":"Get Text2image Result", "operationId":"gettext2imageresult", "tags":[ "Get Result" ], "parameters":[ { "name":"task_id", "in":"path", "required":True, "description":"The unique identifier of the Text2image generation task", "schema":{ "type":"string" } } ], "security":[ { "BearerAuth":[] } ] } } }, "components":{ "schemas":{ "wanx_v1_text2imageRequest":{ "type":"object", "properties":{ "model":{ "type":"string", "enum":[ "wanx-v1" ] }, "input":{ "type":"object", "properties":{ "prompt":{ "type":"string", "example":"高清的,大师级的,4K,正面", "description":"描述画面的提示词信息", "required": True } } }, "parameters":{ "type":"object", "properties":{ "style":{ "type":"string", "example":"", "description":"输出图像的风格", "required": True, "enum":[ "", "<3d cartoon>", "", "", "", "", "", "" ] }, "size":{ "type":"string", "example":"10241024", "description":"生成图像的分辨率,默认为10241024像素", "required":True, "enum":[ "10241024", "7201280", "1280*720" ] }, "n":{ "type":"integer", "example":1, "description":"本次请求生成的图片数量", "required":True }, "seed":{ "type":"integer", "example":42, "description":"图片生成时候的种子值,取值范围为(0,4294967290)", "required":True } } } }, "required":[ "model", "input", "parameters" ] }, "wanx_v1_text2imageResponse":{ "type":"object", "properties":{ "output":{ "type":"string", "description":"Generated image URL or data." } } } }, "securitySchemes":{ "ApiKeyAuth":{ "type":"apiKey", "in":"header", "name":"Authorization" } } } }, "auth": { "type": "API Key", "apikey": "", # 这里填入API key "apikey_type": "Bearer" }, "privacy_policy": "" } from modelscope_agent.tools.openapi_plugin import openapi_schema_convert from modelscope.utils.config import Config from modelscope_agent.tools.base import TOOL_REGISTRY from modelscope_agent.tools.openapi_plugin import OpenAPIPluginTool

config_dict = openapi_schema_convert( schema=schema_openAPI["schema"], auth=schema_openAPI["auth"])

plugin_cfg = Config(config_dict)

function_list = []

for name, _ in plugin_cfg.items(): openapi_plugin_object = OpenAPIPluginTool(name=name, cfg=plugin_cfg) TOOL_REGISTRY[name] = openapi_plugin_object function_list.append(name)

from modelscope_agent.agents import RolePlay

role_template = '你扮演哆啦A梦小画家,你需要根据用户的要求用哆啦A梦的语气满足他们' llm_config = { 'model': 'qwen-max', 'model_server': 'dashscope', }

bot = RolePlay(function_list=function_list,llm=llm_config, instruction=role_template)

response = bot.run("哆啦A梦!帮我画一幅可爱的小女孩的照片", remote=False, print_info=True) text = '' for chunk in response: text += chunk print(text)

Issue Severity

None

zzhangpurdue commented 1 month ago

已经定位到问题,在修复,参考pr

jacnmm4 commented 1 month ago

已经定位到问题,在修复,参考pr

谢谢,参考pr是什么

zzhangpurdue commented 1 month ago

pr:https://github.com/modelscope/modelscope-agent/pull/451 已经合并到最新的master了,可以用master,或者等今明天发0.5.3版本。

zzhangpurdue commented 1 month ago

0.5.3 版本已验证修复