Repository: phidatahq/phidata
File: libs/agno/agno/models/openai/responses.py (Python)

Code before:
        - file_url: when the file has a URL (most efficient, OpenAI fetches server-side)
        - file_data: when the file has local content or filepath (base64 encoded)
        - file_id: when the file has an OpenAI file ID (starts with "file-")
        """
        import base64
        import mimetypes
        import os

        # Determine filename
        filename = file.filename or file.name
        if not filename and file.filepath:
            filename = os.path.basename(str(file.filepath))
        if not filename:
            filename = "document"

        # URL passthrough — let OpenAI fetch it server-side
        if file.url:
            return {
                "type": "input_file",
                "file_url": file.url,
            }

        # Local file or raw bytes — base64 encode as data URI
        if file.filepath or file.content:
            content_bytes = file.get_content_bytes()
            if content_bytes is None:
                return None

            # Resolve MIME type
            mime_type = file.mime_type
            if not mime_type:
                source_path = str(file.filepath) if file.filepath else filename
                mime_type = mimetypes.guess_type(source_path)[0] or "application/octet-stream"

            encoded = base64.b64encode(content_bytes).decode("utf-8")
            file_data = f"data:{mime_type};base64,{encoded}"

            return {
                "type": "input_file",
                "filename": filename,
                "file_data": file_data,
            }

        # OpenAI file ID reference
        if file.id and isinstance(file.id, str) and file.id.startswith("file-"):
            return {
                "type": "input_file",
                "file_id": file.id,
            }

        return None

Review comment (bug):
When `get_content_bytes()` returns None, the file is silently skipped. Let's add a `log_warning` to help users debug why their file wasn't included.

Code after:
        - file_url: when the file has a URL (most efficient, OpenAI fetches server-side)
        - file_data: when the file has local content or filepath (base64 encoded)
        - file_id: when the file has an OpenAI file ID (starts with "file-")
        """
        import base64
        import mimetypes
        import os

        # Determine filename
        filename = file.filename or file.name
        if not filename and file.filepath:
            filename = os.path.basename(str(file.filepath))
        if not filename:
            filename = "document"

        # URL passthrough — let OpenAI fetch it server-side
        if file.url:
            return {
                "type": "input_file",
                "file_url": file.url,
            }

        # Local file or raw bytes — base64 encode as data URI
        if file.filepath or file.content:
            content_bytes = file.get_content_bytes()
            if content_bytes is None:
                log_warning(f"Could not read content from file: {file.filepath or file.filename or 'unknown'}")
                return None

            # Resolve MIME type
            mime_type = file.mime_type
            if not mime_type:
                source_path = str(file.filepath) if file.filepath else filename
                mime_type = mimetypes.guess_type(source_path)[0] or "application/octet-stream"

            encoded = base64.b64encode(content_bytes).decode("utf-8")
            file_data = f"data:{mime_type};base64,{encoded}"

            return {
                "type": "input_file",
                "filename": filename,
                "file_data": file_data,
            }

        # OpenAI file ID reference
        if file.id and isinstance(file.id, str) and file.id.startswith("file-"):
            return {
                "type": "input_file",
                "file_id": file.id,
            }