8000 Sonnet 3.7 fix by A-F-V · Pull Request #1 · A-F-V/instructor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sonnet 3.7 fix #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion instructor/function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def parse_anthropic_json(
assert isinstance(completion, Message)
if completion.stop_reason == "max_tokens":
raise IncompleteOutputException(last_completion=completion)
text = completion.content[0].text
# Find the first text block
text_blocks = [c for c in completion.content if c.type == "text"]
text = text_blocks[0].text

extra_text = extract_json_from_codeblock(text)

Expand Down
51 changes: 13 additions & 38 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[project]
authors = [
{name = "Jason Liu", email = "jason@jxnl.co"},
]
license = {text = "MIT"}
authors = [{ name = "Jason Liu", email = "jason@jxnl.co" }]
license = { text = "MIT" }
requires-python = "<4.0,>=3.9"
dependencies = [
"openai<2.0.0,>=1.52.0",
Expand Down Expand Up @@ -59,33 +57,17 @@ test-docs = [
"litellm<2.0.0,>=1.35.31",
"mistralai<2.0.0,>=1.0.3",
]
anthropic = [
"anthropic==0.42.0",
"xmltodict<0.15,>=0.13",
]
groq = [
"groq<0.14.0,>=0.4.2",
]
cohere = [
"cohere<6.0.0,>=5.1.8",
]
anthropic = ["anthropic==0.47.2", "xmltodict<0.15,>=0.13"]
groq = ["groq<0.14.0,>=0.4.2"]
cohere = ["cohere<6.0.0,>=5.1.8"]
google-generativeai = [
"google-generativeai<1.0.0,>=0.8.2",
"jsonref<2.0.0,>=1.1.0",
]
vertexai = [
"google-cloud-aiplatform<2.0.0,>=1.53.0",
"jsonref<2.0.0,>=1.1.0",
]
cerebras_cloud_sdk = [
"cerebras-cloud-sdk<2.0.0,>=1.5.0",
]
fireworks-ai = [
"fireworks-ai<1.0.0,>=0.15.4",
]
writer = [
"writer-sdk<2.0.0,>=1.2.0",
]
vertexai = ["google-cloud-aiplatform<2.0.0,>=1.53.0", "jsonref<2.0.0,>=1.1.0"]
cerebras_cloud_sdk = ["cerebras-cloud-sdk<2.0.0,>=1.5.0"]
fireworks-ai = ["fireworks-ai<1.0.0,>=0.15.4"]
writer = ["writer-sdk<2.0.0,>=1.2.0"]

[project.scripts]
instructor = "instructor.cli.cli:app"
Expand All @@ -112,9 +94,7 @@ docs = [
"mkdocs-redirects<2.0.0,>=1.2.1",
"material>=0.1",
8000 ]
anthropic = [
"anthropic==0.42.0",
]
anthropic = ["anthropic==0.47.2"]
test-docs = [
"fastapi<0.116.0,>=0.109.2",
"redis<6.0.0,>=5.0.1",
Expand All @@ -123,7 +103,7 @@ test-docs = [
"tabulate<1.0.0,>=0.9.0",
"pydantic-extra-types<3.0.0,>=2.6.0",
"litellm<2.0.0,>=1.35.31",
"anthropic==0.42.0",
"anthropic==0.47.2",
"xmltodict<0.15,>=0.13",
"groq<0.14.0,>=0.4.2",
"phonenumbers<9.0.0,>=8.13.33",
Expand All @@ -138,14 +118,9 @@ test-docs = [
"datasets<4.0.0,>=3.0.1",
"writer-sdk<2.0.0,>=1.2.0",
]
litellm = [
"litellm<2.0.0,>=1.35.31",
]
litellm = ["litellm<2.0.0,>=1.35.31"]
google-generativeai = [
"google-generativeai<1.0.0,>=0.8.2",
"jsonref<2.0.0,>=1.1.0",
]
vertexai = [
"google-cloud-aiplatform<2.0.0,>=1.53.0",
"jsonref<2.0.0,>=1.1.0",
]
vertexai = ["google-cloud-aiplatform<2.0.0,>=1.53.0", "jsonref<2.0.0,>=1.1.0"]
35 changes: 35 additions & 0 deletions tests/llm/test_anthropic/test_reasoning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import anthropic
import pytest
import instructor
from pydantic import BaseModel
from itertools import product
from .util import models, modes
from anthropic.types.message import Message


class Answer(BaseModel):
answer: float


def test_reasoning():
anthropic_client = anthropic.Anthropic()
client = instructor.from_anthropic(
anthropic_client, mode=instructor.Mode.ANTHROPIC_JSON
)
response = client.chat.completions.create(
model="claude-3-7-sonnet-latest",
response_model=Answer,
messages=[
{
"role": "user",
"content": "Which is larger, 9.11 or 9.8",
},
],
temperature=1,
max_tokens=2000,
thinking={"type": "enabled", "budget_tokens": 1024},
)

# Assertions to validate the response
assert isinstance(response, Answer)
assert response.answer == 9.8
25 changes: 14 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0