Skip to content

Commit

Permalink
chore: moving modules around
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik committed Jan 23, 2025
1 parent 38faa35 commit 580ccab
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
)
from anthropic.types.image_block_param import Source

from aidial_adapter_vertexai.chat.attachment_processor import FileTypes
from aidial_adapter_vertexai.chat.claude.prompt.base import ClaudeConversation
from aidial_adapter_vertexai.chat.conversation.factory import (
ConversationFactoryBase,
)
from aidial_adapter_vertexai.chat.gemini.processor import FileTypes

ClaudePart = (
str
Expand Down
34 changes: 22 additions & 12 deletions aidial_adapter_vertexai/chat/claude/prompt/claude_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
from aidial_sdk.chat_completion import Message
from anthropic.types import MessageParam, TextBlockParam

from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessor,
AttachmentProcessorsBase,
max_count_validator,
seq_validators,
)
from aidial_adapter_vertexai.chat.claude.conversation_factory import (
SUPPORTED_IMAGE_TYPES,
ClaudeConversationFactory,
ClaudePart,
)
from aidial_adapter_vertexai.chat.claude.prompt.base import ClaudePrompt
from aidial_adapter_vertexai.chat.conversation.inputs import (
from aidial_adapter_vertexai.chat.conversation.converters import (
messages_to_conversation,
)
from aidial_adapter_vertexai.chat.errors import UserError, ValidationError
from aidial_adapter_vertexai.chat.gemini.processor import (
AttachmentProcessor,
AttachmentProcessorsBase,
max_count_validator,
seq_validators,
)
from aidial_adapter_vertexai.chat.gemini.prompt.gemini_1_5 import (
get_usage_message,
)
from aidial_adapter_vertexai.chat.tools import ToolsConfig
from aidial_adapter_vertexai.dial_api.storage import FileStorage
from aidial_adapter_vertexai.utils.list import group_by
Expand All @@ -47,7 +44,7 @@ async def parse_claude_3_prompt(

processors = AttachmentProcessorsClaude(
conversation_factory=conversation_factory,
processors=[create_image_processor(20)] if supports_vision else [],
processors=[_create_image_processor(20)] if supports_vision else [],
file_storage=file_storage,
)

Expand Down Expand Up @@ -95,9 +92,22 @@ def _merge(
return ListProjection(group_by(messages.list, _key, lambda x: x, _merge))


def create_image_processor(max_count: int) -> AttachmentProcessor:
def _create_image_processor(max_count: int) -> AttachmentProcessor:
# NOTE: not checked condition: The maximum allowed image file size is 5 MB
return AttachmentProcessor(
file_types=SUPPORTED_IMAGE_TYPES,
init_validator=seq_validators(None, max_count_validator(max_count)),
)


def get_usage_message(exts: List[str]) -> str:
return f"""
The application answers queries about attached images.
Attach images and ask questions about them in the same message.
Supported document extensions: {', '.join(exts)}.
Examples of queries:
- "Describe the picture" for one image,
- "What is depicted in these images?", "Compare the images" for multiple images.
""".strip()
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from aidial_sdk.chat_completion import Message, Role

from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessorsBase,
)
from aidial_adapter_vertexai.chat.conversation.factory import (
ConversationFactoryBase,
ConversationT,
PartT,
)
from aidial_adapter_vertexai.chat.errors import ValidationError
from aidial_adapter_vertexai.chat.gemini.processor import (
AttachmentProcessorsBase,
)
from aidial_adapter_vertexai.chat.tools import ToolsConfig

FunctionName = str
Expand Down
2 changes: 1 addition & 1 deletion aidial_adapter_vertexai/chat/gemini/processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from aidial_adapter_vertexai.chat.gemini.processor import (
from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessor,
InitValidator,
max_count_validator,
Expand Down
6 changes: 4 additions & 2 deletions aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from aidial_sdk.chat_completion import Message

from aidial_adapter_vertexai.chat.conversation.inputs import (
from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessors,
)
from aidial_adapter_vertexai.chat.conversation.converters import (
messages_to_conversation,
)
from aidial_adapter_vertexai.chat.errors import UserError, ValidationError
from aidial_adapter_vertexai.chat.gemini.conversation_factory import (
ConversationFactory,
)
from aidial_adapter_vertexai.chat.gemini.processor import AttachmentProcessors
from aidial_adapter_vertexai.chat.gemini.prompt.base import GeminiPrompt
from aidial_adapter_vertexai.chat.static_tools import StaticToolsConfig
from aidial_adapter_vertexai.chat.tools import ToolsConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

from aidial_sdk.chat_completion import Message, Role

from aidial_adapter_vertexai.chat.conversation.inputs import (
from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessors,
exclusive_validator,
)
from aidial_adapter_vertexai.chat.conversation.converters import (
messages_to_conversation,
)
from aidial_adapter_vertexai.chat.errors import UserError, ValidationError
from aidial_adapter_vertexai.chat.gemini.conversation_factory import (
ConversationFactory,
)
from aidial_adapter_vertexai.chat.gemini.processor import (
AttachmentProcessors,
exclusive_validator,
)
from aidial_adapter_vertexai.chat.gemini.processors import (
get_image_processor,
get_pdf_processor,
Expand Down
6 changes: 4 additions & 2 deletions aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

from aidial_sdk.chat_completion import Message

from aidial_adapter_vertexai.chat.conversation.inputs import (
from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessors,
)
from aidial_adapter_vertexai.chat.conversation.converters import (
messages_to_conversation,
)
from aidial_adapter_vertexai.chat.errors import UserError, ValidationError
from aidial_adapter_vertexai.chat.gemini.conversation_factory import (
ConversationFactory,
)
from aidial_adapter_vertexai.chat.gemini.processor import AttachmentProcessors
from aidial_adapter_vertexai.chat.gemini.processors import (
get_audio_processor,
get_image_processor,
Expand Down
8 changes: 4 additions & 4 deletions aidial_adapter_vertexai/chat/gemini/prompt/gemini_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

from aidial_sdk.chat_completion import Message

from aidial_adapter_vertexai.chat.conversation.inputs import (
from aidial_adapter_vertexai.chat.attachment_processor import (
AttachmentProcessorsGenAI,
)
from aidial_adapter_vertexai.chat.conversation.converters import (
messages_to_conversation,
)
from aidial_adapter_vertexai.chat.errors import UserError, ValidationError
from aidial_adapter_vertexai.chat.gemini.conversation_factory import (
GenAIConversationFactory,
)
from aidial_adapter_vertexai.chat.gemini.processor import (
AttachmentProcessorsGenAI,
)
from aidial_adapter_vertexai.chat.gemini.processors import (
get_audio_processor,
get_image_processor,
Expand Down

0 comments on commit 580ccab

Please sign in to comment.