-
-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for Sonnet 3.7 Reasoning for ANTRHOPIC_JSON (#1361)
- Loading branch information
Showing
9 changed files
with
122 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
[project] | ||
authors = [ | ||
{name = "Jason Liu", email = "[email protected]"}, | ||
] | ||
license = {text = "MIT"} | ||
authors = [{ name = "Jason Liu", email = "[email protected]" }] | ||
license = { text = "MIT" } | ||
requires-python = "<4.0,>=3.9" | ||
dependencies = [ | ||
"openai<2.0.0,>=1.52.0", | ||
|
@@ -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" | ||
|
@@ -112,9 +94,7 @@ docs = [ | |
"mkdocs-redirects<2.0.0,>=1.2.1", | ||
"material>=0.1", | ||
] | ||
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", | ||
|
@@ -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", | ||
|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import anthropic | ||
import pytest | ||
import instructor | ||
from pydantic import BaseModel | ||
from itertools import product | ||
from anthropic.types.message import Message | ||
|
||
|
||
class Answer(BaseModel): | ||
answer: float | ||
|
||
|
||
modes = [ | ||
instructor.Mode.ANTHROPIC_REASONING_TOOLS, | ||
instructor.Mode.ANTHROPIC_JSON, | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("mode", modes) | ||
def test_reasoning(mode): | ||
anthropic_client = anthropic.Anthropic() | ||
client = instructor.from_anthropic(anthropic_client, mode=mode) | ||
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 |
Oops, something went wrong.