Fix/async chat serving (#2727)

This commit is contained in:
Sebastian Schoennenbeck
2024-05-03 11:04:14 -07:00
committed by GitHub
parent 7e65477e5e
commit f8e7adda21
5 changed files with 73 additions and 21 deletions
+9 -3
View File
@@ -1,3 +1,4 @@
import asyncio
import codecs
import time
from typing import (AsyncGenerator, AsyncIterator, Awaitable, Iterable, List,
@@ -40,9 +41,11 @@ class OpenAIServingChat(OpenAIServing):
chat_template: Optional[str] = None):
super().__init__(engine=engine,
served_model_names=served_model_names,
lora_modules=lora_modules)
lora_modules=lora_modules,
await_post_init=self._load_chat_template(
chat_template=chat_template))
self.response_role = response_role
self._load_chat_template(chat_template)
def _parse_chat_message_content(
self,
@@ -356,7 +359,10 @@ class OpenAIServingChat(OpenAIServing):
return response
def _load_chat_template(self, chat_template: Optional[str]):
async def _load_chat_template(self, chat_template: Optional[str]):
while self.tokenizer is None:
# Give the parent class time to load the tokenizer
await asyncio.sleep(0.1)
tokenizer = self.tokenizer
if chat_template is not None: