llama-index-llms-openai 0.3.44__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- llama_index/llms/openai/base.py +16 -6
- llama_index/llms/openai/responses.py +14 -6
- llama_index/llms/openai/utils.py +8 -2
- {llama_index_llms_openai-0.3.44.dist-info → llama_index_llms_openai-0.4.1.dist-info}/METADATA +1 -1
- llama_index_llms_openai-0.4.1.dist-info/RECORD +9 -0
- llama_index_llms_openai-0.3.44.dist-info/RECORD +0 -9
- {llama_index_llms_openai-0.3.44.dist-info → llama_index_llms_openai-0.4.1.dist-info}/WHEEL +0 -0
- {llama_index_llms_openai-0.3.44.dist-info → llama_index_llms_openai-0.4.1.dist-info}/licenses/LICENSE +0 -0
llama_index/llms/openai/base.py
CHANGED
|
@@ -179,6 +179,7 @@ class OpenAI(FunctionCallingLLM):
|
|
|
179
179
|
)
|
|
180
180
|
max_tokens: Optional[int] = Field(
|
|
181
181
|
description="The maximum number of tokens to generate.",
|
|
182
|
+
default=None,
|
|
182
183
|
gt=0,
|
|
183
184
|
)
|
|
184
185
|
logprobs: Optional[bool] = Field(
|
|
@@ -215,9 +216,13 @@ class OpenAI(FunctionCallingLLM):
|
|
|
215
216
|
),
|
|
216
217
|
)
|
|
217
218
|
|
|
218
|
-
api_key: str = Field(default=None, description="The OpenAI API key.")
|
|
219
|
-
api_base: str = Field(
|
|
220
|
-
|
|
219
|
+
api_key: Optional[str] = Field(default=None, description="The OpenAI API key.")
|
|
220
|
+
api_base: Optional[str] = Field(
|
|
221
|
+
default=None, description="The base URL for OpenAI API."
|
|
222
|
+
)
|
|
223
|
+
api_version: Optional[str] = Field(
|
|
224
|
+
default=None, description="The API version for OpenAI API."
|
|
225
|
+
)
|
|
221
226
|
strict: bool = Field(
|
|
222
227
|
default=False,
|
|
223
228
|
description="Whether to use strict mode for invoking tools/using schemas.",
|
|
@@ -904,12 +909,15 @@ class OpenAI(FunctionCallingLLM):
|
|
|
904
909
|
chat_history: Optional[List[ChatMessage]] = None,
|
|
905
910
|
verbose: bool = False,
|
|
906
911
|
allow_parallel_tool_calls: bool = False,
|
|
907
|
-
|
|
912
|
+
tool_required: bool = False,
|
|
913
|
+
tool_choice: Optional[Union[str, dict]] = None,
|
|
908
914
|
strict: Optional[bool] = None,
|
|
909
915
|
**kwargs: Any,
|
|
910
916
|
) -> Dict[str, Any]:
|
|
911
917
|
"""Predict and call the tool."""
|
|
912
|
-
tool_specs = [
|
|
918
|
+
tool_specs = [
|
|
919
|
+
tool.metadata.to_openai_tool(skip_length_check=True) for tool in tools
|
|
920
|
+
]
|
|
913
921
|
|
|
914
922
|
# if strict is passed in, use, else default to the class-level attribute, else default to True`
|
|
915
923
|
if strict is not None:
|
|
@@ -934,7 +942,9 @@ class OpenAI(FunctionCallingLLM):
|
|
|
934
942
|
return {
|
|
935
943
|
"messages": messages,
|
|
936
944
|
"tools": tool_specs or None,
|
|
937
|
-
"tool_choice": resolve_tool_choice(tool_choice)
|
|
945
|
+
"tool_choice": resolve_tool_choice(tool_choice, tool_required)
|
|
946
|
+
if tool_specs
|
|
947
|
+
else None,
|
|
938
948
|
**kwargs,
|
|
939
949
|
}
|
|
940
950
|
|
|
@@ -570,7 +570,12 @@ class OpenAIResponses(FunctionCallingLLM):
|
|
|
570
570
|
elif isinstance(event, ResponseImageGenCallPartialImageEvent):
|
|
571
571
|
# Partial image
|
|
572
572
|
if event.partial_image_b64:
|
|
573
|
-
blocks.append(
|
|
573
|
+
blocks.append(
|
|
574
|
+
ImageBlock(
|
|
575
|
+
image=base64.b64decode(event.partial_image_b64),
|
|
576
|
+
detail=f"id_{event.partial_image_index}",
|
|
577
|
+
)
|
|
578
|
+
)
|
|
574
579
|
elif isinstance(event, ResponseFunctionCallArgumentsDeltaEvent):
|
|
575
580
|
# Function call arguments are being streamed
|
|
576
581
|
if current_tool_call is not None:
|
|
@@ -815,7 +820,8 @@ class OpenAIResponses(FunctionCallingLLM):
|
|
|
815
820
|
user_msg: Optional[Union[str, ChatMessage]] = None,
|
|
816
821
|
chat_history: Optional[List[ChatMessage]] = None,
|
|
817
822
|
allow_parallel_tool_calls: bool = True,
|
|
818
|
-
|
|
823
|
+
tool_required: bool = False,
|
|
824
|
+
tool_choice: Optional[Union[str, dict]] = None,
|
|
819
825
|
verbose: bool = False,
|
|
820
826
|
strict: Optional[bool] = None,
|
|
821
827
|
**kwargs: Any,
|
|
@@ -848,7 +854,9 @@ class OpenAIResponses(FunctionCallingLLM):
|
|
|
848
854
|
return {
|
|
849
855
|
"messages": messages,
|
|
850
856
|
"tools": tool_specs or None,
|
|
851
|
-
"tool_choice": resolve_tool_choice(tool_choice)
|
|
857
|
+
"tool_choice": resolve_tool_choice(tool_choice, tool_required)
|
|
858
|
+
if tool_specs
|
|
859
|
+
else None,
|
|
852
860
|
"parallel_tool_calls": allow_parallel_tool_calls,
|
|
853
861
|
**kwargs,
|
|
854
862
|
}
|
|
@@ -860,9 +868,9 @@ class OpenAIResponses(FunctionCallingLLM):
|
|
|
860
868
|
**kwargs: Any,
|
|
861
869
|
) -> List[ToolSelection]:
|
|
862
870
|
"""Predict and call the tool."""
|
|
863
|
-
tool_calls: List[
|
|
864
|
-
|
|
865
|
-
|
|
871
|
+
tool_calls: List[ResponseFunctionToolCall] = (
|
|
872
|
+
response.message.additional_kwargs.get("tool_calls", [])
|
|
873
|
+
)
|
|
866
874
|
|
|
867
875
|
if len(tool_calls) < 1:
|
|
868
876
|
if error_on_no_tool_call:
|
llama_index/llms/openai/utils.py
CHANGED
|
@@ -754,13 +754,19 @@ def validate_openai_api_key(api_key: Optional[str] = None) -> None:
|
|
|
754
754
|
raise ValueError(MISSING_API_KEY_ERROR_MESSAGE)
|
|
755
755
|
|
|
756
756
|
|
|
757
|
-
def resolve_tool_choice(
|
|
757
|
+
def resolve_tool_choice(
|
|
758
|
+
tool_choice: Optional[Union[str, dict]], tool_required: bool = False
|
|
759
|
+
) -> Union[str, dict]:
|
|
758
760
|
"""
|
|
759
761
|
Resolve tool choice.
|
|
760
762
|
|
|
761
763
|
If tool_choice is a function name string, return the appropriate dict.
|
|
762
764
|
"""
|
|
763
|
-
if
|
|
765
|
+
if tool_choice is None:
|
|
766
|
+
tool_choice = "required" if tool_required else "auto"
|
|
767
|
+
if isinstance(tool_choice, dict):
|
|
768
|
+
return tool_choice
|
|
769
|
+
if tool_choice not in ["none", "auto", "required"]:
|
|
764
770
|
return {"type": "function", "function": {"name": tool_choice}}
|
|
765
771
|
|
|
766
772
|
return tool_choice
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
llama_index/llms/openai/__init__.py,sha256=8nmgixeXifQ4eVSgtCic54WxXqrrpXQPL4rhACWCSFs,229
|
|
2
|
+
llama_index/llms/openai/base.py,sha256=LTed9nxKpEnfha_FNDBrzNP3B1CTDFwaxGyAFUXXV5o,38856
|
|
3
|
+
llama_index/llms/openai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
llama_index/llms/openai/responses.py,sha256=Dmp7Tj-SzrzOcqGtWSBAFn-kwT44giXJSYxAXx233Ao,35944
|
|
5
|
+
llama_index/llms/openai/utils.py,sha256=0xO-_6FPZRFCbW5JeqJDCMzLx3WN2_vVeAApWG74oA4,28071
|
|
6
|
+
llama_index_llms_openai-0.4.1.dist-info/METADATA,sha256=qWTl2peBaSSumiXi90zIbdp3Ax04fbGjzK4u6fZEdmo,3039
|
|
7
|
+
llama_index_llms_openai-0.4.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
llama_index_llms_openai-0.4.1.dist-info/licenses/LICENSE,sha256=JPQLUZD9rKvCTdu192Nk0V5PAwklIg6jANii3UmTyMs,1065
|
|
9
|
+
llama_index_llms_openai-0.4.1.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
llama_index/llms/openai/__init__.py,sha256=8nmgixeXifQ4eVSgtCic54WxXqrrpXQPL4rhACWCSFs,229
|
|
2
|
-
llama_index/llms/openai/base.py,sha256=2ojLUicnyDwVXO8-_kis93Yibrc8tQoUthSsY7tSyn8,38642
|
|
3
|
-
llama_index/llms/openai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
llama_index/llms/openai/responses.py,sha256=IVB2ZW8AZopUqKzaeJBsA36glKa9z6bh9lSBdT_KqGE,35749
|
|
5
|
-
llama_index/llms/openai/utils.py,sha256=K8LQ6ykuU-TPzIJQLvZ869q5aGvXSM9HAJIX8GQfM_s,27913
|
|
6
|
-
llama_index_llms_openai-0.3.44.dist-info/METADATA,sha256=pK9skvohtMh4L5JpWFDWht1gOSF3ikgnLJLsARZi1SI,3040
|
|
7
|
-
llama_index_llms_openai-0.3.44.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
llama_index_llms_openai-0.3.44.dist-info/licenses/LICENSE,sha256=JPQLUZD9rKvCTdu192Nk0V5PAwklIg6jANii3UmTyMs,1065
|
|
9
|
-
llama_index_llms_openai-0.3.44.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|