Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ChatCompletionRequest(BaseModel):
top_k: Optional[int] = None
max_length: Optional[int] = None
stream: Optional[bool] = False
stop: Optional[List[str]] = None
stop: Optional[Union[str, List[str]]] = None


class ChatCompletionResponseChoice(BaseModel):
Expand Down Expand Up @@ -143,6 +143,8 @@ async def list_models():

# To work around that unpleasant leading-\n tokenization issue!
def add_extra_stop_words(stop_words):
if isinstance(stop_words, str):
stop_words = [stop_words]
if stop_words:
_stop_words = []
_stop_words.extend(stop_words)
Expand Down Expand Up @@ -397,6 +399,8 @@ async def create_chat_completion(request: ChatCompletionRequest):
gen_kwargs['temperature'] = request.temperature
if request.top_p is not None:
gen_kwargs['top_p'] = request.top_p
if request.max_length is not None:
gen_kwargs['max_length'] = request.max_length

stop_words = add_extra_stop_words(request.stop)
if request.functions:
Expand Down