Skip to content

Commit edbdb0c

Browse files
authored
Feat: Support for Claude 3.7 sonnet LLM (#175)
* Update anthropic llama-index version to 0.6.10 for claude 3.7 support * Updated anthropic.py to handle thinking capabilities for claude 3.7 * Modified json schema * Fixed issue with temperature for model * Changed budget tokens field to thinking budget tokens Signed-off-by: Praveen Kumar <[email protected]> * Updated version to 0.62.0 __init__.py Signed-off-by: Praveen Kumar <[email protected]> --------- Signed-off-by: Praveen Kumar <[email protected]>
1 parent fc0fe4f commit edbdb0c

File tree

6 files changed

+1460
-542
lines changed

6 files changed

+1460
-542
lines changed

pdm.lock

Lines changed: 1395 additions & 535 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies = [
3939
"llama-index-llms-mistralai==0.3.1",
4040
"mistralai==1.2.5",
4141
"llama-index-llms-anyscale==0.3.0",
42-
"llama-index-llms-anthropic==0.6.3",
42+
"llama-index-llms-anthropic==0.6.10",
4343
"llama-index-llms-azure-openai==0.3.1",
4444
"llama-index-llms-vertex==0.4.2",
4545
"llama-index-llms-replicate==0.4.0",
@@ -127,4 +127,4 @@ path = "src/unstract/sdk/__init__.py"
127127
[tool.pdm.resolution.overrides]
128128
grpcio = "1.62.3"
129129
grpcio-tools = "1.62.3"
130-
grpcio-health-checking = "1.62.3"
130+
grpcio-health-checking = "1.62.3"

src/unstract/sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.61.0"
1+
__version__ = "0.62.0"
22

33

44
def get_sdk_version():

src/unstract/sdk/adapters/llm/anthropic/src/anthropic.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Constants:
2020
TIMEOUT = "timeout"
2121
MAX_RETRIES = "max_retries"
2222
MAX_TOKENS = "max_tokens"
23-
23+
ENABLE_THINKING = "enable_thinking"
24+
BUDGET_TOKENS = "budget_tokens"
2425

2526
class AnthropicLLM(LLMAdapter):
2627
def __init__(self, settings: dict[str, Any]):
@@ -53,6 +54,16 @@ def get_llm_instance(self) -> LLM:
5354
max_tokens = int(
5455
self.config.get(Constants.MAX_TOKENS, DEFAULT_ANTHROPIC_MAX_TOKENS)
5556
)
57+
58+
thinking = self.config.get(Constants.ENABLE_THINKING)
59+
thinking_dict = None
60+
temperature = 0
61+
62+
if thinking:
63+
budget_tokens = self.config.get(Constants.BUDGET_TOKENS)
64+
thinking_dict = {"type": "enabled", "budget_tokens": budget_tokens}
65+
temperature = 1
66+
5667
try:
5768
llm: LLM = Anthropic(
5869
model=str(self.config.get(Constants.MODEL)),
@@ -63,8 +74,9 @@ def get_llm_instance(self) -> LLM:
6374
max_retries=int(
6475
self.config.get(Constants.MAX_RETRIES, LLMKeys.DEFAULT_MAX_RETRIES)
6576
),
66-
temperature=0,
77+
temperature=temperature,
6778
max_tokens=max_tokens,
79+
thinking_dict=thinking_dict
6880
)
6981
return llm
7082
except Exception as e:

src/unstract/sdk/adapters/llm/anthropic/src/static/json_schema.json

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,49 @@
5050
"title": "Timeout",
5151
"default": 900,
5252
"description": "Timeout in seconds"
53+
},
54+
"enable_thinking": {
55+
"type": "boolean",
56+
"title": "Enable Extended Thinking",
57+
"default": false,
58+
"description": "Enhance reasoning for complex tasks with step-by-step transparency. Available only for Claude 3.7 Sonnet."
59+
}
60+
},
61+
"allOf": [
62+
{
63+
"if": {
64+
"properties": {
65+
"enable_thinking": {
66+
"const": true
67+
}
68+
}
69+
},
70+
"then": {
71+
"properties": {
72+
"budget_tokens": {
73+
"type": "number",
74+
"minimum": 1024,
75+
"default": 1024,
76+
"title": "Thinking Budget Tokens",
77+
"description": "Sets the max tokens for Claude's internal reasoning when thinking is enabled"
78+
}
79+
},
80+
"required": [
81+
"budget_tokens"
82+
]
83+
}
84+
},
85+
{
86+
"if": {
87+
"properties": {
88+
"enable_thinking": {
89+
"const": false
90+
}
91+
}
92+
},
93+
"then": {
94+
"properties": {}
95+
}
5396
}
54-
}
97+
]
5598
}

src/unstract/sdk/adapters/llm/llm_adapter.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def _test_llm_instance(llm: Optional[LLM]) -> bool:
7777
completion_kwargs = {}
7878
if hasattr(llm, 'model') and getattr(llm, 'model') not in O1_MODELS:
7979
completion_kwargs['temperature'] = 0.003
80-
80+
81+
if hasattr(llm, 'thinking_dict') and getattr(llm, 'thinking_dict') is not None:
82+
completion_kwargs['temperature'] = 1
83+
8184
response = llm.complete(
8285
"The capital of Tamilnadu is ",
8386
**completion_kwargs

0 commit comments

Comments
 (0)