Skip to content

Commit ac197bb

Browse files
[FEAT] Llama-index LLM updates and reasoning effort parameter for OpenAI 'O' series models (#186)
* Added reasoning effort and support for o3 openai model * updated azure openai library * Update src/unstract/sdk/__init__.py Co-authored-by: Chandrasekharan M <[email protected]> Signed-off-by: Praveen Kumar <[email protected]> * Added a more meaningful message for the increase of latency and cost for reasoning effort --------- Signed-off-by: Praveen Kumar <[email protected]> Co-authored-by: Chandrasekharan M <[email protected]>
1 parent fff3220 commit ac197bb

File tree

5 files changed

+2116
-2043
lines changed

5 files changed

+2116
-2043
lines changed

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"python-magic~=0.4.27",
2727
"python-dotenv==1.0.0",
2828
# Adapter changes
29-
"llama-index==0.12.8",
29+
"llama-index==0.12.37",
3030
"tiktoken~=0.9.0",
3131
"transformers==4.37.0",
3232
"llama-index-embeddings-google==0.3.0",
@@ -48,14 +48,14 @@ dependencies = [
4848
"llama-index-vector-stores-weaviate==1.3.1",
4949
"llama-index-vector-stores-pinecone==0.4.2",
5050
"llama-index-vector-stores-qdrant==0.4.2",
51-
"llama-index-llms-openai==0.3.25",
51+
"llama-index-llms-openai==0.3.42",
5252
"llama-index-llms-palm==0.3.0",
5353
"llama-index-llms-mistralai==0.3.1",
5454
"mistralai==1.2.5",
5555
"llama-index-llms-anyscale==0.3.0",
56-
"llama-index-llms-anthropic==0.6.10",
57-
"llama-index-llms-azure-openai==0.3.1",
58-
"llama-index-llms-vertex==0.4.2",
56+
"llama-index-llms-anthropic==0.6.14",
57+
"llama-index-llms-azure-openai==0.3.2",
58+
"llama-index-llms-vertex==0.4.6",
5959
"llama-index-llms-replicate==0.4.0",
6060
"llama-index-llms-ollama==0.5.0",
6161
"llama-index-llms-bedrock==0.3.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__ = "v0.71.1"
1+
__version__ = "v0.72.0"
22

33

44
def get_sdk_version() -> str:

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Constants:
2020
API_BASE = "api_base"
2121
API_VERSION = "api_version"
2222
MAX_TOKENS = "max_tokens"
23+
RESONING_EFFORT = "reasoning_effort"
24+
ENABLE_REASONING = "enable_reasoning"
2325

2426

2527
class OpenAILLM(LLMAdapter):
@@ -54,6 +56,7 @@ def get_llm_instance(self) -> LLM:
5456
max_tokens = self.config.get(Constants.MAX_TOKENS)
5557
max_tokens = int(max_tokens) if max_tokens else None
5658
model = str(self.config.get(Constants.MODEL))
59+
enable_reasoning = self.config.get(Constants.ENABLE_REASONING)
5760

5861
llm_kwargs = {
5962
"model": model,
@@ -70,10 +73,15 @@ def get_llm_instance(self) -> LLM:
7073
"max_tokens": max_tokens,
7174
}
7275

73-
# O-series models default to temperature=1, ignoring passed values, so it's not set explicitly.
76+
# O-series models default to temperature=1
7477
if model not in O1_MODELS:
7578
llm_kwargs["temperature"] = 0
7679

80+
if enable_reasoning:
81+
llm_kwargs["reasoning_effort"] = self.config.get(
82+
Constants.RESONING_EFFORT
83+
)
84+
7785
llm = OpenAI(**llm_kwargs)
7886
return llm
7987
except Exception as e:

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,53 @@
6060
"title": "Timeout",
6161
"default": 900,
6262
"description": "Timeout in seconds"
63+
},
64+
"enable_reasoning": {
65+
"type": "boolean",
66+
"title": "Enable Reasoning",
67+
"default": false,
68+
"description": "Allow the model to apply extra reasoning for complex tasks. May slightly increase latency and cost, typically within 20–50% depending on the level selected. Only applicable for [O series models](https://platform.openai.com/docs/models#reasoning)."
69+
}
70+
},
71+
"allOf": [
72+
{
73+
"if": {
74+
"properties": {
75+
"enable_reasoning": {
76+
"const": true
77+
}
78+
}
79+
},
80+
"then": {
81+
"properties": {
82+
"reasoning_effort": {
83+
"type": "string",
84+
"enum": [
85+
"low",
86+
"medium",
87+
"high"
88+
],
89+
"default": "medium",
90+
"title": "Reasoning Effort",
91+
"description": "Sets the Reasoning Strength when Reasoning Effort is enabled"
92+
}
93+
},
94+
"required": [
95+
"reasoning_effort"
96+
]
97+
}
98+
},
99+
{
100+
"if": {
101+
"properties": {
102+
"enable_reasoning": {
103+
"const": false
104+
}
105+
}
106+
},
107+
"then": {
108+
"properties": {}
109+
}
63110
}
64-
}
111+
]
65112
}

0 commit comments

Comments
 (0)