You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gcgj-dify-1.7.0/api/core/llm/moderation.py

21 lines
585 B
Python

import openai
from flask import current_app
from models.provider import ProviderName
class Moderation:
def __init__(self, provider: str, api_key: str):
self.provider = provider
self.api_key = api_key
# Use proxy openai base
if current_app.config['OPENAI_API_BASE'] is not None:
openai.api_base = current_app.config['OPENAI_API_BASE']
if self.provider == ProviderName.OPENAI.value:
self.client = openai.Moderation
def moderate(self, text):
return self.client.create(input=text, api_key=self.api_key)