Dont wait forever on openai issues.
This commit is contained in:
parent
7af0a7aa81
commit
61a4cfde7e
@ -47,7 +47,7 @@ class AIResponder(object):
|
|||||||
return messages, history
|
return messages, history
|
||||||
|
|
||||||
async def draw(self, description: str) -> BytesIO:
|
async def draw(self, description: str) -> BytesIO:
|
||||||
while True:
|
for _ in range(7):
|
||||||
try:
|
try:
|
||||||
response = await openai.Image.acreate(prompt=description, n=1, size="512x512")
|
response = await openai.Image.acreate(prompt=description, n=1, size="512x512")
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@ -55,10 +55,11 @@ class AIResponder(object):
|
|||||||
return BytesIO(await image.read())
|
return BytesIO(await image.read())
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.warning(f"Failed to generate image {repr(description)}: {repr(err)}")
|
logging.warning(f"Failed to generate image {repr(description)}: {repr(err)}")
|
||||||
|
raise RuntimeError(f"Failed to generate image {repr(description)} after multiple retries")
|
||||||
|
|
||||||
async def send(self, message: AIMessage) -> AIResponse:
|
async def send(self, message: AIMessage) -> AIResponse:
|
||||||
limit = self.config["history-limit"]
|
limit = self.config["history-limit"]
|
||||||
while True:
|
for _ in range(14):
|
||||||
messages, history = self._message(message, limit)
|
messages, history = self._message(message, limit)
|
||||||
try:
|
try:
|
||||||
result = await openai.ChatCompletion.acreate(model=self.config["model"],
|
result = await openai.ChatCompletion.acreate(model=self.config["model"],
|
||||||
@ -84,3 +85,4 @@ class AIResponder(object):
|
|||||||
response['staff'],
|
response['staff'],
|
||||||
response['picture'],
|
response['picture'],
|
||||||
response['hack'])
|
response['hack'])
|
||||||
|
raise RuntimeError(f"Failed to generate answer after multiple retries")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user