diff --git a/examples/tools/openapi_schema_tool.ipynb b/examples/tools/openapi_schema_tool.ipynb index 70817cdf..858827c2 100644 --- a/examples/tools/openapi_schema_tool.ipynb +++ b/examples/tools/openapi_schema_tool.ipynb @@ -173,7 +173,7 @@ " \"schemas\":{\n", " \"wanx_v1_text2imageRequest\":{\n", " \"type\":\"object\",\n", - " \"properties\":{\n", + " \"properties\":{\n", " \"model\":{\n", " \"type\":\"string\",\n", " \"enum\":[\n", @@ -283,24 +283,28 @@ "metadata": {}, "outputs": [], "source": [ - "from modelscope_agent.tools.openapi_plugin import openapi_schema_convert\n", - "from modelscope.utils.config import Config\n", + "import copy\n", + "from modelscope_agent.tools.base import OpenapiServiceProxy\n", "from modelscope_agent.tools.base import TOOL_REGISTRY\n", - "from modelscope_agent.tools.openapi_plugin import OpenAPIPluginTool\n", - "\n", - "\n", - "config_dict = openapi_schema_convert(\n", - " schema=schema_openAPI[\"schema\"],\n", - " auth=schema_openAPI[\"auth\"])\n", - "\n", - "plugin_cfg = Config(config_dict)\n", "\n", + "openapi_instance = OpenapiServiceProxy(openapi=schema_openAPI['schema'])\n", + "schema_info = copy.deepcopy(openapi_instance.api_info_dict)\n", + "for item in schema_info:\n", + " schema_info[item].pop('is_active')\n", + " schema_info[item].pop('is_remote_tool')\n", + " schema_info[item].pop('details')\n", + "print(schema_info)\n", + "print(openapi_instance.api_info_dict)\n", "function_list = []\n", - "\n", - "for name, _ in plugin_cfg.items():\n", - " openapi_plugin_object = OpenAPIPluginTool(name=name, cfg=plugin_cfg)\n", - " TOOL_REGISTRY[name] = openapi_plugin_object\n", - " function_list.append(name)" + "tool_names = openapi_instance.tool_names\n", + "for tool_name in tool_names:\n", + " openapi_instance_for_specific_tool = copy.deepcopy(openapi_instance)\n", + " openapi_instance_for_specific_tool.name = tool_name\n", + " function_plain_text = openapi_instance_for_specific_tool.parser_function_by_tool_name(\n", + " tool_name)\n", + " openapi_instance_for_specific_tool.function_plain_text = function_plain_text\n", + " TOOL_REGISTRY[tool_name] = openapi_instance_for_specific_tool\n", + " function_list.append(tool_name)" ] }, { @@ -320,9 +324,16 @@ "\n", "role_template = '你扮演哆啦A梦小画家,你需要根据用户的要求用哆啦A梦的语气满足他们'\n", "llm_config = {\n", - " 'model': 'qwen-max', \n", + " 'model': 'qwen-max',\n", " 'model_server': 'dashscope',\n", " }\n", + "kwargs = {}\n", + "kwargs[\"credentials\"] = \\\n", + "{\n", + " \"auth_type\": \"api_key\",\n", + " \"api_key_header\": \"Authorization\",\n", + " \"api_key_value\": \"\", # 这里填入API key\n", + "}\n", "\n", "bot = RolePlay(function_list=function_list,llm=llm_config, instruction=role_template)" ] @@ -340,31 +351,12 @@ "metadata": {}, "outputs": [], "source": [ - "response = bot.run(\"哆啦A梦!帮我画一幅可爱的小女孩的照片\", remote=False, print_info=True)\n", + "response = bot.run(\"哆啦A梦!帮我画一幅可爱的小女孩的照片\", remote=False, print_info=True, **kwargs)\n", "text = ''\n", "for chunk in response:\n", " text += chunk\n", "print(text)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import re\n", - "from IPython.display import Image, display\n", - "\n", - "# 使用正则表达式提取音频文件路径\n", - "match = re.search(r'!\\[.*?\\]\\((.*?)\\)', text)\n", - "if match:\n", - " audio_file_path = match.group(1)\n", - " audio = Image(url=audio_file_path)\n", - " display(audio)\n", - "else:\n", - " print(\"No audio file found in the observation string.\")" - ] } ], "metadata": {