Skip to content

Commit

Permalink
Merge pull request #122 from wangyijunlyy/ww
Browse files Browse the repository at this point in the history
add yijun modify
  • Loading branch information
lylalala authored Nov 27, 2023
2 parents 879aaae + bba61df commit 4888c9a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 318 deletions.
2 changes: 1 addition & 1 deletion apps/agentfabric/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict

import json
from modelscope_agent.tools.openapi_plugin import (OpenAPISchemaTool,
from modelscope_agent.tools.openapi_plugin import (OpenAPIPluginTool,
openapi_schema_convert)

from modelscope.utils.config import Config
Expand Down
4 changes: 2 additions & 2 deletions apps/agentfabric/user_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from modelscope_agent.agent_types import AgentType
from modelscope_agent.llm import LLMFactory
from modelscope_agent.retrieve import KnowledgeRetrieval
from modelscope_agent.tools.openapi_plugin import (OpenAPISchemaTool,
from modelscope_agent.tools.openapi_plugin import (OpenAPIPluginTool,
openapi_schema_convert)


Expand Down Expand Up @@ -74,7 +74,7 @@ def init_user_chatbot_agent(uuid_str=''):
def add_openapi_plugin_to_additional_tool(plugin_cfgs, available_plugin_list):
additional_tool_list = {}
for name, cfg in plugin_cfgs.items():
openapi_plugin_object = OpenAPISchemaTool(name=name, cfg=plugin_cfgs)
openapi_plugin_object = OpenAPIPluginTool(name=name, cfg=plugin_cfgs)
additional_tool_list[name] = openapi_plugin_object
return additional_tool_list

Expand Down
44 changes: 28 additions & 16 deletions modelscope_agent/tools/openapi_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ToolSchema(BaseModel):
parameters: List[ParametersSchema]


class OpenAPISchemaTool(Tool):
class OpenAPIPluginTool(Tool):
"""
openapi schema tool
"""
Expand Down Expand Up @@ -115,6 +115,8 @@ def _remote_call(self, *args, **kwargs):
retry_times -= 1
try:
print('GET:', new_url)
print('GET:', self.url)

response = requests.request(
'GET',
url=new_url,
Expand Down Expand Up @@ -194,22 +196,30 @@ def parse_nested_parameters(param_name, param_info, parameters_list, content):
# If the argument type is an object and has a non-empty "properties" field,
# its internal properties are parsed recursively
for inner_param_name, inner_param_info in properties.items():
param_type = inner_param_info['type']
param_description = inner_param_info.get(
inner_param_type = inner_param_info['type']
inner_param_description = inner_param_info.get(
'description', f'用户输入的{param_name}.{inner_param_name}')
param_required = param_name in content['required']
parameters_list.append({
'name':
f'{param_name}.{inner_param_name}',
'description':
param_description,
'required':
param_required,
'type':
param_type,
'value':
inner_param_info.get('enum', '')
})
inner_param_required = param_name.split(
'.')[0] in content['required']

# Recursively call the function to handle nested objects
if inner_param_type == 'object':
parse_nested_parameters(
f'{param_name}.{inner_param_name}',
inner_param_info, parameters_list, content)
else:
parameters_list.append({
'name':
f'{param_name}.{inner_param_name}',
'description':
inner_param_description,
'required':
inner_param_required,
'type':
inner_param_type,
'value':
inner_param_info.get('enum', '')
})
else:
# Non-nested parameters are added directly to the parameter list
parameters_list.append({
Expand All @@ -233,6 +243,7 @@ def parse_responses_parameters(param_name, param_info, parameters_list):
if properties:
# If the argument type is an object and has a non-empty "properties"
# field, its internal properties are parsed recursively

for inner_param_name, inner_param_info in properties.items():
param_type = inner_param_info['type']
param_description = inner_param_info.get(
Expand All @@ -255,6 +266,7 @@ def parse_responses_parameters(param_name, param_info, parameters_list):


def openapi_schema_convert(schema, YOUR_API_TOKEN=''):

resolver = RefResolver.from_schema(schema)
servers = schema.get('servers', [])
if servers:
Expand Down
Loading

0 comments on commit 4888c9a

Please sign in to comment.