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

fix bug with pydantic version #111

Merged
merged 1 commit into from
Jan 26, 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
6 changes: 6 additions & 0 deletions appbuilder/core/_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ def __init__(self, request_id="", code="", message="", service_err_code="", serv
"""
super().__init__("request_id={}, code={}, message={}, service_err_code={}, service_err_message={} ".format(
request_id, code, message, service_err_code, service_err_message))


class InvalidRequestArgumentError(BaseRPCException):
r"""InvalidRequestArgumentError invalid request param
"""
pass
2 changes: 1 addition & 1 deletion appbuilder/core/components/animal_recognize/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
result = self._recognize(req, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = AnimalRecognitionOutMsg(**result_dict)
return Message(content=out.model_dump())
return Message(content=dict(out))

def _recognize(self, request: AnimalRecognitionRequest, timeout: float = None,
retry: int = 0) -> AnimalRecognitionResponse:
Expand Down
6 changes: 5 additions & 1 deletion appbuilder/core/components/doc_enhance/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from appbuilder.core.message import Message
from appbuilder.core._exception import AppBuilderServerException

enhance_type_set = [0, 1, 2, 3]


class DocEnhance(Component):
r"""
Expand Down Expand Up @@ -69,11 +71,13 @@ def run(self, message: Message, enhance_type: int = 0, timeout: float = None, re
if inp.url:
req.url = inp.url
req.scan_type = 3
if enhance_type not in enhance_type_set:
raise InvalidRequestArgumentError(f"enhance_type only support {enhance_type_set}")
req.enhance_type = enhance_type
result = self._recognize(req, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = DocEnhanceOutMsg(**result_dict)
return Message(content=out.model_dump())
return Message(content=dict(out))

def _recognize(self, request: DocEnhanceRequest, timeout: float = None,
retry: int = 0) -> DocEnhanceResponse:
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/general_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
result = self._recognize(request, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = GeneralOCROutMsg(**result_dict)
return Message(content=out.dict())
return Message(content=dict(out))

def _recognize(self, request: GeneralOCRRequest, timeout: float = None,
retry: int = 0) -> GeneralOCRResponse:
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/handwrite_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
height=w.location.height
)))
for w in response.words_result]
return Message(content=out.dict())
return Message(content=dict(out))

def _recognize(self, request: HandwriteOCRRequest, timeout: float = None, retry: int = 0) -> HandwriteOCRResponse:
r"""调用底层接口进行通用文字识别
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/image_understand/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
request.question = inp.question
response = self.__recognize(request, timeout, retry)
out = ImageUnderstandOutMsg(description=response.result.description_to_llm)
return Message(content=out.dict())
return Message(content=dict(out))

def __recognize(self, request: ImageUnderstandRequest, timeout: float = None,
retry: int = 0) -> ImageUnderstandResponse:
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/mix_card_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
height=val.location.height)
ref.fields.append(MixCardField(key=key, value=val.words, position=position))
out.direction = response.direction
return Message(content=out.dict())
return Message(content=dict(out))

def _recognize(self, request: MixCardOCRRequest, timeout: float = None, retry: int = 0) -> MixCardOCRResponse:
r"""调用底层身份证混贴识别
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/object_recognize/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
result = self._recognize(req, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = ObjectRecognitionOutMsg(**result_dict)
return Message(content=out.dict())
return Message(content=dict(out))

def _recognize(self, request: ObjectRecognitionRequest, timeout: float = None,
retry: int = 0) -> ObjectRecognitionResponse:
Expand Down
6 changes: 4 additions & 2 deletions appbuilder/core/components/qrcode_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from appbuilder.core.component import Component
from appbuilder.core.components.qrcode_ocr.model import *
from appbuilder.core.message import Message
from appbuilder.core._exception import AppBuilderServerException
from appbuilder.core._exception import AppBuilderServerException, InvalidRequestArgumentError


class QRcodeOCR(Component):
Expand Down Expand Up @@ -66,11 +66,13 @@ def run(self, message: Message, location: str = "true", timeout: float = None, r
req.image = base64.b64encode(inp.raw_image)
if inp.url:
req.url = inp.url
if not isinstance(location, str) or location not in ('true', 'false'):
raise InvalidRequestArgumentError("location must be a string with value 'true' or 'false'")
req.location = location
result = self._recognize(req, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = QRcodeOutMsg(**result_dict)
return Message(content=out.model_dump())
return Message(content=dict(out))

def _recognize(self, request: QRcodeRequest, timeout: float = None,
retry: int = 0) -> QRcodeResponse:
Expand Down
2 changes: 1 addition & 1 deletion appbuilder/core/components/table_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def run(self, message: Message, timeout: float = None, retry: int = 0) -> Messag
result = self._recognize(req, timeout, retry)
result_dict = proto.Message.to_dict(result)
out = TableOCROutMsg(**result_dict)
return Message(content=out.model_dump())
return Message(content=dict(out))

def _recognize(self, request: TableOCRRequest, timeout: float = None,
retry: int = 0) -> TableOCRResponse:
Expand Down