Skip to content

Commit 90fa1cc

Browse files
committed
Refactor message content handling in schemas.py to add capability for image content
1 parent df2124e commit 90fa1cc

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: schemas.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
from typing import List, Optional
2-
from pydantic import BaseModel, ConfigDict
1+
from typing import List, Union, Optional
2+
from pydantic import BaseModel, RootModel, ConfigDict
33

4+
class ImageContent(BaseModel):
5+
type: str
6+
image_url: dict
7+
8+
class TextContent(BaseModel):
9+
type: str
10+
text: str
11+
12+
class MessageContent(RootModel):
13+
root: Union[TextContent, ImageContent]
414

515
class OpenAIChatMessage(BaseModel):
616
role: str
7-
content: str | List
17+
content: Union[str, List[MessageContent]]
818

919
model_config = ConfigDict(extra="allow")
1020

11-
1221
class OpenAIChatCompletionForm(BaseModel):
1322
stream: bool = True
1423
model: str
1524
messages: List[OpenAIChatMessage]
1625

1726
model_config = ConfigDict(extra="allow")
1827

19-
2028
class FilterForm(BaseModel):
2129
body: dict
2230
user: Optional[dict] = None
23-
model_config = ConfigDict(extra="allow")
31+
model_config = ConfigDict(extra="allow")

0 commit comments

Comments
 (0)