Coverage for src/fastoai/models/generated/file_object.py: 83%

1 from datetime import datetime

2 from typing import Annotated, Literal

3

4 from openai.types.file_object import FileObject as _FileObject

5 from pydantic import field_serializer

6 from sqlalchemy.ext.asyncio import AsyncAttrs

7 from sqlmodel import Enum, Field, SQLModel

8

9 from .._utils import now, random_id_with_prefix

10

11

12 class FileObject(AsyncAttrs, SQLModel, table=True):

13 __tablename__ = 'file'

14 id: Annotated[str, Field(primary_key=True, default_factory=random_id_with_prefix('file-'))]

15 bytes: int

16 created_at: Annotated[datetime, Field(default_factory=now)]

17 filename: str

18 purpose: Annotated[Literal['assistants', 'assistants_output', 'batch', 'batch_output', 'fine-tune', 'fine-tune-results', 'vision'], Field(sa_type=Enum('assistants', 'assistants_output', 'batch', 'batch_output', 'fine-tune', 'fine-tune-results', 'vision'))]

19 status: Annotated[Literal['uploaded', 'processed', 'error'], Field(sa_type=Enum('uploaded', 'processed', 'error'))]

20 status_details: str | None = None

21

22 async def to_openai_model(self) -> _FileObject:

23 value = self.model_dump(by_alias=True)

24 value['object'] = 'file'

25 return _FileObject.model_validate(value)

26

27 @field_serializer('created_at')

28 def serialize_datetime(self, dt: datetime) -> int:

29 return int(dt.timestamp())