Skip to content

Commit fd29af4

Browse files
lylalalawangyijunlyytuhahahasuluyan.slymushenL
committed
Fix/openapi plugin (#311)
* update * add style_repaint * 恢复 * 恢复 * add style_repaint tool * modify style_repaint * fix error * fix rate limit * improve stability * use dashscope to convert url * modify and better * fix * refact framework: add base class for llm, tool, and agent * refact llm * refact llm for custom * add role_play agent * add unittest for role-play agent * refactor/tool/image_gen * fix pre-commit * add agent_builder agent * revert modelscope_agent/agent.py * update agent and add react prompt * adapt agentbuilder in apps * update style_repaint * update style_repaint * change pipeline plugin tool (#248) * change pipeline plugin tool * Standardized input and output * Standardized input and output * Standardized input and output * refactor ms agent * save system to history * avoid duplicated system in roleplay * builder with history running * test case * update tool * update * modify import method * code interpreter and knowledge * running code interpreter with file * Refactor/citest (#257) * add citest * cache dependency * cache dependency update 1 * cache dependency update 2 * cache dependency update 3 --------- Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com> * add modelscope tool (#258) * add modelscope tool * add modelscope tool * add modelscope tool --------- Co-authored-by: Zhicheng Zhang <zczhang.hvac@gmail.com> * unittest-web search web browser * update tool and unittest * Refactor/gradio4 (#260) * Feat/gradio4 (#229) * feat: update gradio 4 * feat: chatbot requirement * feat: update app.py to gradio 4 * fix: gradio 4 of process_configuration * fix: typo * fix: mschatbot * feat: chatbot support copy --------- Co-authored-by: nil.wyw <nil.wyw@alibaba-inc.com> * feat: update gradio 4 * feat: fileupload * feat: MultimodalInput for appBot * fix: ui * feat: MultimodalInput for app.py * feat: Textbox => MultimodalInput * bump version to 0.2.4rc0 * fix: lint * fix: lint * fix: lint * fix: lint * fix: add quotes for src prop (#249) * feat: update gradio 4 * feat: chatbot requirement * feat: update app.py to gradio 4 * fix: gradio 4 of process_configuration * fix: typo * fix: mschatbot * feat: chatbot support copy * feat: fileupload * fix: gradio 4 dataframe update * fix: appBot * fix: dataframe display when config update * fix: src format * fix: files path --------- Co-authored-by: nil.wyw <nil.wyw@alibaba-inc.com> * fix pre-commit * fix submit input. * fix multimodal * fix bugs & support appBot.py * fix pre-commit * fix auto-merge --------- Co-authored-by: wyw <1006629314@qq.com> Co-authored-by: nil.wyw <nil.wyw@alibaba-inc.com> Co-authored-by: Col0ring <1561999073@qq.com> Co-authored-by: wenmeng.zwm <wenmeng.zwm@alibaba-inc.com> Co-authored-by: Col0ring <47329987+Col0ring@users.noreply.github.com> Co-authored-by: suluyan.sly <suluyan.sly@alibaba-inc.com> Co-authored-by: skyline2006 <skyline2006@163.com> * update reame and tool cfg * Refactor/unittest (#264) * update unittest * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update requirements * update ci * update ci * update ci * update ci * update ci * update ci * update ci * update ci * update ci * update ci * merge gradio4 * update ci * update ci * update ci * update ci * pass unit test * merge and pass unit test --------- Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com> * merge origin master * fix bugs * fix video-to-image * add qwen-max * fix apps/agentfabric & update release version * apps/agentfabric/user_core.py * fix pre-commit * fix bugs & add video play for code interpreter * comment out translate * Refactor log (#268) * update logger * add dashscope log * update user log * add comment --------- Co-authored-by: ly119399 <ly119399@alibaba-inc.com> * Refactor/knowledgeretrieval (#271) * pass retrieval knowledge * add unit test * update requirements * pass lint * refact name * refact name --------- Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com> * add logger (#272) * comment out translate * Refactor log (#268) * update logger * add dashscope log * update user log * add comment --------- Co-authored-by: ly119399 <ly119399@alibaba-inc.com> --------- Co-authored-by: skyline2006 <skyline2006@163.com> Co-authored-by: lylalala <liuyang070424@163.com> Co-authored-by: ly119399 <ly119399@alibaba-inc.com> Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com> * pass code unittest * fix publish for missing MODELSCOPE_API_TOKEN alert & rm translation tool * fix bugs * update log * fix bugs * fix instruction * fix tool log * fix bugs * fix pre-commit * Zhipu-glm4 (#276) support zhipu glm-4 model --------- Co-authored-by: skyline2006 <skyline2006@163.com> Co-authored-by: Zhicheng Zhang <zczhang.hvac@gmail.com> * add zhipuai to requirements.txt * make sure .md file is parsed by nltk * Update demo 20240118 (#275) Co-authored-by: Jintao Huang <huangjintao.hjt@alibaba-inc.com> * add zhipuai * update retrieval knowledge logic to not load in agent fabric * update name * fix bugs * fix pre-commit * fix ci * update max_token setting * fix doc list extend method * fix ci * fix ci * add docstr * rm useless agent: function call, react, react_chat * bugfix * bugfix * bugfix: change _detect_tool for role_play * remove uuid related log in ms * fix publish avatar * version 0.3.0rc0 * fix bugs * fix bug * fix audio->video * update demo * bug fixed by comment * lint pass * bug fixed * bug fixed * fix ci (not complete) * add hf tool unit test * Openapi (#287) * feat: openapi * fix pre-commit * fix bugs --------- Co-authored-by: skyline2006 <skyline2006@163.com> Co-authored-by: suluyan <suluyan.sly@alibaba-inc.com> * bug fixed * pass lint * fix openapi bug --------- Co-authored-by: wangyijunlyy <1157637345@qq.com> Co-authored-by: tujianhong.tjh <tujianhong.tjh@alibaba-inc.com> Co-authored-by: suluyan.sly <suluyan.sly@alibaba-inc.com> Co-authored-by: Jianhong Tu <37433392+tuhahaha@users.noreply.github.com> Co-authored-by: mushenL <125954878+mushenL@users.noreply.github.com> Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com> Co-authored-by: Zhicheng Zhang <zczhang.hvac@gmail.com> Co-authored-by: suluyana <110878454+suluyana@users.noreply.github.com> Co-authored-by: wyw <1006629314@qq.com> Co-authored-by: nil.wyw <nil.wyw@alibaba-inc.com> Co-authored-by: Col0ring <1561999073@qq.com> Co-authored-by: wenmeng.zwm <wenmeng.zwm@alibaba-inc.com> Co-authored-by: Col0ring <47329987+Col0ring@users.noreply.github.com> Co-authored-by: skyline2006 <skyline2006@163.com> Co-authored-by: ly119399 <ly119399@alibaba-inc.com> Co-authored-by: Jintao Huang <huangjintao.hjt@alibaba-inc.com> (cherry picked from commit 251b56f)
1 parent 938aac2 commit fd29af4

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

modelscope_agent/agent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ def _register_tool(self, tool: Union[str, Dict]):
115115
raise NotImplementedError
116116
if tool not in self.function_list:
117117
self.function_list.append(tool)
118-
self.function_map[tool_name] = TOOL_REGISTRY[tool_name](tool_cfg)
118+
tool_class = TOOL_REGISTRY[tool_name]
119+
try:
120+
self.function_map[tool_name] = tool_class(tool_cfg)
121+
except TypeError:
122+
# When using OpenAPI, tool_class is already an instantiated object, not a corresponding class
123+
self.function_map[tool_name] = tool_class
124+
except Exception as e:
125+
raise RuntimeError(e)
119126

120127
def _detect_tool(self, message: Union[str, dict]):
121128
# use built-in default judgment functions

modelscope_agent/tools/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ def _build_function(self):
7676
},
7777
}
7878
for para in self.parameters:
79-
function['parameters']['properties'][para['name']] = {
80-
'type': para['type'],
81-
'description': para['description']
79+
function_details = {
80+
'type':
81+
para['type'] if 'type' in para else para['schema']['type'],
82+
'description':
83+
para['description']
8284
}
85+
if 'enum' in para and para['enum'] not in ['', []]:
86+
function_details['enum'] = para['enum']
87+
function['parameters']['properties'][
88+
para['name']] = function_details
8389
if 'required' in para and para['required']:
8490
function['parameters']['required'].append(para['name'])
8591
else:

modelscope_agent/tools/dashscope_tools/wordart_tool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ def call(self, params: str, **kwargs) -> str:
4545
if isinstance(params, str):
4646
return 'Parameter Error'
4747
remote_parsed_input = json.dumps(self._remote_parse_input(**params))
48-
origin_result = None
4948
self.token = kwargs.get('token',
5049
os.environ.get('DASHSCOPE_API_KEY', ''))
5150
assert self.token != '', 'dashscope api token must be acquired with wordart'

modelscope_agent/tools/openapi_plugin.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,17 @@ def __init__(self, cfg, name):
4747
self.description = self.cfg.get('description',
4848
'This is a api tool that ...')
4949
self.responses_param = self.cfg.get('responses_param', [])
50-
try:
51-
all_para = {
52-
'name': self.name,
53-
'description': self.description,
54-
'parameters': self.parameters
55-
}
56-
self.tool_schema = ToolSchema(**all_para)
57-
except ValidationError:
58-
raise ValueError(f'Error when parsing parameters of {self.name}')
59-
self._str = self.tool_schema.model_dump_json()
60-
self._function = self.parse_pydantic_model_to_openai_function(all_para)
50+
super().__init__(cfg)
6151

6252
def call(self, params: str, **kwargs):
6353
if self.url == '':
6454
raise ValueError(
6555
f"Could not use remote call for {self.name} since this tool doesn't have a remote endpoint"
6656
)
67-
#
68-
# remote_parsed_input = json.dumps(
69-
# self._remote_parse_input(*args, **kwargs))
57+
58+
json_params = json.loads(params)
59+
remote_parsed_input = json.dumps(
60+
self._remote_parse_input(**json_params))
7061
params = self._verify_args(params)
7162
if isinstance(params, str):
7263
return 'Parameter Error'
@@ -80,7 +71,10 @@ def call(self, params: str, **kwargs):
8071
print(f'data: {kwargs}')
8172
print(f'header: {self.header}')
8273
response = requests.request(
83-
'POST', url=self.url, headers=self.header, data=params)
74+
'POST',
75+
url=self.url,
76+
headers=self.header,
77+
data=remote_parsed_input)
8478

8579
if response.status_code != requests.codes.ok:
8680
response.raise_for_status()
@@ -96,6 +90,8 @@ def call(self, params: str, **kwargs):
9690
raise ValueError(
9791
f'Remote call failed with error code: {e.response.status_code},\
9892
error message: {e.response.content.decode("utf-8")}')
93+
except Exception as e:
94+
raise ValueError(e)
9995

10096
raise ValueError(
10197
'Remote call max retry times exceeded! Please try to use local call.'
@@ -106,8 +102,8 @@ def call(self, params: str, **kwargs):
106102
new_url = self.url
107103
matches = re.findall(r'\{(.*?)\}', self.url)
108104
for match in matches:
109-
if match in kwargs:
110-
new_url = new_url.replace('{' + match + '}', kwargs[match])
105+
if match in params:
106+
new_url = new_url.replace('{' + match + '}', params[match])
111107
else:
112108
print(
113109
f'The parameter {match} was not generated by the model.'
@@ -209,7 +205,7 @@ def parse_nested_parameters(param_name, param_info, parameters_list, content):
209205
inner_param_required,
210206
'type':
211207
inner_param_type,
212-
'value':
208+
'enum':
213209
inner_param_info.get('enum', '')
214210
})
215211
else:
@@ -219,7 +215,7 @@ def parse_nested_parameters(param_name, param_info, parameters_list, content):
219215
'description': param_description,
220216
'required': param_required,
221217
'type': param_type,
222-
'value': param_info.get('enum', '')
218+
'enum': param_info.get('enum', '')
223219
})
224220
except Exception as e:
225221
raise ValueError(f'{e}:schema结构出错')
@@ -348,7 +344,6 @@ def openapi_schema_convert(schema, auth):
348344
}
349345
}
350346
elif method.upper() == 'GET':
351-
parameters_list = []
352347
parameters_list = details.get('parameters', [])
353348
config_entry = {
354349
'name': name,

0 commit comments

Comments
 (0)