61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import UTC, datetime
|
|
|
|
from cloud.llm_providers import LlmProviderProfile, ResolvedLlmProviderProfile
|
|
from cloud.planner_config import build_cloud_planner_client
|
|
from runtime.tool_calling_client import (
|
|
AnthropicToolCallingClient,
|
|
OpenAIToolCallingClient,
|
|
)
|
|
|
|
|
|
def _resolved_profile(
|
|
provider_type: str, *, base_url: str | None = None
|
|
) -> ResolvedLlmProviderProfile:
|
|
now = datetime.now(UTC)
|
|
profile = LlmProviderProfile(
|
|
id="provider-1",
|
|
name="Managed provider",
|
|
name_normalized="managed provider",
|
|
provider_type=provider_type, # type: ignore[arg-type]
|
|
model="test-model",
|
|
base_url=base_url,
|
|
timeout_seconds=15,
|
|
api_key_ciphertext="ciphertext",
|
|
key_last_rotated_at=now,
|
|
enabled=True,
|
|
revision=1,
|
|
created_at=now,
|
|
updated_at=now,
|
|
)
|
|
return ResolvedLlmProviderProfile(profile=profile, api_key="managed-api-key")
|
|
|
|
|
|
def test_build_cloud_planner_client_uses_managed_anthropic_key() -> None:
|
|
client = build_cloud_planner_client(_resolved_profile("anthropic"))
|
|
|
|
assert isinstance(client, AnthropicToolCallingClient)
|
|
assert client.model == "test-model"
|
|
assert client._api_key == "managed-api-key"
|
|
|
|
|
|
def test_build_cloud_planner_client_uses_anthropic_base_url() -> None:
|
|
client = build_cloud_planner_client(
|
|
_resolved_profile("anthropic", base_url="https://anthropic-proxy.example")
|
|
)
|
|
|
|
assert isinstance(client, AnthropicToolCallingClient)
|
|
assert client._base_url == "https://anthropic-proxy.example"
|
|
|
|
|
|
def test_build_cloud_planner_client_uses_openai_compatible_base_url() -> None:
|
|
client = build_cloud_planner_client(
|
|
_resolved_profile("openai-compatible", base_url="https://compat.example/v1")
|
|
)
|
|
|
|
assert isinstance(client, OpenAIToolCallingClient)
|
|
assert client.model == "test-model"
|
|
assert client._api_key == "managed-api-key"
|
|
assert client._base_url == "https://compat.example/v1"
|