Skip to content

Commit

Permalink
Merge pull request #173 from hermitgreen/master
Browse files Browse the repository at this point in the history
批量修复json返回的visible_scope
  • Loading branch information
seiriosPlus authored Mar 9, 2024
2 parents 6b61b5d + 9230893 commit a4acbc2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
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

0 comments on commit a4acbc2

Please sign in to comment.