diff --git a/endpoints/OAI/types/chat_completion.py b/endpoints/OAI/types/chat_completion.py index 561d9bc..405a609 100644 --- a/endpoints/OAI/types/chat_completion.py +++ b/endpoints/OAI/types/chat_completion.py @@ -56,7 +56,7 @@ class ChatCompletionStreamChoice(BaseModel): # Inherited from common request class ChatCompletionRequest(CommonCompletionRequest): - messages: List[ChatCompletionMessage] = Field(default_factory=list) + messages: List[ChatCompletionMessage] prompt_template: Optional[str] = None add_generation_prompt: Optional[bool] = True template_vars: Optional[dict] = Field( diff --git a/endpoints/OAI/utils/chat_completion.py b/endpoints/OAI/utils/chat_completion.py index f9a556f..bfed45a 100644 --- a/endpoints/OAI/utils/chat_completion.py +++ b/endpoints/OAI/utils/chat_completion.py @@ -207,12 +207,11 @@ async def _append_template_metadata(data: ChatCompletionRequest, template_vars: if isinstance(data.stop, str): data.stop = [data.stop] + template_metadata.stop_strings else: - data.stop += template_metadata.stop_strings + data.stop.extend(template_metadata.stop_strings) # Tool call start strings if template_metadata.tool_starts: - if data.tool_call_start is None: - data.tool_call_start = template_metadata.tool_starts + data.tool_call_start.extend(template_metadata.tool_starts) # Append to stop strings to halt for a tool call generation data.stop.extend(template_metadata.tool_starts) @@ -245,10 +244,6 @@ async def format_messages_with_template( if message.tool_calls: message.tool_calls_json = ToolCallProcessor.to_json(message.tool_calls) - # The tools variable is inspectable in the template, so - # store the list of dicts rather than the ToolCallProcessor object. - message.tool_calls = ToolCallProcessor.dump(message.tool_calls) - message_dicts.append(message.model_dump(exclude_none=True)) # Get all special tokens