Skip to content

FilesAPI

autogen.beta.files.api.FilesAPI #

FilesAPI(config)

Bases: FilesClient

Source code in autogen/beta/files/api.py
def __init__(self, config: ModelConfig) -> None:
    self._client = config.create_files_client()

upload async #

upload(*, path=None, data=None, filename=None, purpose=None)

Upload a file to the provider.

Source code in autogen/beta/files/api.py
async def upload(
    self,
    *,
    path: str | PathLike[str] | None = None,
    data: bytes | None = None,
    filename: str | None = None,
    purpose: str | None = None,
) -> UploadedFile:
    """Upload a file to the provider."""
    if path is not None:
        p = Path(path)
        data = p.read_bytes()
        filename = filename or p.name
    if data is None:
        raise ValueError("Either 'path' or 'data' must be provided.")
    if filename is None:
        raise ValueError("'filename' is required when using 'data' without 'path'.")
    return await self._client.upload(data, filename, purpose)

read async #

read(file_id)

Download file content by ID.

Source code in autogen/beta/files/api.py
async def read(self, file_id: str) -> FileContent:
    """Download file content by ID."""
    return await self._client.read(file_id)

list async #

list()

List all files in the provider.

Source code in autogen/beta/files/api.py
async def list(self) -> list[UploadedFile]:
    """List all files in the provider."""
    return await self._client.list()

delete async #

delete(file_id)

Delete a file by ID.

Source code in autogen/beta/files/api.py
async def delete(self, file_id: str) -> None:
    """Delete a file by ID."""
    await self._client.delete(file_id)