Skip to content

Commit

Permalink
Merge pull request #182 from hermitgreen/master
Browse files Browse the repository at this point in the history
新增文生图敏感词风控判断逻辑
  • Loading branch information
seiriosPlus authored Mar 13, 2024
2 parents 6e3cbcc + ba31333 commit fad4cd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
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

0 comments on commit fad4cd4

Please sign in to comment.