diff --git a/aidial_adapter_vertexai/chat/gemini/processor.py b/aidial_adapter_vertexai/chat/attachment_processor.py similarity index 100% rename from aidial_adapter_vertexai/chat/gemini/processor.py rename to aidial_adapter_vertexai/chat/attachment_processor.py diff --git a/aidial_adapter_vertexai/chat/claude/conversation_factory.py b/aidial_adapter_vertexai/chat/claude/conversation_factory.py index 890dace..aa38742 100644 --- a/aidial_adapter_vertexai/chat/claude/conversation_factory.py +++ b/aidial_adapter_vertexai/chat/claude/conversation_factory.py @@ -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 diff --git a/aidial_adapter_vertexai/chat/claude/prompt/claude_3.py b/aidial_adapter_vertexai/chat/claude/prompt/claude_3.py index 01a72bf..f047d25 100644 --- a/aidial_adapter_vertexai/chat/claude/prompt/claude_3.py +++ b/aidial_adapter_vertexai/chat/claude/prompt/claude_3.py @@ -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 @@ -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, ) @@ -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() diff --git a/aidial_adapter_vertexai/chat/conversation/inputs.py b/aidial_adapter_vertexai/chat/conversation/converters.py similarity index 98% rename from aidial_adapter_vertexai/chat/conversation/inputs.py rename to aidial_adapter_vertexai/chat/conversation/converters.py index 7a3b45d..e0825f5 100644 --- a/aidial_adapter_vertexai/chat/conversation/inputs.py +++ b/aidial_adapter_vertexai/chat/conversation/converters.py @@ -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 diff --git a/aidial_adapter_vertexai/chat/gemini/processors.py b/aidial_adapter_vertexai/chat/gemini/processors.py index 29b4bdb..1f57bb4 100644 --- a/aidial_adapter_vertexai/chat/gemini/processors.py +++ b/aidial_adapter_vertexai/chat/gemini/processors.py @@ -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, diff --git a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro.py b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro.py index 9031abf..f566a07 100644 --- a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro.py +++ b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro.py @@ -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 diff --git a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro_vision.py b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro_vision.py index cbee223..14a0e72 100644 --- a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro_vision.py +++ b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_0_pro_vision.py @@ -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, diff --git a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_5.py b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_5.py index 6f49de6..7ac8a00 100644 --- a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_5.py +++ b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_1_5.py @@ -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, diff --git a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_2.py b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_2.py index cc4331d..e98ff87 100644 --- a/aidial_adapter_vertexai/chat/gemini/prompt/gemini_2.py +++ b/aidial_adapter_vertexai/chat/gemini/prompt/gemini_2.py @@ -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,