fix(notion-search): pin SDK model to dated ID + drop unused type alias

Code review caught that the bare alias 'claude-haiku-4-5' works in the
Claude Code CLI but may not resolve in the Anthropic SDK. Pin the
default to 'claude-haiku-4-5-20251001' (the full dated ID) via a
DEFAULT_MODEL constant so the SDK path doesn't silently break the
first time it hits the real API.

Also document the max_tokens-ignored behavior on the CLI path in the
public call_claude docstring (not just the private _call_via_cli),
and drop the unused LLMCaller type alias (dead code).

3/3 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-28 07:41:25 +09:00
parent 45c68dee61
commit 89b20aef16

View File

@@ -5,9 +5,10 @@ from __future__ import annotations
import os import os
import shutil import shutil
import subprocess import subprocess
from typing import Callable
LLMCaller = Callable[..., str] # (prompt, *, model, max_tokens) -> response text # Anthropic SDK requires fully-qualified dated model IDs (the bare alias
# `claude-haiku-4-5` works in Claude Code CLI but may not resolve via SDK).
DEFAULT_MODEL = "claude-haiku-4-5-20251001"
def _have_anthropic_sdk() -> bool: def _have_anthropic_sdk() -> bool:
@@ -48,13 +49,16 @@ def _call_via_cli(prompt: str, model: str, max_tokens: int) -> str:
def call_claude( def call_claude(
prompt: str, prompt: str,
*, *,
model: str = "claude-haiku-4-5", model: str = DEFAULT_MODEL,
max_tokens: int = 1000, max_tokens: int = 1000,
) -> str: ) -> str:
"""Send a prompt to Claude. """Send a prompt to Claude.
Tries the anthropic SDK first (requires ANTHROPIC_API_KEY), falls back to Tries the anthropic SDK first (requires ANTHROPIC_API_KEY), falls back to
the `claude -p` CLI if available. Raises RuntimeError if neither works. the `claude -p` CLI if available. Raises RuntimeError if neither works.
Note: ``max_tokens`` is honored by the SDK path but ignored by the CLI
path (the CLI sets its own defaults).
""" """
if _have_anthropic_sdk() and os.getenv("ANTHROPIC_API_KEY"): if _have_anthropic_sdk() and os.getenv("ANTHROPIC_API_KEY"):
return _call_via_sdk(prompt, model, max_tokens) return _call_via_sdk(prompt, model, max_tokens)