From 1248add4fda12b1d42d7a48549e20640ce70fe85 Mon Sep 17 00:00:00 2001 From: birham-red-bd <34261319+birham-red-bd@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:51:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=A4=8D=E7=89=A9=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E3=80=81=E5=9B=BE=E7=89=87=E5=86=85=E5=AE=B9=E7=90=86=E8=A7=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E=E7=BB=93=E6=9E=9C=20(#199)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 动植物识别、图片内容理解修改返回结果 * 修改代码规范 --------- Co-authored-by: zhongsonghui --- .../core/components/animal_recognize/component.py | 7 +++++-- .../core/components/image_understand/component.py | 11 ++++++++++- .../core/components/plant_recognize/component.py | 7 +++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/appbuilder/core/components/animal_recognize/component.py b/appbuilder/core/components/animal_recognize/component.py index ffd735a9f..2d67bca26 100644 --- a/appbuilder/core/components/animal_recognize/component.py +++ b/appbuilder/core/components/animal_recognize/component.py @@ -24,6 +24,9 @@ from appbuilder.core._exception import AppBuilderServerException from typing import Generator, Union +TOP_NUM = 1 +BAIKE_NUM = 0 + class AnimalRecognition(Component): r""" @@ -169,8 +172,8 @@ def _recognize_w_post_process(self, img_path, img_url, file_urls) -> str: if img_url in file_urls: img_url = file_urls['img_url'] req.url = img_url - req.top_num = 6 - req.baike_num = 0 + req.top_num = TOP_NUM + req.baike_num = BAIKE_NUM result = self._recognize(req) result_dict = proto.Message.to_dict(result) rec_res = "模型识别结果为:\n" diff --git a/appbuilder/core/components/image_understand/component.py b/appbuilder/core/components/image_understand/component.py index 19fa68d68..ff3b19de4 100644 --- a/appbuilder/core/components/image_understand/component.py +++ b/appbuilder/core/components/image_understand/component.py @@ -168,7 +168,16 @@ def tool_eval(self, name: str, streaming: bool, file_urls = kwargs.get("file_urls", {}) rec_res = self._recognize_w_post_process(img_path, img_url, file_urls) if streaming: - yield rec_res + yield { + "type": "text", + "text": rec_res, + "visible_scope": 'llm', + } + yield { + "type": "text", + "text": "", + "visible_scope": 'user', + } else: return rec_res diff --git a/appbuilder/core/components/plant_recognize/component.py b/appbuilder/core/components/plant_recognize/component.py index b679eccf1..ea92d6338 100644 --- a/appbuilder/core/components/plant_recognize/component.py +++ b/appbuilder/core/components/plant_recognize/component.py @@ -22,6 +22,9 @@ from appbuilder.core.components.plant_recognize.model import * from typing import Generator, Union +TOP_NUM = 1 +BAIKE_NUM = 0 + class PlantRecognition(Component): r""" @@ -174,8 +177,8 @@ def _recognize_w_post_process(self, img_path, img_url, file_urls): if img_url in file_urls: img_url = file_urls['img_url'] req.url = img_url - req.top_num = 6 - req.baike_num = 0 + req.top_num = TOP_NUM + req.baike_num = BAIKE_NUM result = self.__recognize(req) result_dict = proto.Message.to_dict(result) rec_res = "模型识别结果为:\n"