Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pydantic_ai_slim/pydantic_ai/providers/alibaba.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ def client(self) -> AsyncOpenAI:
def model_profile(model_name: str) -> ModelProfile | None:
base_profile = qwen_model_profile(model_name)

# Wrap/merge into OpenAIModelProfile
openai_profile = OpenAIModelProfile(json_schema_transformer=OpenAIJsonSchemaTransformer).update(base_profile)
# Wrap/merge into OpenAIModelProfile.
# Alibaba's compatible-mode Chat Completions API rejects OpenAI `type:file` content parts,
# so document input must fail client-side with a clear UserError.
openai_profile = OpenAIModelProfile(
json_schema_transformer=OpenAIJsonSchemaTransformer,
openai_chat_supports_document_input=False,
).update(base_profile)

# For Qwen Omni models, force URI audio input encoding
if 'omni' in model_name.lower():
Expand Down
28 changes: 28 additions & 0 deletions tests/providers/test_alibaba_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import pytest

from pydantic_ai.exceptions import UserError
from pydantic_ai.messages import BinaryContent, DocumentUrl
from pydantic_ai.profiles.openai import OpenAIModelProfile

from ..conftest import TestEnv, try_import

with try_import() as imports_successful:
import openai

from pydantic_ai import Agent
Comment thread
dsfaccini marked this conversation as resolved.
Outdated
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers import infer_provider
from pydantic_ai.providers.alibaba import AlibabaProvider

Expand Down Expand Up @@ -64,6 +67,8 @@ def test_qwen_omni_profile_audio_uri():
profile = provider.model_profile('qwen-omni-turbo')
assert isinstance(profile, OpenAIModelProfile)
assert profile.openai_chat_audio_input_encoding == 'uri'
# The document-input flag must survive the omni branch's `.update()` merge.
assert profile.openai_chat_supports_document_input is False


def test_qwen_non_omni_profile_default():
Expand Down Expand Up @@ -92,3 +97,26 @@ def test_alibaba_provider_custom_base_url():
provider = AlibabaProvider(api_key='test-key', base_url='https://custom.endpoint.com/v1')
assert provider.base_url == 'https://custom.endpoint.com/v1'
assert str(provider.client.base_url).rstrip('/') == 'https://custom.endpoint.com/v1'


async def test_alibaba_document_input_not_supported(allow_model_requests: None):
Comment thread
dsfaccini marked this conversation as resolved.
provider = AlibabaProvider(api_key='test-key')
model = OpenAIChatModel(model_name='qwen-max', provider=provider)
agent = Agent(model)

with pytest.raises(UserError, match='alibaba.*does not support document input'):
await agent.run(
[
'Summarize this document',
BinaryContent(data=b'%PDF-1.4 test', media_type='application/pdf'),
]
)


async def test_alibaba_document_url_input_not_supported(allow_model_requests: None):
provider = AlibabaProvider(api_key='test-key')
model = OpenAIChatModel(model_name='qwen-max', provider=provider)
agent = Agent(model)

with pytest.raises(UserError, match='alibaba.*does not support document input'):
await agent.run(['Summarize this document', DocumentUrl(url='https://example.com/test.pdf')])
Loading