Map thinking onto Pydantic AI's unified setting
This commit is contained in:
parent
9168bc15ef
commit
ae345cc39f
7 changed files with 197 additions and 166 deletions
|
|
@ -1,6 +1,12 @@
|
|||
# Changelog
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Bump `pydantic-ai` to 2.18.0.
|
||||
- `enable_thinking` maps onto Pydantic AI's unified `thinking` setting for the `anthropic`, `gemini`, `groq` and `bedrock` providers. The Anthropic thinking budget is now Pydantic AI's default of 10000 tokens, was 4096; `enable_thinking: false` disables Gemini thinking rather than only hiding thoughts; Groq maps reasoning effort rather than `groq_reasoning_format`. The `openai` and `ollama` providers still map to `openai_reasoning_effort`.
|
||||
- `provider: bedrock` with a proprietary OpenAI model such as `openai.o3-mini-v1:0` raises `UserError`: Bedrock Converse serves only the `gpt-oss` family. Use `provider: bedrock-mantle`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- `Store.set_haiku_version` stamps the store's own config into a recreated settings row instead of the process-global `Config`.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ requires-python = ">=3.12"
|
|||
dependencies = [
|
||||
"starlette>=0.50.0",
|
||||
"uvicorn[standard]>=0.40.0",
|
||||
"pydantic-ai-slim[ag-ui,anthropic,openai]>=2.11.0,<3.0.0",
|
||||
"pydantic-ai-slim[ag-ui,anthropic,openai]>=2.18.0,<3.0.0",
|
||||
"python-dotenv>=1.2.1",
|
||||
"haiku.rag-slim>=0.70.0",
|
||||
"logfire[pydantic-ai]>=3.17.0",
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ See the [Pydantic AI thinking documentation](https://ai.pydantic.dev/thinking/)
|
|||
- **Anthropic**: All Claude models
|
||||
- **Google**: Gemini models with thinking support
|
||||
- **Groq**: Models with reasoning capabilities
|
||||
- **Bedrock**: Claude, OpenAI, and Qwen models
|
||||
- **Bedrock**: Claude, Qwen, and `gpt-oss` models. Bedrock Converse does not serve the proprietary OpenAI models, so configuring one raises an error. Reach those through `provider: bedrock-mantle`.
|
||||
- **Ollama**: Models supporting reasoning (gpt-oss, etc.)
|
||||
- **vLLM**: Models with a pydantic-ai reasoning profile (gpt-oss). Qwen3, Gemma, and similar templates ignore the OpenAI `reasoning_effort` that `enable_thinking` translates to — use [`extra_body`](#raw-provider-pass-through) to drive them.
|
||||
- **LM Studio**: Models supporting reasoning (gpt-oss, etc.)
|
||||
|
|
@ -63,6 +63,9 @@ See the [Pydantic AI thinking documentation](https://ai.pydantic.dev/thinking/)
|
|||
- Enable for QA, complex reasoning, and mathematical problems
|
||||
- Disable for speed-critical applications, title generation, and simple tasks
|
||||
|
||||
!!! note "Anthropic thinking and max_tokens"
|
||||
Anthropic requires `max_tokens` to exceed the thinking budget, and `enable_thinking: true` requests Pydantic AI's default budget of 10000 tokens. Set `max_tokens` above 10000 on Claude models that use budget-based thinking, or leave it unset on Sonnet 4.6+ and Opus 4.6+, which use adaptive thinking instead of a budget.
|
||||
|
||||
!!! note "vLLM-served models without a reasoning profile"
|
||||
On `provider: openai` with a custom `base_url`, `enable_thinking` only takes effect for models whose pydantic-ai profile advertises reasoning support (o-series, gpt-5, gpt-oss). For other vLLM-served models (Qwen3, Gemma family, …) the field is a silent no-op. Reach the chat template's thinking switch directly via [`extra_body`](#raw-provider-pass-through).
|
||||
|
||||
|
|
|
|||
|
|
@ -55,30 +55,35 @@ def image_binary_content(data: bytes) -> "BinaryContent":
|
|||
|
||||
def apply_common_settings(
|
||||
settings: Any | None,
|
||||
settings_class: type[Any],
|
||||
model_config: Any,
|
||||
*,
|
||||
map_thinking: bool = True,
|
||||
) -> Any | None:
|
||||
"""Apply common settings (temperature, max_tokens) to model settings.
|
||||
"""Apply the settings every provider shares onto a model settings dict.
|
||||
|
||||
Args:
|
||||
settings: Existing settings instance or None
|
||||
settings_class: Settings class to instantiate if needed
|
||||
model_config: ModelConfig with temperature and max_tokens
|
||||
map_thinking: Whether to map `enable_thinking` onto the unified
|
||||
`thinking` setting. The OpenAI-compatible branches opt out and set
|
||||
`openai_reasoning_effort` themselves, so that models whose profile
|
||||
advertises thinking without OpenAI reasoning support (Ollama's
|
||||
deepseek-r1, for one) keep receiving no `reasoning_effort`.
|
||||
|
||||
Returns:
|
||||
Updated settings instance or None if no settings to apply
|
||||
"""
|
||||
thinking = model_config.enable_thinking if map_thinking else None
|
||||
|
||||
if (
|
||||
model_config.temperature is None
|
||||
and model_config.max_tokens is None
|
||||
and model_config.extra_body is None
|
||||
and thinking is None
|
||||
):
|
||||
return settings
|
||||
|
||||
if settings is None:
|
||||
settings_dict = settings_class()
|
||||
else:
|
||||
settings_dict = settings
|
||||
settings_dict = {} if settings is None else settings
|
||||
|
||||
if model_config.temperature is not None:
|
||||
settings_dict["temperature"] = model_config.temperature
|
||||
|
|
@ -89,6 +94,9 @@ def apply_common_settings(
|
|||
if model_config.extra_body is not None:
|
||||
settings_dict["extra_body"] = model_config.extra_body
|
||||
|
||||
if thinking is not None:
|
||||
settings_dict["thinking"] = thinking
|
||||
|
||||
return settings_dict
|
||||
|
||||
|
||||
|
|
@ -139,7 +147,7 @@ def get_model(
|
|||
model_settings = OpenAIChatModelSettings(openai_reasoning_effort="high")
|
||||
|
||||
model_settings = apply_common_settings(
|
||||
model_settings, OpenAIChatModelSettings, model_config
|
||||
model_settings, model_config, map_thinking=False
|
||||
)
|
||||
|
||||
# Ollama's OpenAI-compatible API lives under /v1. Append it if the
|
||||
|
|
@ -173,7 +181,7 @@ def get_model(
|
|||
)
|
||||
|
||||
openai_settings = apply_common_settings(
|
||||
openai_settings, OpenAIChatModelSettings, model_config
|
||||
openai_settings, model_config, map_thinking=False
|
||||
)
|
||||
|
||||
# Use model-level base_url if set (for vLLM, LM Studio, etc.)
|
||||
|
|
@ -188,75 +196,42 @@ def get_model(
|
|||
return OpenAIChatModel(model_name=model, settings=openai_settings)
|
||||
|
||||
elif provider == "anthropic":
|
||||
from anthropic.types.beta import (
|
||||
BetaThinkingConfigDisabledParam,
|
||||
BetaThinkingConfigEnabledParam,
|
||||
)
|
||||
from anthropic.types.beta import BetaThinkingConfigDisabledParam
|
||||
from pydantic_ai.models.anthropic import AnthropicModel, AnthropicModelSettings
|
||||
|
||||
anthropic_settings: Any = None
|
||||
|
||||
# Apply thinking control
|
||||
if model_config.enable_thinking is not None:
|
||||
if model_config.enable_thinking:
|
||||
thinking_config: BetaThinkingConfigEnabledParam = {
|
||||
"type": "enabled",
|
||||
"budget_tokens": 4096,
|
||||
}
|
||||
anthropic_settings = AnthropicModelSettings(
|
||||
anthropic_thinking=thinking_config
|
||||
)
|
||||
else:
|
||||
thinking_disabled: BetaThinkingConfigDisabledParam = {
|
||||
"type": "disabled"
|
||||
}
|
||||
anthropic_settings = AnthropicModelSettings(
|
||||
anthropic_thinking=thinking_disabled
|
||||
)
|
||||
# Unified `thinking=False` omits the request field, which leaves the
|
||||
# adaptive-thinking models (Sonnet 4.6+, Opus 4.6+) thinking by default.
|
||||
disable_thinking = model_config.enable_thinking is False
|
||||
if disable_thinking:
|
||||
thinking_disabled: BetaThinkingConfigDisabledParam = {"type": "disabled"}
|
||||
anthropic_settings = AnthropicModelSettings(
|
||||
anthropic_thinking=thinking_disabled
|
||||
)
|
||||
|
||||
anthropic_settings = apply_common_settings(
|
||||
anthropic_settings, AnthropicModelSettings, model_config
|
||||
anthropic_settings, model_config, map_thinking=not disable_thinking
|
||||
)
|
||||
|
||||
return AnthropicModel(model_name=model, settings=anthropic_settings)
|
||||
|
||||
elif provider == "gemini":
|
||||
from pydantic_ai.models.google import GoogleModel, GoogleModelSettings
|
||||
from pydantic_ai.models.google import GoogleModel
|
||||
|
||||
gemini_settings: Any = None
|
||||
|
||||
# Apply thinking control
|
||||
if model_config.enable_thinking is not None:
|
||||
gemini_settings = GoogleModelSettings(
|
||||
google_thinking_config={
|
||||
"include_thoughts": model_config.enable_thinking
|
||||
}
|
||||
)
|
||||
|
||||
gemini_settings = apply_common_settings(
|
||||
gemini_settings, GoogleModelSettings, model_config
|
||||
return GoogleModel(
|
||||
model_name=model,
|
||||
settings=apply_common_settings(None, model_config),
|
||||
)
|
||||
|
||||
return GoogleModel(model_name=model, settings=gemini_settings)
|
||||
|
||||
elif provider == "groq":
|
||||
from pydantic_ai.models.groq import GroqModel, GroqModelSettings
|
||||
from pydantic_ai.models.groq import GroqModel
|
||||
|
||||
groq_settings: Any = None
|
||||
|
||||
# Apply thinking control
|
||||
if model_config.enable_thinking is not None:
|
||||
if model_config.enable_thinking:
|
||||
groq_settings = GroqModelSettings(groq_reasoning_format="parsed")
|
||||
else:
|
||||
groq_settings = GroqModelSettings(groq_reasoning_format="hidden")
|
||||
|
||||
groq_settings = apply_common_settings(
|
||||
groq_settings, GroqModelSettings, model_config
|
||||
return GroqModel(
|
||||
model_name=model,
|
||||
settings=apply_common_settings(None, model_config),
|
||||
)
|
||||
|
||||
return GroqModel(model_name=model, settings=groq_settings)
|
||||
|
||||
elif provider == "bedrock":
|
||||
from pydantic_ai.models.bedrock import (
|
||||
BedrockConverseModel,
|
||||
|
|
@ -265,41 +240,25 @@ def get_model(
|
|||
|
||||
bedrock_settings: Any = None
|
||||
|
||||
# Apply thinking control for Claude models
|
||||
if model_config.enable_thinking is not None:
|
||||
additional_fields: dict[str, Any] = {}
|
||||
if model.startswith("anthropic.claude"):
|
||||
if model_config.enable_thinking:
|
||||
additional_fields = {
|
||||
"thinking": {"type": "enabled", "budget_tokens": 4096}
|
||||
}
|
||||
else:
|
||||
additional_fields = {"thinking": {"type": "disabled"}}
|
||||
elif "o1" in model or "o3" in model:
|
||||
# OpenAI reasoning models on Bedrock (o-series only, not gpt-4o)
|
||||
additional_fields = {
|
||||
"reasoning_effort": "high"
|
||||
if model_config.enable_thinking
|
||||
else "low"
|
||||
}
|
||||
elif "qwen" in model:
|
||||
# Qwen models on Bedrock
|
||||
additional_fields = {
|
||||
"reasoning_config": "high"
|
||||
if model_config.enable_thinking
|
||||
else "low"
|
||||
}
|
||||
|
||||
if additional_fields:
|
||||
bedrock_settings = BedrockModelSettings(
|
||||
bedrock_additional_model_requests_fields=additional_fields
|
||||
)
|
||||
|
||||
bedrock_settings = apply_common_settings(
|
||||
bedrock_settings, BedrockModelSettings, model_config
|
||||
# Same omission as the direct Anthropic branch: unified `thinking=False`
|
||||
# leaves the adaptive-thinking Claude models thinking. Bedrock ids are
|
||||
# `[<geo>.]<family>.<model>`, as in `us.anthropic.claude-...`.
|
||||
disable_claude_thinking = (
|
||||
model_config.enable_thinking is False and "anthropic." in model
|
||||
)
|
||||
if disable_claude_thinking:
|
||||
bedrock_settings = BedrockModelSettings(
|
||||
bedrock_additional_model_requests_fields={
|
||||
"thinking": {"type": "disabled"}
|
||||
}
|
||||
)
|
||||
|
||||
return BedrockConverseModel(model_name=model, settings=bedrock_settings)
|
||||
return BedrockConverseModel(
|
||||
model_name=model,
|
||||
settings=apply_common_settings(
|
||||
bedrock_settings, model_config, map_thinking=not disable_claude_thinking
|
||||
),
|
||||
)
|
||||
|
||||
else:
|
||||
# For any other provider, use string format and let Pydantic AI handle it
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ dependencies = [
|
|||
"lancedb==0.34.0",
|
||||
"pathspec>=1.0.4",
|
||||
"pydantic>=2.12.5",
|
||||
"pydantic-ai-slim[openai,logfire,ag-ui]>=2.11.0,<3.0.0",
|
||||
"pydantic-ai-slim[openai,logfire,ag-ui]>=2.18.0,<3.0.0",
|
||||
"pydantic-monty>=0.0.17",
|
||||
"pypdfium2>=5.0",
|
||||
"python-dotenv>=1.2.2",
|
||||
|
|
|
|||
|
|
@ -237,6 +237,27 @@ def test_get_model_openai_non_reasoning_model_ignores_thinking():
|
|||
assert result._settings is None
|
||||
|
||||
|
||||
def test_get_model_vllm_model_without_reasoning_profile_sends_no_thinking():
|
||||
"""A vLLM-served model with no reasoning profile carries no thinking settings.
|
||||
|
||||
Its chat template reads the switch from `chat_template_kwargs`, which only
|
||||
`extra_body` can reach, and the endpoint rejects `reasoning_effort`.
|
||||
"""
|
||||
model_config = ModelConfig(
|
||||
provider="openai",
|
||||
name="Qwen/Qwen3-32B",
|
||||
base_url="http://vllm:8000/v1",
|
||||
enable_thinking=True,
|
||||
temperature=0.2,
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, OpenAIChatModel)
|
||||
assert result._settings is not None
|
||||
assert "thinking" not in result._settings
|
||||
assert "openai_reasoning_effort" not in result._settings
|
||||
|
||||
|
||||
def test_get_model_openai_extra_body_forwarded():
|
||||
"""`extra_body` on ModelConfig is forwarded to ModelSettings.extra_body.
|
||||
|
||||
|
|
@ -328,27 +349,41 @@ def test_get_model_anthropic():
|
|||
|
||||
|
||||
@pytest.mark.skipif(not HAS_ANTHROPIC, reason="Anthropic not installed")
|
||||
@pytest.mark.parametrize(
|
||||
"enable_thinking,expected_thinking",
|
||||
[
|
||||
(True, {"type": "enabled", "budget_tokens": 4096}),
|
||||
(False, {"type": "disabled"}),
|
||||
],
|
||||
)
|
||||
def test_get_model_anthropic_with_thinking(enable_thinking, expected_thinking):
|
||||
def test_get_model_anthropic_with_thinking():
|
||||
"""Test get_model configures thinking for Anthropic."""
|
||||
from pydantic_ai.models.anthropic import AnthropicModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
provider="anthropic",
|
||||
name="claude-3-5-sonnet-20241022",
|
||||
enable_thinking=enable_thinking,
|
||||
enable_thinking=True,
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, AnthropicModel)
|
||||
assert result.settings is not None
|
||||
assert result.settings.get("anthropic_thinking") == expected_thinking
|
||||
assert result.settings.get("thinking") is True
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_ANTHROPIC, reason="Anthropic not installed")
|
||||
def test_get_model_anthropic_thinking_off_disables_adaptive_models():
|
||||
"""Adaptive-thinking models think by default, so off must be explicit.
|
||||
|
||||
The unified `thinking=False` omits the request field, which leaves Sonnet
|
||||
4.6+ and Opus 4.6+ thinking.
|
||||
"""
|
||||
from pydantic_ai.models.anthropic import AnthropicModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
provider="anthropic", name="claude-sonnet-4-6", enable_thinking=False
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, AnthropicModel)
|
||||
assert result.settings is not None
|
||||
assert result.settings.get("anthropic_thinking") == {"type": "disabled"}
|
||||
# The explicit disable replaces the unified key rather than joining it.
|
||||
assert "thinking" not in result.settings
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GOOGLE, reason="Google not installed")
|
||||
|
|
@ -362,15 +397,21 @@ def test_get_model_gemini():
|
|||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GOOGLE, reason="Google not installed")
|
||||
def test_get_model_gemini_with_thinking():
|
||||
@pytest.mark.parametrize("enable_thinking", [True, False])
|
||||
def test_get_model_gemini_with_thinking(enable_thinking):
|
||||
"""Test get_model configures thinking for Gemini."""
|
||||
from pydantic_ai.models.google import GoogleModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
provider="gemini", name="gemini-2.0-flash-thinking-exp", enable_thinking=True
|
||||
provider="gemini",
|
||||
name="gemini-2.0-flash-thinking-exp",
|
||||
enable_thinking=enable_thinking,
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, GoogleModel)
|
||||
assert result.settings is not None
|
||||
assert result.settings.get("thinking") == enable_thinking
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GROQ, reason="Groq not installed")
|
||||
|
|
@ -384,11 +425,9 @@ def test_get_model_groq():
|
|||
|
||||
|
||||
@pytest.mark.skipif(not HAS_GROQ, reason="Groq not installed")
|
||||
@pytest.mark.parametrize(
|
||||
"enable_thinking,expected_format", [(True, "parsed"), (False, "hidden")]
|
||||
)
|
||||
def test_get_model_groq_with_thinking(enable_thinking, expected_format):
|
||||
"""Test get_model configures thinking format for Groq."""
|
||||
@pytest.mark.parametrize("enable_thinking", [True, False])
|
||||
def test_get_model_groq_with_thinking(enable_thinking):
|
||||
"""Test get_model configures thinking for Groq."""
|
||||
from pydantic_ai.models.groq import GroqModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
|
|
@ -400,7 +439,7 @@ def test_get_model_groq_with_thinking(enable_thinking, expected_format):
|
|||
|
||||
assert isinstance(result, GroqModel)
|
||||
assert result.settings is not None
|
||||
assert result.settings.get("groq_reasoning_format") == expected_format
|
||||
assert result.settings.get("thinking") == enable_thinking
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_BEDROCK, reason="Bedrock not installed")
|
||||
|
|
@ -417,57 +456,81 @@ def test_get_model_bedrock():
|
|||
|
||||
@pytest.mark.skipif(not HAS_BEDROCK, reason="Bedrock not installed")
|
||||
@pytest.mark.parametrize(
|
||||
"name,enable_thinking,expected_fields",
|
||||
"name",
|
||||
[
|
||||
(
|
||||
"anthropic.claude-3-5-sonnet-20241022-v2:0",
|
||||
True,
|
||||
{"thinking": {"type": "enabled", "budget_tokens": 4096}},
|
||||
),
|
||||
(
|
||||
"anthropic.claude-3-5-sonnet-20241022-v2:0",
|
||||
False,
|
||||
{"thinking": {"type": "disabled"}},
|
||||
),
|
||||
("openai.o3-mini-v1:0", True, {"reasoning_effort": "high"}),
|
||||
("openai.o3-mini-v1:0", False, {"reasoning_effort": "low"}),
|
||||
("qwen.qwen3-32b-v1:0", True, {"reasoning_config": "high"}),
|
||||
("qwen.qwen3-32b-v1:0", False, {"reasoning_config": "low"}),
|
||||
# A family with no reasoning mapping leaves the request fields untouched.
|
||||
("meta.llama3-70b-instruct-v1:0", True, None),
|
||||
("meta.llama3-70b-instruct-v1:0", False, None),
|
||||
],
|
||||
ids=[
|
||||
"claude_on",
|
||||
"claude_off",
|
||||
"o_series_on",
|
||||
"o_series_off",
|
||||
"qwen_on",
|
||||
"qwen_off",
|
||||
"unmapped_on",
|
||||
"unmapped_off",
|
||||
"anthropic.claude-3-5-sonnet-20241022-v2:0",
|
||||
"openai.gpt-oss-120b-1:0",
|
||||
"qwen.qwen3-32b-v1:0",
|
||||
"meta.llama3-70b-instruct-v1:0",
|
||||
],
|
||||
ids=["claude", "gpt_oss", "qwen", "unmapped"],
|
||||
)
|
||||
def test_get_model_bedrock_with_thinking(name, enable_thinking, expected_fields):
|
||||
"""Each Bedrock model family maps thinking onto its own request field."""
|
||||
def test_get_model_bedrock_with_thinking(name):
|
||||
"""Every Bedrock family carries the unified thinking setting."""
|
||||
from pydantic_ai.models.bedrock import BedrockConverseModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
provider="bedrock",
|
||||
name=name,
|
||||
enable_thinking=enable_thinking,
|
||||
enable_thinking=True,
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, BedrockConverseModel)
|
||||
if expected_fields is None:
|
||||
assert result.settings is None
|
||||
return
|
||||
assert result.settings is not None
|
||||
assert (
|
||||
result.settings.get("bedrock_additional_model_requests_fields")
|
||||
== expected_fields
|
||||
assert result.settings.get("thinking") is True
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_BEDROCK, reason="Bedrock not installed")
|
||||
@pytest.mark.parametrize(
|
||||
"name",
|
||||
[
|
||||
"anthropic.claude-sonnet-4-6-20260514-v1:0",
|
||||
"us.anthropic.claude-sonnet-4-6-20260514-v1:0",
|
||||
],
|
||||
ids=["plain", "cross_region"],
|
||||
)
|
||||
def test_get_model_bedrock_thinking_off_disables_adaptive_claude(name):
|
||||
"""Bedrock omits the field for adaptive Claude, which leaves it thinking."""
|
||||
from pydantic_ai.models.bedrock import BedrockConverseModel
|
||||
|
||||
model_config = ModelConfig(provider="bedrock", name=name, enable_thinking=False)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, BedrockConverseModel)
|
||||
assert result.settings is not None
|
||||
assert result.settings.get("bedrock_additional_model_requests_fields") == {
|
||||
"thinking": {"type": "disabled"}
|
||||
}
|
||||
# The explicit disable replaces the unified key rather than joining it.
|
||||
assert "thinking" not in result.settings
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_BEDROCK, reason="Bedrock not installed")
|
||||
def test_get_model_bedrock_thinking_off_leaves_non_claude_families_alone():
|
||||
"""Only the Anthropic variant takes a `thinking` request field."""
|
||||
from pydantic_ai.models.bedrock import BedrockConverseModel
|
||||
|
||||
model_config = ModelConfig(
|
||||
provider="bedrock", name="qwen.qwen3-32b-v1:0", enable_thinking=False
|
||||
)
|
||||
result = get_model(model_config)
|
||||
|
||||
assert isinstance(result, BedrockConverseModel)
|
||||
assert result.settings is not None
|
||||
assert "bedrock_additional_model_requests_fields" not in result.settings
|
||||
assert result.settings.get("thinking") is False
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_BEDROCK, reason="Bedrock not installed")
|
||||
def test_get_model_bedrock_rejects_mantle_only_model():
|
||||
"""Proprietary OpenAI models are Bedrock Mantle-only, not served by Converse."""
|
||||
from pydantic_ai.exceptions import UserError
|
||||
|
||||
model_config = ModelConfig(provider="bedrock", name="openai.o3-mini-v1:0")
|
||||
|
||||
with pytest.raises(UserError):
|
||||
get_model(model_config)
|
||||
|
||||
|
||||
def test_get_model_unknown_provider():
|
||||
|
|
@ -491,7 +554,7 @@ def test_get_package_versions():
|
|||
assert "docling_document_schema" in versions
|
||||
|
||||
# All should be non-empty strings
|
||||
for key, value in versions.items():
|
||||
for value in versions.values():
|
||||
assert isinstance(value, str)
|
||||
assert len(value) > 0
|
||||
|
||||
|
|
@ -504,7 +567,7 @@ def test_apply_common_settings_no_settings():
|
|||
from haiku.rag.utils import apply_common_settings
|
||||
|
||||
mc = ModelConfig(provider="openai", name="gpt-4o")
|
||||
result = apply_common_settings(None, dict, mc)
|
||||
result = apply_common_settings(None, mc)
|
||||
assert result is None
|
||||
|
||||
|
||||
|
|
@ -513,7 +576,7 @@ def test_apply_common_settings_temperature():
|
|||
from haiku.rag.utils import apply_common_settings
|
||||
|
||||
mc = ModelConfig(provider="openai", name="gpt-4o", temperature=0.7)
|
||||
result = apply_common_settings(None, dict, mc)
|
||||
result = apply_common_settings(None, mc)
|
||||
assert result is not None
|
||||
assert result["temperature"] == 0.7
|
||||
|
||||
|
|
@ -523,7 +586,7 @@ def test_apply_common_settings_max_tokens():
|
|||
from haiku.rag.utils import apply_common_settings
|
||||
|
||||
mc = ModelConfig(provider="openai", name="gpt-4o", max_tokens=500)
|
||||
result = apply_common_settings(None, dict, mc)
|
||||
result = apply_common_settings(None, mc)
|
||||
assert result is not None
|
||||
assert result["max_tokens"] == 500
|
||||
|
||||
|
|
@ -534,7 +597,7 @@ def test_apply_common_settings_existing():
|
|||
|
||||
mc = ModelConfig(provider="openai", name="gpt-4o", temperature=0.5)
|
||||
existing = {"some_key": "value"}
|
||||
result = apply_common_settings(existing, dict, mc)
|
||||
result = apply_common_settings(existing, mc)
|
||||
assert result is not None
|
||||
assert result["temperature"] == 0.5
|
||||
assert result["some_key"] == "value"
|
||||
|
|
|
|||
20
uv.lock
20
uv.lock
|
|
@ -1768,7 +1768,7 @@ requires-dist = [
|
|||
{ name = "pydantic-ai-slim", extras = ["google"], marker = "extra == 'vertexai'" },
|
||||
{ name = "pydantic-ai-slim", extras = ["groq"], marker = "extra == 'groq'" },
|
||||
{ name = "pydantic-ai-slim", extras = ["mistral"], marker = "extra == 'mistral'" },
|
||||
{ name = "pydantic-ai-slim", extras = ["openai", "logfire", "ag-ui"], specifier = ">=2.11.0,<3.0.0" },
|
||||
{ name = "pydantic-ai-slim", extras = ["openai", "logfire", "ag-ui"], specifier = ">=2.18.0,<3.0.0" },
|
||||
{ name = "pydantic-ai-slim", extras = ["voyageai"], marker = "extra == 'voyageai'" },
|
||||
{ name = "pydantic-monty", specifier = ">=0.0.17" },
|
||||
{ name = "pypdfium2", specifier = ">=5.0" },
|
||||
|
|
@ -3826,7 +3826,7 @@ email = [
|
|||
|
||||
[[package]]
|
||||
name = "pydantic-ai-slim"
|
||||
version = "2.16.0"
|
||||
version = "2.18.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "genai-prices" },
|
||||
|
|
@ -3837,9 +3837,9 @@ dependencies = [
|
|||
{ name = "pydantic-graph" },
|
||||
{ name = "typing-inspection" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/76/6a/3048579c646f4cea7966889009a1d7eef1365f9126393945d39cefad9e83/pydantic_ai_slim-2.16.0.tar.gz", hash = "sha256:36d17cb12edd72ffc62f9e06cc49ac5f23cb77cf6b665c4b1fd11c00dbe6a852", size = 889343, upload-time = "2026-07-23T02:47:20.696Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/4b/39/c3a941027be87f6bc07e50e1e72ae93e66a1b11b838e33ad5d135d2fe2f0/pydantic_ai_slim-2.18.0.tar.gz", hash = "sha256:dfe47a3602049f779223702a684ed8091b111cfae1851236616d6b0eb3b0b077", size = 902113, upload-time = "2026-07-25T01:21:05.614Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/2e/95/2c79b9f8e875562bae8141078af27428120e8415d493bb07ea36ca5905f9/pydantic_ai_slim-2.16.0-py3-none-any.whl", hash = "sha256:7cad27fb8f45ce4af4e8da83d7f206a3e1038dbc7535625c0ce5518fe378a55d", size = 1077057, upload-time = "2026-07-23T02:47:12.633Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/bf/a0/a0619bddf602f69a754540cb82147f9b53dfa2d093e1fe7051c5e6a8eceb/pydantic_ai_slim-2.18.0-py3-none-any.whl", hash = "sha256:4c4076166a63ad96fe6ed5a517223c4a5aba6c9682a17d8d0ac42839cbc83622", size = 1091565, upload-time = "2026-07-25T01:20:57.323Z" },
|
||||
]
|
||||
|
||||
[package.optional-dependencies]
|
||||
|
|
@ -3949,7 +3949,7 @@ wheels = [
|
|||
|
||||
[[package]]
|
||||
name = "pydantic-evals"
|
||||
version = "2.16.0"
|
||||
version = "2.18.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "anyio" },
|
||||
|
|
@ -3959,14 +3959,14 @@ dependencies = [
|
|||
{ name = "pyyaml" },
|
||||
{ name = "rich" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/52/f5/7c2bf8ce45da52ed70c030e91ce43747317f61bd0615a40e91f1ec515c70/pydantic_evals-2.16.0.tar.gz", hash = "sha256:717e9615c7688650cdc716046f1d8edfbe0bac1748286c0a2744e3689fb518c7", size = 85147, upload-time = "2026-07-23T02:47:22.089Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/fd/4a/e2b629f4724a6026c792a5bd7ceb470bf38d48c6a2ebe8cec091ed85485f/pydantic_evals-2.18.0.tar.gz", hash = "sha256:d26ab006290564a5e56394b9033fbd5925e4a172d9e23be5f3c034ae3637eb18", size = 85222, upload-time = "2026-07-25T01:21:07.101Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/f0/f6/d7f20f976f81d073856138bd046bf1ce5dc96561391526753c1c9076d33c/pydantic_evals-2.16.0-py3-none-any.whl", hash = "sha256:6705b427ea7c77d7f6b7d152ced6f86728931eceb9c57a8aa07ab8225fb1a934", size = 100439, upload-time = "2026-07-23T02:47:14.523Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1c/8d/be8abc897f9cd9ef83e000bfaa8d9bec0d93fe2f59f219d2c3835d66b033/pydantic_evals-2.18.0-py3-none-any.whl", hash = "sha256:98d20973df83c3ca6d7341ce2f704ae59b53e02698b55df765f9a1cd5ec5ea1d", size = 100524, upload-time = "2026-07-25T01:20:59.284Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pydantic-graph"
|
||||
version = "2.16.0"
|
||||
version = "2.18.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "httpx" },
|
||||
|
|
@ -3974,9 +3974,9 @@ dependencies = [
|
|||
{ name = "pydantic" },
|
||||
{ name = "typing-inspection" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c3/22/6b6426e14607275f6b15f2a0c4530514c48ff01f86c53bbaac4041d09df9/pydantic_graph-2.16.0.tar.gz", hash = "sha256:f71e5c8e78a4ce56bc044861178e506ebd99881717ae0993924c457f5de6230e", size = 43979, upload-time = "2026-07-23T02:47:23.328Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e5/f9/1554e818e6d38bcb3f66ec7da7abe17c28dcd00caa1550b034e175b8841f/pydantic_graph-2.18.0.tar.gz", hash = "sha256:9423defa047b477a561a06eadfd37aaf101a2b690d044adb79de80d7ea203e4e", size = 44017, upload-time = "2026-07-25T01:21:08.152Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/80/c0/362a7fb50562d7b51e3d02d454826e0a7b5652f27e5be8e835ddfaf84da6/pydantic_graph-2.16.0-py3-none-any.whl", hash = "sha256:99c25852c436d4d510d1ecdcb53ce4a0b11aa4d1d9d81472727587f2b5a3bc13", size = 51661, upload-time = "2026-07-23T02:47:15.921Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2f/29/fd05a4a84db9dae16c0417d8bcd6847148439a55329d000ef101d7243ded/pydantic_graph-2.18.0-py3-none-any.whl", hash = "sha256:48df74e3ae12ca44f99890e9b4f7020ae70a5a38d20df02db7cb16b0db3c3711", size = 51662, upload-time = "2026-07-25T01:21:00.764Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
|||
Loading…
Reference in a new issue