mirror of
https://github.com/NovaOSS/nova-api.git
synced 2024-11-25 18:43:57 +01:00
Compare commits
1 commit
0b08c5b712
...
03f8c9ad0a
Author | SHA1 | Date | |
---|---|---|---|
03f8c9ad0a |
|
@ -7,7 +7,7 @@ import aiohttp
|
|||
import asyncio
|
||||
import starlette
|
||||
|
||||
from typing import Any, Coroutine, Set
|
||||
from typing import Set
|
||||
from rich import print
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
@ -24,18 +24,7 @@ CRITICAL_API_ERRORS = ['invalid_api_key', 'account_deactivated']
|
|||
|
||||
keymanager = providerkeys.manager
|
||||
|
||||
background_tasks: Set[asyncio.Task[Any]] = set()
|
||||
|
||||
|
||||
def create_background_task(coro: Coroutine[Any, Any, Any]) -> None:
|
||||
"""asyncio.create_task, which prevents the task from being garbage collected.
|
||||
|
||||
https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task
|
||||
"""
|
||||
task = asyncio.create_task(coro)
|
||||
background_tasks.add(task)
|
||||
task.add_done_callback(background_tasks.discard)
|
||||
|
||||
background_tasks: Set[asyncio.Task] = set()
|
||||
|
||||
async def respond(
|
||||
path: str='/v1/chat/completions',
|
||||
|
@ -180,7 +169,7 @@ async def respond(
|
|||
if (not is_stream) and server_json_response:
|
||||
yield json.dumps(server_json_response)
|
||||
|
||||
create_background_task(
|
||||
task = asyncio.create_task(
|
||||
after_request.after_request(
|
||||
incoming_request=incoming_request,
|
||||
target_request=target_request,
|
||||
|
@ -192,3 +181,5 @@ async def respond(
|
|||
model=model,
|
||||
)
|
||||
)
|
||||
background_tasks.add(task)
|
||||
task.add_done_callback(background_tasks.discard)
|
||||
|
|
Loading…
Reference in a new issue