chore(api/core): apply ruff reformatting (#7624)
This commit is contained in:
@@ -12,19 +12,20 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def check_moderation(model_config: ModelConfigWithCredentialsEntity, text: str) -> bool:
|
||||
moderation_config = hosting_configuration.moderation_config
|
||||
if (moderation_config and moderation_config.enabled is True
|
||||
and 'openai' in hosting_configuration.provider_map
|
||||
and hosting_configuration.provider_map['openai'].enabled is True
|
||||
if (
|
||||
moderation_config
|
||||
and moderation_config.enabled is True
|
||||
and "openai" in hosting_configuration.provider_map
|
||||
and hosting_configuration.provider_map["openai"].enabled is True
|
||||
):
|
||||
using_provider_type = model_config.provider_model_bundle.configuration.using_provider_type
|
||||
provider_name = model_config.provider
|
||||
if using_provider_type == ProviderType.SYSTEM \
|
||||
and provider_name in moderation_config.providers:
|
||||
hosting_openai_config = hosting_configuration.provider_map['openai']
|
||||
if using_provider_type == ProviderType.SYSTEM and provider_name in moderation_config.providers:
|
||||
hosting_openai_config = hosting_configuration.provider_map["openai"]
|
||||
|
||||
# 2000 text per chunk
|
||||
length = 2000
|
||||
text_chunks = [text[i:i + length] for i in range(0, len(text), length)]
|
||||
text_chunks = [text[i : i + length] for i in range(0, len(text), length)]
|
||||
|
||||
if len(text_chunks) == 0:
|
||||
return True
|
||||
@@ -34,15 +35,13 @@ def check_moderation(model_config: ModelConfigWithCredentialsEntity, text: str)
|
||||
try:
|
||||
model_type_instance = OpenAIModerationModel()
|
||||
moderation_result = model_type_instance.invoke(
|
||||
model='text-moderation-stable',
|
||||
credentials=hosting_openai_config.credentials,
|
||||
text=text_chunk
|
||||
model="text-moderation-stable", credentials=hosting_openai_config.credentials, text=text_chunk
|
||||
)
|
||||
|
||||
if moderation_result is True:
|
||||
return True
|
||||
except Exception as ex:
|
||||
logger.exception(ex)
|
||||
raise InvokeBadRequestError('Rate limit exceeded, please try again later.')
|
||||
raise InvokeBadRequestError("Rate limit exceeded, please try again later.")
|
||||
|
||||
return False
|
||||
|
Reference in New Issue
Block a user