mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-26 01:30:20 +01:00
Prevent deadlocks in OpenAI API with simultaneous requests
This commit is contained in:
parent
21ed9a260e
commit
effb3aef42
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
@ -46,6 +47,9 @@ params = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
streaming_semaphore = asyncio.Semaphore(1)
|
||||||
|
|
||||||
|
|
||||||
def verify_api_key(authorization: str = Header(None)) -> None:
|
def verify_api_key(authorization: str = Header(None)) -> None:
|
||||||
expected_api_key = shared.args.api_key
|
expected_api_key = shared.args.api_key
|
||||||
if expected_api_key and (authorization is None or authorization != f"Bearer {expected_api_key}"):
|
if expected_api_key and (authorization is None or authorization != f"Bearer {expected_api_key}"):
|
||||||
@ -84,6 +88,7 @@ async def openai_completions(request: Request, request_data: CompletionRequest):
|
|||||||
|
|
||||||
if request_data.stream:
|
if request_data.stream:
|
||||||
async def generator():
|
async def generator():
|
||||||
|
async with streaming_semaphore:
|
||||||
response = OAIcompletions.stream_completions(to_dict(request_data), is_legacy=is_legacy)
|
response = OAIcompletions.stream_completions(to_dict(request_data), is_legacy=is_legacy)
|
||||||
for resp in response:
|
for resp in response:
|
||||||
yield {"data": json.dumps(resp)}
|
yield {"data": json.dumps(resp)}
|
||||||
@ -102,6 +107,7 @@ async def openai_chat_completions(request: Request, request_data: ChatCompletion
|
|||||||
|
|
||||||
if request_data.stream:
|
if request_data.stream:
|
||||||
async def generator():
|
async def generator():
|
||||||
|
async with streaming_semaphore:
|
||||||
response = OAIcompletions.stream_chat_completions(to_dict(request_data), is_legacy=is_legacy)
|
response = OAIcompletions.stream_chat_completions(to_dict(request_data), is_legacy=is_legacy)
|
||||||
for resp in response:
|
for resp in response:
|
||||||
yield {"data": json.dumps(resp)}
|
yield {"data": json.dumps(resp)}
|
||||||
|
Loading…
Reference in New Issue
Block a user