mirror of
https://github.com/open-webui/open-webui
synced 2025-02-22 13:18:25 +00:00
Merge pull request #10377 from Seniorsimo/chat-message-validator
**fix** ChatMessage validator: content can be null when using tools
This commit is contained in:
commit
ea3f873ae9
@ -26,7 +26,7 @@ from fastapi import (
|
||||
)
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, validator
|
||||
from starlette.background import BackgroundTask
|
||||
|
||||
|
||||
@ -936,10 +936,19 @@ async def generate_completion(
|
||||
|
||||
class ChatMessage(BaseModel):
|
||||
role: str
|
||||
content: str
|
||||
content: Optional[str] = None
|
||||
tool_calls: Optional[list[dict]] = None
|
||||
images: Optional[list[str]] = None
|
||||
|
||||
@validator("content", pre=True)
|
||||
@classmethod
|
||||
def check_at_least_one_field(cls, field_value, values, **kwargs):
|
||||
# Raise an error if both 'content' and 'tool_calls' are None
|
||||
if field_value is None and ("tool_calls" not in values or values["tool_calls"] is None):
|
||||
raise ValueError("At least one of 'content' or 'tool_calls' must be provided")
|
||||
|
||||
return field_value
|
||||
|
||||
|
||||
class GenerateChatCompletionForm(BaseModel):
|
||||
model: str
|
||||
|
Loading…
Reference in New Issue
Block a user