From 788e9662fcb1ad1c8214679d041f49c1dab86783 Mon Sep 17 00:00:00 2001 From: zhoulongchao <152879727+longchao1916@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:20:58 +0800 Subject: [PATCH] =?UTF-8?q?translate=E5=A2=9E=E5=8A=A0=E5=B8=B8=E8=A7=81?= =?UTF-8?q?=E8=AF=AD=E7=A7=8D&general-ocr=E6=89=93=E5=BC=80=E6=96=B9?= =?UTF-8?q?=E5=90=91=E6=A3=80=E6=B5=8B=E5=BC=80=E5=85=B3=20(#207)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * translate组件functioncall修改manifests增加支持常见语种 * general-ocr打开方向检测开关 --- .../core/components/general_ocr/component.py | 2 ++ appbuilder/core/components/translate/component.py | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/appbuilder/core/components/general_ocr/component.py b/appbuilder/core/components/general_ocr/component.py index 82a7be5d7..f0b3f5845 100644 --- a/appbuilder/core/components/general_ocr/component.py +++ b/appbuilder/core/components/general_ocr/component.py @@ -100,6 +100,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag request.image = base64.b64encode(inp.raw_image) if inp.url: request.url = inp.url + request.detect_direction = "true" result = self._recognize(request, timeout, retry) result_dict = proto.Message.to_dict(result) out = GeneralOCROutMsg(**result_dict) @@ -162,6 +163,7 @@ def tool_eval(self, name: str, streaming: bool, **kwargs): if not img_url: raise InvalidRequestArgumentError(f"file {img_name} url does not exist") req = GeneralOCRRequest(url=img_url) + req.detect_direction = "true" result = proto.Message.to_dict(self._recognize(req)) results = { "识别结果": " \n".join(item["words"] for item in result["words_result"]) diff --git a/appbuilder/core/components/translate/component.py b/appbuilder/core/components/translate/component.py index e512f1b29..a306e6504 100644 --- a/appbuilder/core/components/translate/component.py +++ b/appbuilder/core/components/translate/component.py @@ -63,9 +63,15 @@ class Translation(Component): }, "to_lang": { "type": "string", - "description": "翻译的目标语言类型,'en'表示翻译成英语, 'zh'表示翻译成中文,'jp'表示翻译成日语," - "'kor'表示翻译成韩语,'fra'表示翻译成法语,'de'表示翻译成德语,默认为'en'", - "enum": ["en", "zh", "jp", "kor", "fra", "de"] + "description": "翻译的目标语言类型,'en'表示翻译成英语, 'zh'表示翻译成中文,'yue'表示翻译成粤语,'wyw'表示翻译成文言文," + "'jp'表示翻译成日语,'kor'表示翻译成韩语,'fra'表示翻译成法语,'spa'表示翻译成西班牙语,'th'表示翻译成泰语," + "'ara'表示翻译成阿拉伯语,'ru'表示翻译成俄语,'pt'表示翻译成葡萄牙语,'de'表示翻译成德语,'it'表示翻译成意大利语," + "'el'表示翻译成希腊语,'nl'表示翻译成荷兰语,'pl'表示翻译成波兰语,'bul'表示翻译成保加利亚语,'est'表示翻译成爱沙尼亚语," + "'dan'表示翻译成丹麦语, 'fin'表示翻译成芬兰语,'cs'表示翻译成捷克语,'rom'表示翻译成罗马尼亚语,'slo'表示翻译成斯洛文尼亚语," + "'swe'表示翻译成瑞典语,'hu'表示翻译成匈牙利语,'cht'表示翻译成繁体中文,'vie'表示翻译成越南语,默认为'en'", + "enum": ["en", "zh", "yue", "wyw", "jp", "kor", "fra", "spa", "th", "ara", "ru", "pt", "de", + "it", "el", "nl", "pl", "bul", "est", "dan", "fin", "cs", "rom", "slo", "swe", "hu", + "cht", "vie"] } }, "required": [ @@ -134,7 +140,8 @@ def _translate(self, request: TranslateRequest, timeout: float = None, request_id = self.http_client.response_request_id(response) self.http_client.check_response_json(data) if "error_code" in data and "error_msg" in data: - raise AppBuilderServerException(request_id=request_id, service_err_code=data["error_code"], service_err_message=data["error_msg"]) + raise AppBuilderServerException(request_id=request_id, service_err_code=data["error_code"], + service_err_message=data["error_msg"]) json_str = json.dumps(data) return TranslateResponse(TranslateResponse.from_json(json_str))