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

表格文字识别、条形码/二维码识别、身份证混贴识别、手写文字识别支持function call #170

Merged
merged 1 commit into from
Mar 7, 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: 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
Loading