Skip to content

Commit

Permalink
表格文字识别、条形码/二维码识别、身份证混贴识别、手写文字识别支持function call
Browse files Browse the repository at this point in the history
  • Loading branch information
sucuicong committed Mar 7, 2024
1 parent 79c7d3f commit 94a332b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
6 changes: 5 additions & 1 deletion appbuilder/core/components/handwrite_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from appbuilder.core.components.handwrite_ocr.model import *
from appbuilder.core.message import Message
from appbuilder.core._client import HTTPClient
from appbuilder.core import utils

class HandwriteOCR(Component):
r""" 手写文字识别组件
Expand Down Expand Up @@ -106,7 +107,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = HandwriteOCRRequest()
Expand Down
7 changes: 6 additions & 1 deletion appbuilder/core/components/mix_card_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
r"""身份证混贴识别组件"""
import base64
import json

from appbuilder.core import utils
from appbuilder.core._client import HTTPClient
from appbuilder.core._exception import AppBuilderServerException, InvalidRequestArgumentError
from appbuilder.core.component import Component
Expand Down Expand Up @@ -154,7 +156,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")

Expand Down
6 changes: 5 additions & 1 deletion appbuilder/core/components/qrcode_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import json

from appbuilder.core import utils
from appbuilder.core.component import Component
from appbuilder.core.components.qrcode_ocr.model import *
from appbuilder.core.message import Message
Expand Down Expand Up @@ -154,7 +155,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):

file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = QRcodeRequest()
Expand Down
6 changes: 5 additions & 1 deletion appbuilder/core/components/table_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import base64
import json

from appbuilder.core import utils
from appbuilder.core.component import Component
from appbuilder.core.components.table_ocr.model import *
from appbuilder.core.message import Message
Expand Down Expand Up @@ -180,7 +181,10 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
file_names = kwargs.get("files")
file_urls = kwargs.get("file_urls", {})
for file_name in file_names:
file_url = file_urls.get(file_name, None)
if utils.is_url(file_name):
file_url = file_name
else:
file_url = file_urls.get(file_name, None)
if file_url is None:
raise InvalidRequestArgumentError(f"file {file_name} url does not exist")
req = TableOCRRequest()
Expand Down
12 changes: 11 additions & 1 deletion appbuilder/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
import itertools
from typing import List

from urllib.parse import urlparse
from appbuilder.core._client import HTTPClient
from appbuilder.core._exception import TypeNotSupportedException, ModelNotSupportedException
from appbuilder.utils.model_util import GetModelListRequest, Models, model_name_mapping
Expand Down Expand Up @@ -63,6 +63,16 @@ def convert_cloudhub_url(client: HTTPClient, qianfan_url: str) -> str:
return "{}/{}{}".format(client.gateway, cloudhub_url_prefix, url_suffix)


def is_url(string):
"""
判断字符串是否是URL
:param string:
:return:
"""
result = urlparse(string)
return all([result.scheme, result.netloc])


class ModelInfo:
""" 模型信息类 """

Expand Down

0 comments on commit 94a332b

Please sign in to comment.