From 9230893a6bf140d3b3c37100f24b5d2744092bd7 Mon Sep 17 00:00:00 2001 From: hermitgreen Date: Sat, 9 Mar 2024 12:07:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=BF=AE=E5=A4=8Djson?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=9A=84visible=5Fscope?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/components/handwrite_ocr/component.py | 14 ++++++++++++-- .../core/components/mix_card_ocr/component.py | 14 ++++++++++++-- .../core/components/qrcode_ocr/component.py | 15 +++++++++++++-- appbuilder/core/components/table_ocr/component.py | 15 +++++++++++++-- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/appbuilder/core/components/handwrite_ocr/component.py b/appbuilder/core/components/handwrite_ocr/component.py index 3d2a82f48..7753f1671 100644 --- a/appbuilder/core/components/handwrite_ocr/component.py +++ b/appbuilder/core/components/handwrite_ocr/component.py @@ -122,10 +122,20 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): response = self._recognize(req) result[file_name] = [w.words for w in response.words_result] + result = json.dumps(result, ensure_ascii=False) if streaming: - yield json.dumps(result, ensure_ascii=False) + yield { + "type": "text", + "text": result, + "visible_scope": 'llm', + } + yield { + "type": "text", + "text": "", + "visible_scope": "user", + } else: - return json.dumps(result, ensure_ascii=False) + return result def _recognize(self, request: HandwriteOCRRequest, timeout: float = None, retry: int = 0) -> HandwriteOCRResponse: r"""调用底层接口进行通用文字识别 diff --git a/appbuilder/core/components/mix_card_ocr/component.py b/appbuilder/core/components/mix_card_ocr/component.py index 93f352bbd..5e6704eba 100644 --- a/appbuilder/core/components/mix_card_ocr/component.py +++ b/appbuilder/core/components/mix_card_ocr/component.py @@ -183,7 +183,17 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): out.direction = response.direction result[file_name] = out.dict() + result = json.dumps(result, ensure_ascii=False) if streaming: - yield json.dumps(result, ensure_ascii=False) + yield { + "type": "text", + "text": result, + "visible_scope": 'llm', + } + yield { + "type": "text", + "text": "", + "visible_scope": "user", + } else: - return json.dumps(result, ensure_ascii=False) + return result diff --git a/appbuilder/core/components/qrcode_ocr/component.py b/appbuilder/core/components/qrcode_ocr/component.py index 5edb5a0b8..95628b6a6 100644 --- a/appbuilder/core/components/qrcode_ocr/component.py +++ b/appbuilder/core/components/qrcode_ocr/component.py @@ -168,7 +168,18 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): req.location = location resp = self._recognize(req) 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: - yield json.dumps(result, ensure_ascii=False) + yield { + "type": "text", + "text": result, + "visible_scope": 'llm', + } + yield { + "type": "text", + "text": "", + "visible_scope": "user", + } else: - return json.dumps(result, ensure_ascii=False) + return result diff --git a/appbuilder/core/components/table_ocr/component.py b/appbuilder/core/components/table_ocr/component.py index 0947d36be..29326772c 100644 --- a/appbuilder/core/components/table_ocr/component.py +++ b/appbuilder/core/components/table_ocr/component.py @@ -194,7 +194,18 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): tables_result = proto.Message.to_dict(resp)["tables_result"] markdowns = self.get_table_markdown(tables_result) result[file_name] = markdowns + + result = json.dumps(result, ensure_ascii=False) if streaming: - yield json.dumps(result, ensure_ascii=False) + yield { + "type": "text", + "text": result, + "visible_scope": 'llm', + } + yield { + "type": "text", + "text": "", + "visible_scope": "user", + } else: - return json.dumps(result, ensure_ascii=False) + return result