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

新增文生图敏感词风控判断逻辑 #182

Merged
merged 1 commit into from
Mar 13, 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 @@ -89,3 +89,9 @@ class InvalidRequestArgumentError(BaseRPCException):
r"""InvalidRequestArgumentError invalid request param
"""
pass


class RiskInputException(BaseRPCException):
r"""RiskInputException
"""
pass
18 changes: 11 additions & 7 deletions appbuilder/core/components/text_to_image/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.message import Message
from appbuilder.core._client import HTTPClient
from appbuilder.core._exception import AppBuilderServerException
from appbuilder.core._exception import AppBuilderServerException, RiskInputException
from appbuilder.core.components.text_to_image.model import Text2ImageSubmitRequest, Text2ImageQueryRequest, \
Text2ImageQueryResponse, Text2ImageSubmitResponse, Text2ImageOutMessage, Text2ImageInMessage

Expand Down Expand Up @@ -197,13 +197,17 @@ def tool_eval(
query = origin_query
try:
result = self.run(Message({"prompt": query}))
result = {
'event': 'image',
'type': 'image',
'text': result.content['img_urls'][0],
}
except Exception as e:
raise AppBuilderServerException(f'绘图时发生错误:{e}')
raise AppBuilderServerException(f'绘图服务发生错误:{e}')

if len(result.content['img_urls']) == 0:
raise RiskInputException(f'query:{query} 中可能存在敏感词')

result = {
'event': 'image',
'type': 'image',
'text': result.content['img_urls'][0],
}
if streaming:
yield result
else:
Expand Down
Loading