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

批量修复json返回的visible_scope #173

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
14 changes: 12 additions & 2 deletions appbuilder/core/components/handwrite_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,20 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
response = self._recognize(req)
result[file_name] = [w.words for w in response.words_result]

result = json.dumps(result, ensure_ascii=False)
if streaming:
yield json.dumps(result, ensure_ascii=False)
yield {
"type": "text",
"text": result,
"visible_scope": 'llm',
}
yield {
"type": "text",
"text": "",
"visible_scope": "user",
}
else:
return json.dumps(result, ensure_ascii=False)
return result

def _recognize(self, request: HandwriteOCRRequest, timeout: float = None, retry: int = 0) -> HandwriteOCRResponse:
r"""调用底层接口进行通用文字识别
Expand Down
14 changes: 12 additions & 2 deletions appbuilder/core/components/mix_card_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,17 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
out.direction = response.direction
result[file_name] = out.dict()

result = json.dumps(result, ensure_ascii=False)
if streaming:
yield json.dumps(result, ensure_ascii=False)
yield {
"type": "text",
"text": result,
"visible_scope": 'llm',
}
yield {
"type": "text",
"text": "",
"visible_scope": "user",
}
else:
return json.dumps(result, ensure_ascii=False)
return result
15 changes: 13 additions & 2 deletions appbuilder/core/components/qrcode_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,18 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
req.location = location
resp = self._recognize(req)
result[file_name] = [item["text"] for item in proto.Message.to_dict(resp).get("codes_result", [])]

result = json.dumps(result, ensure_ascii=False)
if streaming:
yield json.dumps(result, ensure_ascii=False)
yield {
"type": "text",
"text": result,
"visible_scope": 'llm',
}
yield {
"type": "text",
"text": "",
"visible_scope": "user",
}
else:
return json.dumps(result, ensure_ascii=False)
return result
15 changes: 13 additions & 2 deletions appbuilder/core/components/table_ocr/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,18 @@ def tool_eval(self, name: str, streaming: bool, **kwargs):
tables_result = proto.Message.to_dict(resp)["tables_result"]
markdowns = self.get_table_markdown(tables_result)
result[file_name] = markdowns

result = json.dumps(result, ensure_ascii=False)
if streaming:
yield json.dumps(result, ensure_ascii=False)
yield {
"type": "text",
"text": result,
"visible_scope": 'llm',
}
yield {
"type": "text",
"text": "",
"visible_scope": "user",
}
else:
return json.dumps(result, ensure_ascii=False)
return result
Loading