mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-04-28 02:23:52 +02:00
update: moderation add asyncio func impl
This commit is contained in:
parent
ebb5ec9c0a
commit
1463b7d8a6
1 changed files with 17 additions and 3 deletions
|
|
@ -6,7 +6,7 @@
|
|||
"""
|
||||
import asyncio
|
||||
import time
|
||||
from typing import List, NamedTuple, Union
|
||||
from typing import NamedTuple, Union
|
||||
|
||||
import openai
|
||||
from openai.error import APIConnectionError
|
||||
|
|
@ -296,7 +296,7 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
return CONFIG.max_tokens_rsp
|
||||
return get_max_completion_tokens(messages, self.model, CONFIG.max_tokens_rsp)
|
||||
|
||||
def moderation(self, content: Union[str, List[str]]):
|
||||
def moderation(self, content: Union[str, list[str]]):
|
||||
try:
|
||||
if not content:
|
||||
logger.error("content cannot be empty!")
|
||||
|
|
@ -306,6 +306,20 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
|
|||
except Exception as e:
|
||||
logger.error(f"moderating failed:{e}")
|
||||
|
||||
def _moderation(self, content: Union[str]):
|
||||
def _moderation(self, content: Union[str, list[str]]):
|
||||
rsp = self.llm.Moderation.create(input=content)
|
||||
return rsp
|
||||
|
||||
async def amoderation(self, content: Union[str, list[str]]):
|
||||
try:
|
||||
if not content:
|
||||
logger.error("content cannot be empty!")
|
||||
else:
|
||||
rsp = await self._amoderation(content=content)
|
||||
return rsp
|
||||
except Exception as e:
|
||||
logger.error(f"moderating failed:{e}")
|
||||
|
||||
async def _amoderation(self, content: Union[str, list[str]]):
|
||||
rsp = await self.llm.Moderation.acreate(input=content)
|
||||
return rsp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue