Skip to content

Commit

Permalink
feat(provider_engine): add support for uploading text and PDF files t…
Browse files Browse the repository at this point in the history
…o Anthropic

Fixes #485
  • Loading branch information
AAClause committed Jan 28, 2025
1 parent f9ac163 commit f3058ea
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 358 deletions.
14 changes: 13 additions & 1 deletion basilisk/conversation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from .attached_file import (
URL_PATTERN,
AttachmentFile,
AttachmentFileTypes,
ImageFile,
NotImageError,
get_mime_type,
parse_supported_attachment_formats,
)
from .conversation_helper import PROMPT_TITLE
from .conversation_model import (
Conversation,
Message,
MessageBlock,
MessageRoleEnum,
)
from .image_model import URL_PATTERN, ImageFile, ImageFileTypes, NotImageError

__all__ = [
"AttachmentFile",
"AttachmentFileTypes",
"Conversation",
"get_mime_type",
"ImageFile",
"ImageFileTypes",
"Message",
"MessageBlock",
"MessageRoleEnum",
"NotImageError",
"parse_supported_attachment_formats",
"PROMPT_TITLE",
"URL_PATTERN",
]
10 changes: 6 additions & 4 deletions basilisk/conversation/conversation_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from basilisk.config import conf
from basilisk.decorators import measure_time

from .image_model import ImageFile, ImageFileTypes
from .attached_file import AttachmentFile, AttachmentFileTypes, ImageFile

if TYPE_CHECKING:
from .conversation_model import Conversation
Expand All @@ -23,11 +23,13 @@


def save_attachments(
attachments: list[ImageFile], attachment_path: str, fs: ZipFileSystem
attachments: list[AttachmentFile | ImageFile],
attachment_path: str,
fs: ZipFileSystem,
):
attachment_mapping = {}
for attachment in attachments:
if attachment.type == ImageFileTypes.IMAGE_URL:
if attachment.type == AttachmentFileTypes.URL:
continue
new_location = f"{attachment_path}/{attachment.location.name}"
with attachment.location.open(mode="rb") as attachment_file:
Expand Down Expand Up @@ -56,7 +58,7 @@ def create_conv_main_file(conversation: Conversation, fs: ZipFileSystem):

def restore_attachments(attachments: list[ImageFile], storage_path: UPath):
for attachment in attachments:
if attachment.type == ImageFileTypes.IMAGE_URL:
if attachment.type == AttachmentFileTypes.URL:
continue
new_path = storage_path / attachment.location.name
with attachment.location.open(mode="rb") as attachment_file:
Expand Down
4 changes: 2 additions & 2 deletions basilisk/conversation/conversation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from basilisk.provider_ai_model import AIModelInfo

from .attached_file import AttachmentFile, ImageFile
from .conversation_helper import create_bskc_file, open_bskc_file
from .image_model import ImageFile


class MessageRoleEnum(Enum):
Expand All @@ -21,7 +21,7 @@ class MessageRoleEnum(Enum):
class Message(BaseModel):
role: MessageRoleEnum
content: str
attachments: list[ImageFile] | None = Field(default=None)
attachments: list[AttachmentFile | ImageFile] | None = Field(default=None)


class MessageBlock(BaseModel):
Expand Down
307 changes: 0 additions & 307 deletions basilisk/conversation/image_model.py

This file was deleted.

Loading

0 comments on commit f3058ea

Please sign in to comment.