From c6fa455a658eaf6474c040cf57ad618de8d078d2 Mon Sep 17 00:00:00 2001 From: hermitgreen Date: Thu, 30 May 2024 20:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8tool=5Feval=E6=97=B6?= =?UTF-8?q?,=20=E6=89=93=E9=80=9A=E9=93=BE=E8=B7=AF=E4=B8=8A=E7=9A=84reque?= =?UTF-8?q?st-id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appbuilder/core/components/animal_recognize/component.py | 4 ++-- appbuilder/core/components/asr/component.py | 6 +++--- .../core/components/doc_format_converter/component.py | 4 ++-- appbuilder/core/components/general_ocr/component.py | 4 ++-- appbuilder/core/components/handwrite_ocr/component.py | 4 ++-- appbuilder/core/components/image_understand/component.py | 4 ++-- .../core/components/llms/similar_question/component.py | 4 ++-- .../core/components/llms/style_rewrite/component.py | 4 ++-- .../core/components/llms/style_writing/component.py | 4 ++-- appbuilder/core/components/mix_card_ocr/component.py | 4 ++-- appbuilder/core/components/object_recognize/component.py | 4 ++-- appbuilder/core/components/plant_recognize/component.py | 4 ++-- appbuilder/core/components/qrcode_ocr/component.py | 9 +++++---- appbuilder/core/components/table_ocr/component.py | 4 ++-- appbuilder/core/components/translate/component.py | 4 ++-- 15 files changed, 34 insertions(+), 33 deletions(-) diff --git a/appbuilder/core/components/animal_recognize/component.py b/appbuilder/core/components/animal_recognize/component.py index da417a4a0..ef65202d1 100644 --- a/appbuilder/core/components/animal_recognize/component.py +++ b/appbuilder/core/components/animal_recognize/component.py @@ -157,11 +157,11 @@ def tool_eval( 返回: Union[Generator[str, None, None], str]: 动物识别结果,包括识别出的动物类别和相应的置信度信息 """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") img_name = kwargs.get("img_name", "") img_url = kwargs.get("img_url", "") file_urls = kwargs.get("file_urls", {}) - rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, request_id) + rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, traceid) if streaming: yield rec_res else: diff --git a/appbuilder/core/components/asr/component.py b/appbuilder/core/components/asr/component.py index b8f0ac173..683469f5a 100644 --- a/appbuilder/core/components/asr/component.py +++ b/appbuilder/core/components/asr/component.py @@ -192,14 +192,14 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): _, file_type = os.path.splitext(os.path.basename(urlparse(file_url).path)) file_type = file_type.strip('.') - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") req = ShortSpeechRecognitionRequest() req.speech = requests.get(file_url).content req.format = file_type - req.cuid = request_id if request_id else str(uuid.uuid4()) + req.cuid = traceid if traceid else str(uuid.uuid4()) req.dev_pid = "80001" req.rate = 16000 - result = proto.Message.to_dict(self._recognize(req, request_id=request_id)) + result = proto.Message.to_dict(self._recognize(req, request_id=traceid)) results = { "识别结果": " \n".join(item for item in result["result"]) } diff --git a/appbuilder/core/components/doc_format_converter/component.py b/appbuilder/core/components/doc_format_converter/component.py index 98f1facdd..d55b23025 100644 --- a/appbuilder/core/components/doc_format_converter/component.py +++ b/appbuilder/core/components/doc_format_converter/component.py @@ -216,7 +216,7 @@ def tool_eval(self, streaming: bool, origin_query: str, **kwargs,): """ tool eval """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") file_url = kwargs.get("file_url", None) page_num = kwargs.get("page_num", '') if page_num: @@ -234,7 +234,7 @@ def tool_eval(self, streaming: bool, origin_query: str, **kwargs,): if not file_url: raise InvalidRequestArgumentError("request format error, file url is not set") try: - result = self.run(Message({"file_path": file_url, "page_num": page_num}), request_id) + result = self.run(Message({"file_path": file_url, "page_num": page_num}), traceid) except AppBuilderServerException: raise except Exception as e: diff --git a/appbuilder/core/components/general_ocr/component.py b/appbuilder/core/components/general_ocr/component.py index 389c5341c..c459d0d43 100644 --- a/appbuilder/core/components/general_ocr/component.py +++ b/appbuilder/core/components/general_ocr/component.py @@ -160,7 +160,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): """ general_ocr for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") img_url = kwargs.get("img_url", None) if not img_url: file_urls = kwargs.get("file_urls", {}) @@ -176,7 +176,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): req = GeneralOCRRequest(url=img_url) req.detect_direction = "true" req.language_type = "auto_detect" - result = proto.Message.to_dict(self._recognize(req, request_id)) + result = proto.Message.to_dict(self._recognize(req, traceid)) results = { "识别结果": " \n".join(item["words"] for item in result["words_result"]) } diff --git a/appbuilder/core/components/handwrite_ocr/component.py b/appbuilder/core/components/handwrite_ocr/component.py index 3bf9d29a6..35bdb885f 100644 --- a/appbuilder/core/components/handwrite_ocr/component.py +++ b/appbuilder/core/components/handwrite_ocr/component.py @@ -101,7 +101,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag def tool_eval(self, name: str, streaming: bool, **kwargs): - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") result = "" file_names = kwargs.get("file_names", None) if not file_names: @@ -121,7 +121,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): req.probability = "false" req.detect_direction = "true" req.detect_alteration = "true" - response = self._recognize(req, request_id) + response = self._recognize(req, traceid) text = "".join([w.words for w in response.words_result]) result += f"{file_name}的手写识别结果是:{text} " diff --git a/appbuilder/core/components/image_understand/component.py b/appbuilder/core/components/image_understand/component.py index 1d9a6a8c8..fd715c789 100644 --- a/appbuilder/core/components/image_understand/component.py +++ b/appbuilder/core/components/image_understand/component.py @@ -178,11 +178,11 @@ def tool_eval( 返回: Union[Generator[str, None, None], str]: 图片内容理解结果 """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") img_name = kwargs.get("img_name", "") img_url = kwargs.get("img_url", "") file_urls = kwargs.get("file_urls", {}) - rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, request_id=request_id) + rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, request_id=traceid) if streaming: yield { "type": "text", diff --git a/appbuilder/core/components/llms/similar_question/component.py b/appbuilder/core/components/llms/similar_question/component.py index 965f5fdc6..c181c3d10 100644 --- a/appbuilder/core/components/llms/similar_question/component.py +++ b/appbuilder/core/components/llms/similar_question/component.py @@ -114,7 +114,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): """ tool_eval for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") query = kwargs.get("query", None) if not query: raise ValueError("param `query` is required") @@ -122,7 +122,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): model_configs = kwargs.get('model_configs', {}) temperature = model_configs.get("temperature", 1e-10) top_p = model_configs.get("top_p", 0.0) - message = super().run(message=msg, stream=False, temperature=temperature, top_p=top_p, request_id=request_id) + message = super().run(message=msg, stream=False, temperature=temperature, top_p=top_p, request_id=traceid) if streaming: yield str(message.content) diff --git a/appbuilder/core/components/llms/style_rewrite/component.py b/appbuilder/core/components/llms/style_rewrite/component.py index ba820ff1b..38b84a2b3 100644 --- a/appbuilder/core/components/llms/style_rewrite/component.py +++ b/appbuilder/core/components/llms/style_rewrite/component.py @@ -153,7 +153,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): """ tool_eval for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") query = kwargs.get("query", None) if not query: raise ValueError("param `query` is required") @@ -164,7 +164,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): model_configs = kwargs.get('model_configs', {}) temperature = model_configs.get("temperature", 1e-10) top_p = model_configs.get("top_p", 0.0) - message = super().run(message=msg, style=style, stream=False, temperature=temperature, top_p=top_p, request_id=request_id) + message = super().run(message=msg, style=style, stream=False, temperature=temperature, top_p=top_p, request_id=traceid) if streaming: yield str(message.content) diff --git a/appbuilder/core/components/llms/style_writing/component.py b/appbuilder/core/components/llms/style_writing/component.py index c769240e5..97236225d 100644 --- a/appbuilder/core/components/llms/style_writing/component.py +++ b/appbuilder/core/components/llms/style_writing/component.py @@ -182,7 +182,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): """ tool_eval for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") query = kwargs.get("query", None) if not query: raise ValueError("param `query` is required") @@ -201,7 +201,7 @@ def tool_eval(self, name: str, streaming: bool = False, **kwargs): temperature = model_configs.get("temperature", 1e-10) top_p = model_configs.get("top_p", 0.0) message = super().run(message=msg, style_query=style, length=length, stream=False, - temperature=temperature, top_p=top_p, request_id=request_id) + temperature=temperature, top_p=top_p, request_id=traceid) if streaming: yield str(message.content) diff --git a/appbuilder/core/components/mix_card_ocr/component.py b/appbuilder/core/components/mix_card_ocr/component.py index cf8de23ff..c5f0e540b 100644 --- a/appbuilder/core/components/mix_card_ocr/component.py +++ b/appbuilder/core/components/mix_card_ocr/component.py @@ -151,7 +151,7 @@ def _check_service_error(request_id: str, data: dict): def tool_eval(self, name: str, streaming: bool, **kwargs): result = {} - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") file_names = kwargs.get("file_names", None) if not file_names: file_names = kwargs.get("files") @@ -170,7 +170,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): request.detect_quality = "false" request.detect_photo = "false" request.detect_card = "false" - response = self._recognize(request, request_id) + response = self._recognize(request, traceid) out = MixCardOCROutMsg() for res in response.words_result: card_type = res.card_info.card_type diff --git a/appbuilder/core/components/object_recognize/component.py b/appbuilder/core/components/object_recognize/component.py index 429ee5e0e..74199f35a 100644 --- a/appbuilder/core/components/object_recognize/component.py +++ b/appbuilder/core/components/object_recognize/component.py @@ -149,7 +149,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): """ object_recognize for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") img_url = kwargs.get("img_url", None) if not img_url: file_urls = kwargs.get("file_urls", {}) @@ -162,7 +162,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): raise InvalidRequestArgumentError(f"request format error, file {img_name} url does not exist") score_threshold = kwargs.get("score_threshold", 0.5) req = ObjectRecognitionRequest(url=img_url) - result = proto.Message.to_dict(self._recognize(req, request_id)) + result = proto.Message.to_dict(self._recognize(req, traceid)) results = [] for item in result["result"]: if item["score"] < score_threshold and len(results) > 0: diff --git a/appbuilder/core/components/plant_recognize/component.py b/appbuilder/core/components/plant_recognize/component.py index de9776a18..e216e2acd 100644 --- a/appbuilder/core/components/plant_recognize/component.py +++ b/appbuilder/core/components/plant_recognize/component.py @@ -162,11 +162,11 @@ def tool_eval( 返回: Union[Generator[str, None, None], str]: 植物识别结果,包括识别出的植物类别和相应的置信度信息 """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") img_name = kwargs.get("img_name", "") img_url = kwargs.get("img_url", "") file_urls = kwargs.get("file_urls", {}) - rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, request_id) + rec_res = self._recognize_w_post_process(img_name, img_url, file_urls, traceid) if streaming: yield rec_res else: diff --git a/appbuilder/core/components/qrcode_ocr/component.py b/appbuilder/core/components/qrcode_ocr/component.py index e9bee52f0..004d345c5 100644 --- a/appbuilder/core/components/qrcode_ocr/component.py +++ b/appbuilder/core/components/qrcode_ocr/component.py @@ -151,7 +151,7 @@ def _check_service_error(request_id: str, data: dict): def tool_eval(self, name: str, streaming: bool, **kwargs): result = {} - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") file_names = kwargs.get("file_names", None) location = kwargs.get("locations", "false") if not file_names: @@ -173,9 +173,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): f"illegal location, expected location is 'true' or 'false', got {location}" ) req.location = location - resp = self._recognize(req, request_id) - result[file_name] = [item["text"] - for item in proto.Message.to_dict(resp).get("codes_result", [])] + resp = self._recognize(req, traceid) + result[file_name] = [ + item["text"] for item in proto.Message.to_dict(resp).get("codes_result", []) + ] result = json.dumps(result, ensure_ascii=False) if streaming: diff --git a/appbuilder/core/components/table_ocr/component.py b/appbuilder/core/components/table_ocr/component.py index fb4f00bdc..ace0464be 100644 --- a/appbuilder/core/components/table_ocr/component.py +++ b/appbuilder/core/components/table_ocr/component.py @@ -178,7 +178,7 @@ def get_table_markdown(self, tables_result): def tool_eval(self, name: str, streaming: bool, **kwargs): result = {} - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") file_names = kwargs.get("file_names", None) if not file_names: file_names = kwargs.get("files") @@ -195,7 +195,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): req = TableOCRRequest() req.url = file_url req.cell_contents = "false" - resp = self._recognize(req, request_id) + resp = self._recognize(req, traceid) tables_result = proto.Message.to_dict(resp)["tables_result"] markdowns = self.get_table_markdown(tables_result) result[file_name] = markdowns diff --git a/appbuilder/core/components/translate/component.py b/appbuilder/core/components/translate/component.py index 67ab5e696..3662b1828 100644 --- a/appbuilder/core/components/translate/component.py +++ b/appbuilder/core/components/translate/component.py @@ -150,7 +150,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): """ translate for function call """ - request_id = kwargs.get("traceid") + traceid = kwargs.get("traceid") req = TranslateRequest() text = kwargs.get("q", None) if not text: @@ -158,7 +158,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): req.q = text to_lang = kwargs.get("to_lang", "en") req.to_lang = to_lang - results = proto.Message.to_dict(self._translate(req, request_id))["result"] + results = proto.Message.to_dict(self._translate(req, traceid))["result"] trans_result = results["trans_result"] res = { "原文本": "\n ".join(item["src"] for item in trans_result),