Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重构接口报错处理 #174

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions appbuilder/core/components/animal_recognize/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,14 @@ def _recognize_w_post_process(self, img_path, img_url, file_urls) -> str:
返回:
str: 动物识别结果,包括识别出的动物类别和相应的置信度信息
"""
if not img_path and not img_url:
return "Image path and image url cannot be all empty"
req = AnimalRecognitionRequest()
if img_path in file_urls:
req.url = file_urls[img_path]
if img_url:
req.url = img_url
req.top_num = 6
req.baike_num = 0
try:
result = self._recognize(req)
except Exception as ex:
return "API call failed: {}".format(str(ex))
result = self._recognize(req)
result_dict = proto.Message.to_dict(result)
rec_res = "模型识别结果为:\n"
for rec_info in result_dict['result']:
Expand Down
7 changes: 1 addition & 6 deletions appbuilder/core/components/image_understand/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,13 @@ def _recognize_w_post_process(self, img_path, img_url, file_urls, question="图
返回:
str: 图片内容理解结果
"""
if question == "":
return "Question cannot be empty"
req = ImageUnderstandRequest()
req.question = question
if img_path in file_urls:
req.url = file_urls[img_path]
if img_url:
req.url = img_url
try:
response = self.__recognize(req)
except Exception as ex:
return "API call failed: {}".format(str(ex))
response = self.__recognize(req)
description_to_llm = response.result.description_to_llm
description_processed = description_to_llm.rsplit("。", 2)[0]
return description_processed
Expand Down
7 changes: 1 addition & 6 deletions appbuilder/core/components/plant_recognize/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,14 @@ def _recognize_w_post_process(self, img_path, img_url, file_urls):
返回:
str: 植物识别结果,包括识别出的动物类别和相应的置信度信息
"""
if not img_path and not img_url:
return "Image path and image url cannot be all empty"
req = PlantRecognitionRequest()
if img_path in file_urls:
req.url = file_urls[img_path]
if img_url:
req.url = img_url
req.top_num = 6
req.baike_num = 0
try:
result = self.__recognize(req)
except Exception as ex:
return "API call failed: {}".format(str(ex))
result = self.__recognize(req)
result_dict = proto.Message.to_dict(result)
rec_res = "模型识别结果为:\n"
for rec_info in result_dict['result']:
Expand Down
Loading