This commit is contained in:
monosans 2023-10-06 07:47:56 +00:00 committed by GitHub
commit 7f42c0b966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import aiohttp
import asyncio
import starlette
from typing import Set
from rich import print
from dotenv import load_dotenv
@ -23,6 +24,8 @@ CRITICAL_API_ERRORS = ['invalid_api_key', 'account_deactivated']
keymanager = providerkeys.manager
background_tasks: Set[asyncio.Task] = set()
async def respond(
path: str='/v1/chat/completions',
user: dict=None,
@ -154,7 +157,7 @@ async def respond(
if (not is_stream) and server_json_response:
yield json.dumps(server_json_response)
asyncio.create_task(
task = asyncio.create_task(
after_request.after_request(
incoming_request=incoming_request,
target_request=target_request,
@ -166,3 +169,5 @@ async def respond(
model=model,
)
)
background_tasks.add(task)
task.add_done_callback(background_tasks.discard)