Files
wehub-resource-sync 9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:27:52 +08:00

64 lines
2.4 KiB
Python

from __future__ import annotations as _annotations
import httpx
import pytest
from pydantic_ai.exceptions import UserError
from ..conftest import TestEnv, try_import
with try_import() as imports_successful:
from cohere import AsyncClientV2
from cohere.core.http_client import AsyncHttpClient
from pydantic_ai.providers.cohere import CohereProvider
pytestmark = pytest.mark.skipif(not imports_successful(), reason='cohere not installed')
def test_cohere_provider() -> None:
provider = CohereProvider(api_key='api-key')
assert provider.name == 'cohere'
assert provider.base_url == 'https://api.cohere.com'
assert isinstance(provider.client, AsyncClientV2)
assert provider.client._client_wrapper._token == 'api-key' # type: ignore[reportPrivateUsage]
def test_cohere_provider_need_api_key(env: TestEnv) -> None:
env.remove('CO_API_KEY')
with pytest.raises(UserError, match='CO_API_KEY'):
CohereProvider()
def test_cohere_provider_pass_http_client() -> None:
http_client = httpx.AsyncClient()
provider = CohereProvider(http_client=http_client, api_key='api-key')
# The AsyncClientV2 wraps our httpx client in an AsyncHttpClient
# So we just check that the httpx_client is an instance of AsyncHttpClient
assert isinstance(provider.client._client_wrapper.httpx_client, AsyncHttpClient) # type: ignore[reportPrivateUsage]
def test_cohere_provider_pass_cohere_client() -> None:
cohere_client = AsyncClientV2(api_key='test-api-key')
provider = CohereProvider(cohere_client=cohere_client)
assert provider.client == cohere_client
def test_cohere_provider_with_env_base_url(monkeypatch: pytest.MonkeyPatch) -> None:
custom_base_url = 'https://custom.cohere.com/'
# Test with environment variable for base_url
monkeypatch.setenv('CO_BASE_URL', custom_base_url)
provider = CohereProvider(api_key='api-key')
assert provider.base_url == custom_base_url
def test_cohere_provider_model_profile_sets_inline_flag():
profile = CohereProvider.model_profile('command-r')
assert profile.get('supports_inline_system_prompts', False) is True
assert profile.get('supports_thinking', False) is False
reasoning_profile = CohereProvider.model_profile('command-reasoning')
assert reasoning_profile.get('supports_inline_system_prompts', False) is True
assert reasoning_profile.get('supports_thinking', False) is True