fix: allow openai list message format

This commit is contained in:
Timothy J. Baek 2024-11-03 01:34:45 -08:00
parent 0925c6b33b
commit 4e7951d5fc

View File

@ -817,7 +817,7 @@ class OpenAIChatMessageContent(BaseModel):
class OpenAIChatMessage(BaseModel):
role: str
content: Union[str, OpenAIChatMessageContent]
content: Union[str, list[OpenAIChatMessageContent]]
model_config = ConfigDict(extra="allow")
@ -836,7 +836,15 @@ async def generate_openai_chat_completion(
url_idx: Optional[int] = None,
user=Depends(get_verified_user),
):
try:
completion_form = OpenAIChatCompletionForm(**form_data)
except Exception as e:
log.exception(e)
raise HTTPException(
status_code=400,
detail=str(e),
)
payload = {**completion_form.model_dump(exclude_none=True, exclude=["metadata"])}
if "metadata" in payload:
del payload["metadata"]