From 689f028e57e0f8139cb57559275e88b0b53eeb53 Mon Sep 17 00:00:00 2001 From: mushenL Date: Wed, 10 Jan 2024 18:45:29 +0800 Subject: [PATCH 1/3] add modelscope tool --- .../tools/modelscope_tools/__init__.py | 5 + .../modelscope_tools/text_address_tool.py | 21 ++-- .../tools/modelscope_tools/text_ie_tool.py | 31 +++--- .../tools/modelscope_tools/text_ner_tool.py | 23 ++-- .../modelscope_tools/text_to_video_tool.py | 39 +++---- .../tools/utils/output_wrapper.py | 100 +++++++++--------- tests/tools/test_pipeline_tool.py | 33 +++++- 7 files changed, 146 insertions(+), 106 deletions(-) diff --git a/modelscope_agent/tools/modelscope_tools/__init__.py b/modelscope_agent/tools/modelscope_tools/__init__.py index e69de29bb..d839ab344 100644 --- a/modelscope_agent/tools/modelscope_tools/__init__.py +++ b/modelscope_agent/tools/modelscope_tools/__init__.py @@ -0,0 +1,5 @@ +from .text_to_video_tool import TextToVideoTool +from .text_to_speech_tool import TexttoSpeechTool +from .text_address_tool import TextAddressTool +from .text_ner_tool import TextNerTool +from .text_ie_tool import TextInfoExtractTool \ No newline at end of file diff --git a/modelscope_agent/tools/modelscope_tools/text_address_tool.py b/modelscope_agent/tools/modelscope_tools/text_address_tool.py index 6f0b575fc..a2e009ad5 100644 --- a/modelscope_agent/tools/modelscope_tools/text_address_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_address_tool.py @@ -9,12 +9,19 @@ class TextAddressTool(ModelscopePipelineTool): parameters: list = [{ 'name': 'input', 'description': '用户输入的地址信息', - 'required': True + 'required': True, + 'type': 'string' }] - task = Tasks.token_classification - def _parse_output(self, origin_result, *args, **kwargs): - final_result = {} - for e in origin_result['output']: - final_result[e['type']] = e['span'] - return {'result': final_result} + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + address = {} + for e in result['Data']['output']: + address[e['type']] = e['span'] + return address + + # def _parse_output(self, origin_result, *args, **kwargs): + # final_result = {} + # for e in origin_result['output']: + # final_result[e['type']] = e['span'] + # return {'result': final_result} diff --git a/modelscope_agent/tools/modelscope_tools/text_ie_tool.py b/modelscope_agent/tools/modelscope_tools/text_ie_tool.py index af5f32269..bb484cf38 100644 --- a/modelscope_agent/tools/modelscope_tools/text_ie_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_ie_tool.py @@ -1,3 +1,5 @@ +from typing import Union +import traceback from collections import defaultdict from modelscope.utils.constant import Tasks @@ -11,22 +13,25 @@ class TextInfoExtractTool(ModelscopePipelineTool): parameters: list = [{ 'name': 'input', 'description': '用户输入的文本', - 'required': True + 'required': True, + 'type': 'string' }, { 'name': 'schema', 'description': '要抽取信息的json表示', - 'required': True + 'required': True, + 'type': 'dict' }] - task = Tasks.siamese_uie - def _remote_parse_input(self, *args, **kwargs): - kwargs['parameters'] = {'schema': kwargs['schema']} - kwargs.pop('schema') - return kwargs + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + InfoExtract = defaultdict(list) + for e in result['Data']['output']: + InfoExtract[e[0]['type']].append(e[0]['span']) + return str(dict(InfoExtract)) + + def _verify_args(self, params: str) -> Union[str, dict]: + params = super()._verify_args(params) + params['parameters'] = {'schema': params['schema']} + params.pop('schema') + return params - def _parse_output(self, origin_result, *args, **kwargs): - final_result = defaultdict(list) - for e in origin_result['output']: - final_result[e[0]['type']].append(e[0]['span']) - - return {'result': dict(final_result)} diff --git a/modelscope_agent/tools/modelscope_tools/text_ner_tool.py b/modelscope_agent/tools/modelscope_tools/text_ner_tool.py index 6da3f27e7..41dda1390 100644 --- a/modelscope_agent/tools/modelscope_tools/text_ner_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_ner_tool.py @@ -5,18 +5,25 @@ class TextNerTool(ModelscopePipelineTool): - default_model = 'damo/nlp_raner_named-entity-recognition_chinese-base-news' + default_model = 'damo/nlp_raner_named-entity-recognition_chinese-base-cmeee' description = '命名实体识别服务,针对需要识别的中文文本,找出其中的实体,返回json格式结果' name = 'text-ner' parameters: list = [{ 'name': 'input', 'description': '用户输入的文本', - 'required': True + 'required': True, + 'type': 'string' }] - task = Tasks.named_entity_recognition - def _parse_output(self, origin_result, *args, **kwargs): - final_result = defaultdict(list) - for e in origin_result['output']: - final_result[e['type']].append(e['span']) - return {'result': dict(final_result)} + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + ner = defaultdict(list) + for e in result['Data']['output']: + ner[e['type']].append(e['span']) + return str(dict(ner)) + + # def _parse_output(self, origin_result, *args, **kwargs): + # final_result = defaultdict(list) + # for e in origin_result['output']: + # final_result[e['type']].append(e['span']) + # return {'result': dict(final_result)} diff --git a/modelscope_agent/tools/modelscope_tools/text_to_video_tool.py b/modelscope_agent/tools/modelscope_tools/text_to_video_tool.py index 467b86b35..baffb0314 100644 --- a/modelscope_agent/tools/modelscope_tools/text_to_video_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_to_video_tool.py @@ -1,40 +1,25 @@ -import os -import tempfile -import uuid - +from typing import Union from modelscope_agent.tools.utils.output_wrapper import VideoWrapper - -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool - class TextToVideoTool(ModelscopePipelineTool): default_model = 'damo/text-to-video-synthesis' description = '视频生成服务,针对英文文本输入,生成一段描述视频;如果是中文输入同时依赖插件modelscope_text-translation-zh2en翻译成英文' - name = 'video-generation' parameters: list = [{ 'name': 'text', 'description': '用户输入的文本信息', - 'required': True + 'required': True, + 'type': 'string' }] - task = Tasks.text_to_video_synthesis - - def _remote_parse_input(self, *args, **kwargs): - return {'input': {'text': kwargs['text']}} - - def _local_parse_input(self, *args, **kwargs): - - text = kwargs.pop('text', '') - directory = tempfile.mkdtemp() - file_path = os.path.join(directory, str(uuid.uuid4()) + '.mp4') - - parsed_args = ({'text': text}, ) - parsed_kwargs = {'output_video': file_path} - - return parsed_args, parsed_kwargs - def _parse_output(self, origin_result, remote=True): + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + video = result['Data']['output_video'] + return VideoWrapper(video) + + def _verify_args(self, params: str) -> Union[str, dict]: + params = super()._verify_args(params) + params = {'input': {'text': params['text']}} + return params - video = origin_result['output_video'] - return {'result': VideoWrapper(video)} diff --git a/modelscope_agent/tools/utils/output_wrapper.py b/modelscope_agent/tools/utils/output_wrapper.py index e8e189bd4..e1cdea589 100644 --- a/modelscope_agent/tools/utils/output_wrapper.py +++ b/modelscope_agent/tools/utils/output_wrapper.py @@ -7,7 +7,7 @@ import json import numpy as np import requests -from modelscope_agent.agent_types import AgentType +# from modelscope_agent.agent_types import AgentType from moviepy.editor import VideoFileClip from PIL import Image from requests.exceptions import RequestException @@ -166,52 +166,52 @@ def get_raw_output(exec_result: Dict): # -def display(llm_result: Union[str, dict], exec_result: Dict, idx: int, - agent_type: AgentType): - """Display the result of each round in jupyter notebook. - The multi-modal data will be extracted. - - Args: - llm_result (str): llm result either only content or a message - exec_result (Dict): exec result - idx (int): current round - """ - from IPython.display import display, Pretty, Image, Audio, JSON - idx_info = '*' * 50 + f'round {idx}' + '*' * 50 - display(Pretty(idx_info)) - - if isinstance(llm_result, dict): - llm_result = llm_result.get('content', '') - - if agent_type == AgentType.MS_AGENT: - pattern = r'<\|startofthink\|>```JSON([\s\S]*)```<\|endofthink\|>' - else: - pattern = r'```JSON([\s\S]*)```' - - match_action = re.search(pattern, llm_result) - if match_action: - result = match_action.group(1) - try: - json_content = json.loads(result, strict=False) - display(JSON(json_content)) - llm_result = llm_result.replace(match_action.group(0), '') - except Exception: - pass - - display(Pretty(llm_result)) - - exec_result = exec_result.get('result', '') - - if isinstance(exec_result, ImageWrapper) or isinstance( - exec_result, VideoWrapper): - display(Image(exec_result.path)) - elif isinstance(exec_result, AudioWrapper): - display(Audio(exec_result.path)) - elif isinstance(exec_result, dict): - display(JSON(exec_result)) - elif isinstance(exec_result, list): - display(JSON(exec_result)) - else: - display(Pretty(exec_result)) - - return +# def display(llm_result: Union[str, dict], exec_result: Dict, idx: int, +# agent_type: AgentType): +# """Display the result of each round in jupyter notebook. +# The multi-modal data will be extracted. + +# Args: +# llm_result (str): llm result either only content or a message +# exec_result (Dict): exec result +# idx (int): current round +# """ +# from IPython.display import display, Pretty, Image, Audio, JSON +# idx_info = '*' * 50 + f'round {idx}' + '*' * 50 +# display(Pretty(idx_info)) + +# if isinstance(llm_result, dict): +# llm_result = llm_result.get('content', '') + +# if agent_type == AgentType.MS_AGENT: +# pattern = r'<\|startofthink\|>```JSON([\s\S]*)```<\|endofthink\|>' +# else: +# pattern = r'```JSON([\s\S]*)```' + +# match_action = re.search(pattern, llm_result) +# if match_action: +# result = match_action.group(1) +# try: +# json_content = json.loads(result, strict=False) +# display(JSON(json_content)) +# llm_result = llm_result.replace(match_action.group(0), '') +# except Exception: +# pass + +# display(Pretty(llm_result)) + +# exec_result = exec_result.get('result', '') + +# if isinstance(exec_result, ImageWrapper) or isinstance( +# exec_result, VideoWrapper): +# display(Image(exec_result.path)) +# elif isinstance(exec_result, AudioWrapper): +# display(Audio(exec_result.path)) +# elif isinstance(exec_result, dict): +# display(JSON(exec_result)) +# elif isinstance(exec_result, list): +# display(JSON(exec_result)) +# else: +# display(Pretty(exec_result)) + +# return diff --git a/tests/tools/test_pipeline_tool.py b/tests/tools/test_pipeline_tool.py index 01175bc23..7398c914b 100644 --- a/tests/tools/test_pipeline_tool.py +++ b/tests/tools/test_pipeline_tool.py @@ -10,11 +10,42 @@ def test_modelscope_speech_generation(): - from modelscope_agent.tools import TexttoSpeechTool + from modelscope_agent.tools.modelscope_tools import TexttoSpeechTool kwargs = """{'input': '北京今天天气怎样?', 'gender': 'man'}""" txt2speech = TexttoSpeechTool(cfg) res = txt2speech.call(kwargs) print(res) +def test_modelscope_video_generation(): + from modelscope_agent.tools.modelscope_tools import TextToVideoTool + kwargs = """{'text': '一个正在打篮球的人'}""" + txt2video = TextToVideoTool(cfg) + res = txt2video.call(kwargs) + print(res) + +def test_modelscope_text_address(): + from modelscope_agent.tools.modelscope_tools import TextAddressTool + kwargs = """{'input': '北京朝阳望京东金辉大厦'}""" + txt_addr = TextAddressTool(cfg) + res = txt_addr.call(kwargs) + print(res) + +def test_modelscope_text_ner(): + from modelscope_agent.tools.modelscope_tools import TextNerTool + kwargs = """{'input': '多数新生儿甲亢在出生时即有症状,表现为突眼、甲状腺肿大、烦躁、多动、心动过速、呼吸急促,严重可出现心力衰竭,血T3、T4升高,TSH下降。'}""" + txt_ner = TextNerTool(cfg) + res = txt_ner.call(kwargs) + print(res) + +def test_modelscope_text_ie(): + from modelscope_agent.tools.modelscope_tools import TextInfoExtractTool + kwargs = """{'input': '很满意,音质很好,发货速度快,值得购买', 'schema': {'属性词': {'情感词': null}}}""" + txt_ie = TextInfoExtractTool(cfg) + res = txt_ie.call(kwargs) + print(res) test_modelscope_speech_generation() +test_modelscope_video_generation() +test_modelscope_text_address() +test_modelscope_text_ner() +test_modelscope_text_ie() From 55ea2d9e93c833647dad8c1e8169277f6cf8b2a8 Mon Sep 17 00:00:00 2001 From: mushenL Date: Wed, 10 Jan 2024 23:23:13 +0800 Subject: [PATCH 2/3] add modelscope tool --- .../tools/modelscope_tools/__init__.py | 5 ++- .../tools/modelscope_tools/image_chat_tool.py | 31 ++++++++++--------- .../modelscope_tools/text_address_tool.py | 6 ---- .../tools/modelscope_tools/text_ie_tool.py | 2 -- .../tools/modelscope_tools/text_ner_tool.py | 6 ---- .../translation_en2zh_tool.py | 14 ++++++--- .../translation_zh2en_tool.py | 14 ++++++--- tests/tools/test_pipeline_tool.py | 25 +++++++++++++++ 8 files changed, 63 insertions(+), 40 deletions(-) diff --git a/modelscope_agent/tools/modelscope_tools/__init__.py b/modelscope_agent/tools/modelscope_tools/__init__.py index d839ab344..e97f03a30 100644 --- a/modelscope_agent/tools/modelscope_tools/__init__.py +++ b/modelscope_agent/tools/modelscope_tools/__init__.py @@ -2,4 +2,7 @@ from .text_to_speech_tool import TexttoSpeechTool from .text_address_tool import TextAddressTool from .text_ner_tool import TextNerTool -from .text_ie_tool import TextInfoExtractTool \ No newline at end of file +from .text_ie_tool import TextInfoExtractTool +from .translation_en2zh_tool import TranslationEn2ZhTool +from .translation_zh2en_tool import TranslationZh2EnTool +from .image_chat_tool import ImageChatTool \ No newline at end of file diff --git a/modelscope_agent/tools/modelscope_tools/image_chat_tool.py b/modelscope_agent/tools/modelscope_tools/image_chat_tool.py index a4981c5d2..5e8949659 100644 --- a/modelscope_agent/tools/modelscope_tools/image_chat_tool.py +++ b/modelscope_agent/tools/modelscope_tools/image_chat_tool.py @@ -1,4 +1,4 @@ -from modelscope.utils.constant import Tasks +from typing import Union from .pipeline_tool import ModelscopePipelineTool @@ -9,18 +9,24 @@ class ImageChatTool(ModelscopePipelineTool): parameters: list = [{ 'name': 'image', 'description': '用户输入的图片', - 'required': True + 'required': True, + 'type': 'string' }, { 'name': 'text', 'description': '用户输入的文本', - 'required': True + 'required': True, + 'type': 'string' }] - task = Tasks.multimodal_dialogue - - def construct_image_chat_input(self, **kwargs): - image = kwargs.pop('image', '') - text = kwargs.pop('text', '') + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + image_chat = result['Data']['text'] + return image_chat + + def _verify_args(self, params: str) -> Union[str, dict]: + params = super()._verify_args(params) + image = params.pop('image', '') + text = params.pop('text', '') system_prompt_1 = 'The following is a conversation between a curious human and AI assistant.' system_prompt_2 = "The assistant gives helpful, detailed, and polite answers to the user's questions." messages = { @@ -41,11 +47,6 @@ def construct_image_chat_input(self, **kwargs): }, ] } - return messages - - def _remote_parse_input(self, *args, **kwargs): - messages = self.construct_image_chat_input(**kwargs) - return {'input': messages} + params = {'input': messages} + return params - def _local_parse_input(self, *args, **kwargs): - return (self.construct_image_chat_input(**kwargs)), {} diff --git a/modelscope_agent/tools/modelscope_tools/text_address_tool.py b/modelscope_agent/tools/modelscope_tools/text_address_tool.py index a2e009ad5..59447cba8 100644 --- a/modelscope_agent/tools/modelscope_tools/text_address_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_address_tool.py @@ -1,4 +1,3 @@ -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool @@ -20,8 +19,3 @@ def call(self, params: str, **kwargs) -> str: address[e['type']] = e['span'] return address - # def _parse_output(self, origin_result, *args, **kwargs): - # final_result = {} - # for e in origin_result['output']: - # final_result[e['type']] = e['span'] - # return {'result': final_result} diff --git a/modelscope_agent/tools/modelscope_tools/text_ie_tool.py b/modelscope_agent/tools/modelscope_tools/text_ie_tool.py index bb484cf38..f067c82e1 100644 --- a/modelscope_agent/tools/modelscope_tools/text_ie_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_ie_tool.py @@ -1,8 +1,6 @@ from typing import Union -import traceback from collections import defaultdict -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool diff --git a/modelscope_agent/tools/modelscope_tools/text_ner_tool.py b/modelscope_agent/tools/modelscope_tools/text_ner_tool.py index 41dda1390..d8cc2895f 100644 --- a/modelscope_agent/tools/modelscope_tools/text_ner_tool.py +++ b/modelscope_agent/tools/modelscope_tools/text_ner_tool.py @@ -1,6 +1,5 @@ from collections import defaultdict -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool @@ -22,8 +21,3 @@ def call(self, params: str, **kwargs) -> str: ner[e['type']].append(e['span']) return str(dict(ner)) - # def _parse_output(self, origin_result, *args, **kwargs): - # final_result = defaultdict(list) - # for e in origin_result['output']: - # final_result[e['type']].append(e['span']) - # return {'result': dict(final_result)} diff --git a/modelscope_agent/tools/modelscope_tools/translation_en2zh_tool.py b/modelscope_agent/tools/modelscope_tools/translation_en2zh_tool.py index 1fd490ef4..23cdc24c1 100644 --- a/modelscope_agent/tools/modelscope_tools/translation_en2zh_tool.py +++ b/modelscope_agent/tools/modelscope_tools/translation_en2zh_tool.py @@ -1,4 +1,3 @@ -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool @@ -6,12 +5,17 @@ class TranslationEn2ZhTool(ModelscopePipelineTool): default_model = 'damo/nlp_csanmt_translation_en2zh' description = '根据输入指令,将相应的英文文本翻译成中文回复' name = 'text-translation-en2zh' - task = Tasks.translation parameters: list = [{ 'name': 'input', 'description': '用户输入的英文文本', - 'required': True + 'required': True, + 'type': 'string' }] - def _parse_output(self, origin_result, *args, **kwargs): - return {'result': origin_result['translation']} + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + zh = result['Data']['translation'] + return zh + + # def _parse_output(self, origin_result, *args, **kwargs): + # return {'result': origin_result['translation']} diff --git a/modelscope_agent/tools/modelscope_tools/translation_zh2en_tool.py b/modelscope_agent/tools/modelscope_tools/translation_zh2en_tool.py index e8f19d769..814cb8152 100644 --- a/modelscope_agent/tools/modelscope_tools/translation_zh2en_tool.py +++ b/modelscope_agent/tools/modelscope_tools/translation_zh2en_tool.py @@ -1,4 +1,3 @@ -from modelscope.utils.constant import Tasks from .pipeline_tool import ModelscopePipelineTool @@ -6,12 +5,17 @@ class TranslationZh2EnTool(ModelscopePipelineTool): default_model = 'damo/nlp_csanmt_translation_zh2en' description = '根据输入指令,将相应的中文文本翻译成英文回复' name = 'text-translation-zh2en' - task = Tasks.translation parameters: list = [{ 'name': 'input', 'description': '用户输入的中文文本', - 'required': True + 'required': True, + 'type': 'string' }] - def _parse_output(self, origin_result, *args, **kwargs): - return {'result': origin_result['translation']} + def call(self, params: str, **kwargs) -> str: + result = super().call(params, **kwargs) + en = result['Data']['translation'] + return en + + # def _parse_output(self, origin_result, *args, **kwargs): + # return {'result': origin_result['translation']} diff --git a/tests/tools/test_pipeline_tool.py b/tests/tools/test_pipeline_tool.py index 7398c914b..73ba8ae14 100644 --- a/tests/tools/test_pipeline_tool.py +++ b/tests/tools/test_pipeline_tool.py @@ -44,8 +44,33 @@ def test_modelscope_text_ie(): res = txt_ie.call(kwargs) print(res) +def test_modelscope_en2zh(): + from modelscope_agent.tools.modelscope_tools import TranslationEn2ZhTool + kwargs = """{'input': 'Autonomous agents have long been a prominent research focus in both academic and industry communities.'}""" + zh_txt = TranslationEn2ZhTool(cfg) + res = zh_txt.call(kwargs) + print(res) + +def test_modelscope_zh2en(): + from modelscope_agent.tools.modelscope_tools import TranslationZh2EnTool + kwargs = """{'input': '北京今天天气怎样?'}""" + en_txt = TranslationZh2EnTool(cfg) + res = en_txt.call(kwargs) + print(res) + +def test_modelscope_image_chat(): + from modelscope_agent.tools.modelscope_tools import ImageChatTool + kwargs = """{'image': 'http://mm-chatgpt.oss-cn-zhangjiakou.aliyuncs.com/mplug_owl_demo/released_checkpoint/portrait_input.png', 'text': 'Describe the facial expression of the man.'}""" + image_chat = ImageChatTool(cfg) + res = image_chat.call(kwargs) + print(res) + + test_modelscope_speech_generation() test_modelscope_video_generation() test_modelscope_text_address() test_modelscope_text_ner() test_modelscope_text_ie() +test_modelscope_en2zh() +test_modelscope_zh2en() +test_modelscope_image_chat() From 1973dd6abc1c31d5f2d0d98b75099cdf6150b8ef Mon Sep 17 00:00:00 2001 From: mushenL Date: Thu, 11 Jan 2024 15:42:37 +0800 Subject: [PATCH 3/3] add modelscope tool --- .../tools/utils/output_wrapper.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/modelscope_agent/tools/utils/output_wrapper.py b/modelscope_agent/tools/utils/output_wrapper.py index e1cdea589..0c6c588b0 100644 --- a/modelscope_agent/tools/utils/output_wrapper.py +++ b/modelscope_agent/tools/utils/output_wrapper.py @@ -7,7 +7,6 @@ import json import numpy as np import requests -# from modelscope_agent.agent_types import AgentType from moviepy.editor import VideoFileClip from PIL import Image from requests.exceptions import RequestException @@ -166,11 +165,13 @@ def get_raw_output(exec_result: Dict): # +# +# # # def display(llm_result: Union[str, dict], exec_result: Dict, idx: int, # agent_type: AgentType): # """Display the result of each round in jupyter notebook. # The multi-modal data will be extracted. - +# # Args: # llm_result (str): llm result either only content or a message # exec_result (Dict): exec result @@ -179,15 +180,15 @@ def get_raw_output(exec_result: Dict): # from IPython.display import display, Pretty, Image, Audio, JSON # idx_info = '*' * 50 + f'round {idx}' + '*' * 50 # display(Pretty(idx_info)) - +# # if isinstance(llm_result, dict): # llm_result = llm_result.get('content', '') - +# # if agent_type == AgentType.MS_AGENT: # pattern = r'<\|startofthink\|>```JSON([\s\S]*)```<\|endofthink\|>' # else: # pattern = r'```JSON([\s\S]*)```' - +# # match_action = re.search(pattern, llm_result) # if match_action: # result = match_action.group(1) @@ -197,11 +198,11 @@ def get_raw_output(exec_result: Dict): # llm_result = llm_result.replace(match_action.group(0), '') # except Exception: # pass - +# # display(Pretty(llm_result)) - +# # exec_result = exec_result.get('result', '') - +# # if isinstance(exec_result, ImageWrapper) or isinstance( # exec_result, VideoWrapper): # display(Image(exec_result.path)) @@ -213,5 +214,5 @@ def get_raw_output(exec_result: Dict): # display(JSON(exec_result)) # else: # display(Pretty(exec_result)) - -# return +# +# return \ No newline at end of file