|
1 | 1 | """LLM client for Anthropic models.""" |
2 | 2 |
|
3 | 3 | import json |
| 4 | +import logging |
4 | 5 | import os |
5 | 6 | import random |
6 | 7 | import time |
7 | 8 | from dataclasses import dataclass |
8 | 9 | from typing import Any, Tuple, cast |
9 | | -from dataclasses_json import DataClassJsonMixin |
| 10 | + |
10 | 11 | import anthropic |
11 | 12 | import openai |
12 | 13 | from anthropic import ( |
|
24 | 25 | from anthropic._exceptions import ( |
25 | 26 | OverloadedError as AnthropicOverloadedError, # pyright: ignore[reportPrivateImportUsage] |
26 | 27 | ) |
| 28 | +from anthropic.types import ( |
| 29 | + RedactedThinkingBlock as AnthropicRedactedThinkingBlock, |
| 30 | +) |
27 | 31 | from anthropic.types import ( |
28 | 32 | TextBlock as AnthropicTextBlock, |
| 33 | +) |
| 34 | +from anthropic.types import ( |
29 | 35 | ThinkingBlock as AnthropicThinkingBlock, |
30 | | - RedactedThinkingBlock as AnthropicRedactedThinkingBlock, |
31 | 36 | ) |
32 | 37 | from anthropic.types import ToolParam as AnthropicToolParam |
33 | 38 | from anthropic.types import ( |
|
41 | 46 | ToolChoiceToolChoiceAuto, |
42 | 47 | ToolChoiceToolChoiceTool, |
43 | 48 | ) |
44 | | - |
| 49 | +from dataclasses_json import DataClassJsonMixin |
45 | 50 | from openai import ( |
46 | 51 | APIConnectionError as OpenAI_APIConnectionError, |
47 | 52 | ) |
|
55 | 60 | NOT_GIVEN as OpenAI_NOT_GIVEN, # pyright: ignore[reportPrivateImportUsage] |
56 | 61 | ) |
57 | 62 |
|
58 | | -import logging |
59 | | - |
60 | 63 | logging.getLogger("httpx").setLevel(logging.WARNING) |
61 | 64 |
|
62 | 65 |
|
@@ -170,7 +173,7 @@ class AnthropicDirectClient(LLMClient): |
170 | 173 |
|
171 | 174 | def __init__( |
172 | 175 | self, |
173 | | - model_name="claude-3-7-sonnet-20250219", |
| 176 | + model_name="claude-sonnet-4-20250514", |
174 | 177 | max_retries=2, |
175 | 178 | use_caching=True, |
176 | 179 | use_low_qos_server: bool = False, |
@@ -315,9 +318,9 @@ def generate( |
315 | 318 | "thinking": {"type": "enabled", "budget_tokens": thinking_tokens} |
316 | 319 | } |
317 | 320 | temperature = 1 |
318 | | - assert max_tokens >= 32_000 and thinking_tokens <= 8192, ( |
319 | | - f"As a heuristic, max tokens {max_tokens} must be >= 32k and thinking tokens {thinking_tokens} must be < 8k" |
320 | | - ) |
| 321 | + assert ( |
| 322 | + max_tokens >= 32_000 and thinking_tokens <= 8192 |
| 323 | + ), f"As a heuristic, max tokens {max_tokens} must be >= 32k and thinking tokens {thinking_tokens} must be < 8k" |
321 | 324 | else: |
322 | 325 | extra_body = None |
323 | 326 |
|
|
0 commit comments