97e91a83f3
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import pytest
|
|
import instructor
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class Answer(BaseModel):
|
|
answer: float
|
|
|
|
|
|
def test_reasoning():
|
|
client = instructor.from_provider(
|
|
"anthropic/claude-sonnet-4-5-20250514",
|
|
mode=instructor.Mode.ANTHROPIC_REASONING_TOOLS,
|
|
)
|
|
try:
|
|
response = client.chat.completions.create(
|
|
response_model=Answer,
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "Which is larger, 9.11 or 9.8? Think carefully about decimal places.",
|
|
},
|
|
],
|
|
temperature=1, # Required when thinking is enabled
|
|
max_tokens=2000,
|
|
thinking={"type": "enabled", "budget_tokens": 1024},
|
|
max_retries=3, # Retry if the model gets it wrong
|
|
)
|
|
except Exception as e:
|
|
if "404" in str(e) or "not_found_error" in str(e):
|
|
pytest.skip(
|
|
"Model claude-sonnet-4-5-20250514 not available with current API key"
|
|
)
|
|
raise
|
|
|
|
# Assertions to validate the response
|
|
assert isinstance(response, Answer)
|
|
assert response.answer == 9.8
|