gllm-inference-binary 0.5.9__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.

Potentially problematic release.


This version of gllm-inference-binary might be problematic. Click here for more details.

Files changed (94) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/build_em_invoker.pyi +122 -0
  4. gllm_inference/builder/build_lm_invoker.pyi +150 -0
  5. gllm_inference/builder/build_lm_request_processor.pyi +93 -0
  6. gllm_inference/builder/build_output_parser.pyi +29 -0
  7. gllm_inference/catalog/__init__.pyi +4 -0
  8. gllm_inference/catalog/catalog.pyi +121 -0
  9. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  10. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  11. gllm_inference/constants.pyi +10 -0
  12. gllm_inference/em_invoker/__init__.pyi +9 -0
  13. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +86 -0
  14. gllm_inference/em_invoker/em_invoker.pyi +83 -0
  15. gllm_inference/em_invoker/google_em_invoker.pyi +124 -0
  16. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  17. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +62 -0
  18. gllm_inference/em_invoker/langchain_em_invoker.pyi +41 -0
  19. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +92 -0
  20. gllm_inference/em_invoker/openai_em_invoker.pyi +86 -0
  21. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  22. gllm_inference/em_invoker/schema/google.pyi +7 -0
  23. gllm_inference/em_invoker/schema/langchain.pyi +4 -0
  24. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  25. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  26. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  27. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  28. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +99 -0
  29. gllm_inference/em_invoker/voyage_em_invoker.pyi +101 -0
  30. gllm_inference/exceptions/__init__.pyi +4 -0
  31. gllm_inference/exceptions/error_parser.pyi +48 -0
  32. gllm_inference/exceptions/exceptions.pyi +120 -0
  33. gllm_inference/lm_invoker/__init__.pyi +11 -0
  34. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +275 -0
  35. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +253 -0
  36. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +232 -0
  37. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +166 -0
  38. gllm_inference/lm_invoker/google_lm_invoker.pyi +310 -0
  39. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +258 -0
  40. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +248 -0
  41. gllm_inference/lm_invoker/lm_invoker.pyi +151 -0
  42. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +265 -0
  43. gllm_inference/lm_invoker/openai_lm_invoker.pyi +361 -0
  44. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  45. gllm_inference/lm_invoker/schema/anthropic.pyi +50 -0
  46. gllm_inference/lm_invoker/schema/bedrock.pyi +48 -0
  47. gllm_inference/lm_invoker/schema/datasaur.pyi +12 -0
  48. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  49. gllm_inference/lm_invoker/schema/langchain.pyi +22 -0
  50. gllm_inference/lm_invoker/schema/openai.pyi +90 -0
  51. gllm_inference/lm_invoker/schema/openai_compatible.pyi +56 -0
  52. gllm_inference/model/__init__.pyi +9 -0
  53. gllm_inference/model/em/__init__.pyi +0 -0
  54. gllm_inference/model/em/google_em.pyi +16 -0
  55. gllm_inference/model/em/openai_em.pyi +15 -0
  56. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  57. gllm_inference/model/em/voyage_em.pyi +20 -0
  58. gllm_inference/model/lm/__init__.pyi +0 -0
  59. gllm_inference/model/lm/anthropic_lm.pyi +20 -0
  60. gllm_inference/model/lm/google_lm.pyi +17 -0
  61. gllm_inference/model/lm/openai_lm.pyi +27 -0
  62. gllm_inference/output_parser/__init__.pyi +3 -0
  63. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  64. gllm_inference/output_parser/output_parser.pyi +27 -0
  65. gllm_inference/prompt_builder/__init__.pyi +3 -0
  66. gllm_inference/prompt_builder/prompt_builder.pyi +56 -0
  67. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  68. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  69. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  70. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  71. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  72. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  73. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  74. gllm_inference/request_processor/__init__.pyi +4 -0
  75. gllm_inference/request_processor/lm_request_processor.pyi +92 -0
  76. gllm_inference/request_processor/uses_lm_mixin.pyi +50 -0
  77. gllm_inference/schema/__init__.pyi +13 -0
  78. gllm_inference/schema/attachment.pyi +88 -0
  79. gllm_inference/schema/code_exec_result.pyi +14 -0
  80. gllm_inference/schema/enums.pyi +24 -0
  81. gllm_inference/schema/lm_output.pyi +36 -0
  82. gllm_inference/schema/message.pyi +52 -0
  83. gllm_inference/schema/model_id.pyi +138 -0
  84. gllm_inference/schema/reasoning.pyi +15 -0
  85. gllm_inference/schema/token_usage.pyi +11 -0
  86. gllm_inference/schema/tool_call.pyi +14 -0
  87. gllm_inference/schema/tool_result.pyi +11 -0
  88. gllm_inference/schema/type_alias.pyi +15 -0
  89. gllm_inference/utils/__init__.pyi +4 -0
  90. gllm_inference/utils/langchain.pyi +30 -0
  91. gllm_inference/utils/validation.pyi +12 -0
  92. gllm_inference_binary-0.5.9.dist-info/METADATA +108 -0
  93. gllm_inference_binary-0.5.9.dist-info/RECORD +94 -0
  94. gllm_inference_binary-0.5.9.dist-info/WHEEL +4 -0
@@ -0,0 +1,275 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.event import EventEmitter as EventEmitter
3
+ from gllm_core.schema.tool import Tool as Tool
4
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
5
+ from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
6
+ from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
7
+ from gllm_inference.lm_invoker.schema.anthropic import InputType as InputType, Key as Key, OutputType as OutputType
8
+ from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EmitDataType as EmitDataType, LMOutput as LMOutput, Message as Message, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult
9
+ from langchain_core.tools import Tool as LangChainTool
10
+ from typing import Any
11
+
12
+ SUPPORTED_ATTACHMENTS: Incomplete
13
+ DEFAULT_MAX_TOKENS: int
14
+ DEFAULT_THINKING_BUDGET: int
15
+
16
+ class AnthropicLMInvoker(BaseLMInvoker):
17
+ '''A language model invoker to interact with Anthropic language models.
18
+
19
+ Attributes:
20
+ model_id (str): The model ID of the language model.
21
+ model_provider (str): The provider of the language model.
22
+ model_name (str): The name of the language model.
23
+ client (AsyncAnthropic): The Anthropic client instance.
24
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
25
+ tools (list[Tool]): Tools provided to the model to enable tool calling.
26
+ response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
27
+ structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
28
+ output_analytics (bool): Whether to output the invocation analytics.
29
+ retry_config (RetryConfig): The retry configuration for the language model.
30
+ thinking (bool): Whether to enable thinking. Only allowed for thinking models.
31
+ thinking_budget (int): The tokens allocated for the thinking process. Only allowed for thinking models.
32
+
33
+ Basic usage:
34
+ The `AnthropicLMInvoker` can be used as follows:
35
+ ```python
36
+ lm_invoker = AnthropicLMInvoker(model_name="claude-sonnet-4-20250514")
37
+ result = await lm_invoker.invoke("Hi there!")
38
+ ```
39
+
40
+ Input types:
41
+ The `AnthropicLMInvoker` supports the following input types: text, image, and document.
42
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
43
+
44
+ Usage example:
45
+ ```python
46
+ text = "What animal is in this image?"
47
+ image = Attachment.from_path("path/to/local/image.png")
48
+ result = await lm_invoker.invoke([text, image])
49
+ ```
50
+
51
+ Tool calling:
52
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
53
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
54
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
55
+ `tool_calls` attribute in the output.
56
+
57
+ Usage example:
58
+ ```python
59
+ lm_invoker = AnthropicLMInvoker(..., tools=[tool_1, tool_2])
60
+ ```
61
+
62
+ Output example:
63
+ ```python
64
+ LMOutput(
65
+ response="Let me call the tools...",
66
+ tool_calls=[
67
+ ToolCall(id="123", name="tool_1", args={"key": "value"}),
68
+ ToolCall(id="456", name="tool_2", args={"key": "value"}),
69
+ ]
70
+ )
71
+ ```
72
+
73
+ Structured output:
74
+ Structured output is a feature that allows the language model to output a structured response.
75
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
76
+
77
+ The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
78
+ If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
79
+ For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
80
+
81
+ Structured output is achieved by providing the schema name in the `tool_choice` parameter. This forces
82
+ the model to call the provided schema as a tool. Thus, structured output is not compatible with:
83
+ 1. Tool calling, since the tool calling is reserved to force the model to call the provided schema as a tool.
84
+ 2. Thinking, since thinking is not allowed when a tool use is forced through the `tool_choice` parameter.
85
+ The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
86
+ invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
87
+
88
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
89
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
90
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
91
+
92
+ # Example 1: Using a JSON schema dictionary
93
+ Usage example:
94
+ ```python
95
+ schema = {
96
+ "title": "Animal",
97
+ "description": "A description of an animal.",
98
+ "properties": {
99
+ "color": {"title": "Color", "type": "string"},
100
+ "name": {"title": "Name", "type": "string"},
101
+ },
102
+ "required": ["name", "color"],
103
+ "type": "object",
104
+ }
105
+ lm_invoker = AnthropicLMInvoker(..., response_schema=schema)
106
+ ```
107
+ Output example:
108
+ ```python
109
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
110
+ ```
111
+
112
+ # Example 2: Using a Pydantic BaseModel class
113
+ Usage example:
114
+ ```python
115
+ class Animal(BaseModel):
116
+ name: str
117
+ color: str
118
+
119
+ lm_invoker = AnthropicLMInvoker(..., response_schema=Animal)
120
+ ```
121
+ Output example:
122
+ ```python
123
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
124
+ ```
125
+
126
+ Analytics tracking:
127
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
128
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
129
+ When enabled, the following attributes will be stored in the output:
130
+ 1. `token_usage`: The token usage.
131
+ 2. `duration`: The duration in seconds.
132
+ 3. `finish_details`: The details about how the generation finished.
133
+
134
+ Output example:
135
+ ```python
136
+ LMOutput(
137
+ response="Golden retriever is a good dog breed.",
138
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
139
+ duration=0.729,
140
+ finish_details={"stop_reason": "end_turn"},
141
+ )
142
+ ```
143
+
144
+ Retry and timeout:
145
+ The `AnthropicLMInvoker` supports retry and timeout configuration.
146
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
147
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
148
+
149
+ Retry config examples:
150
+ ```python
151
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
152
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
153
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
154
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
155
+ ```
156
+
157
+ Usage example:
158
+ ```python
159
+ lm_invoker = AnthropicLMInvoker(..., retry_config=retry_config)
160
+ ```
161
+
162
+ Thinking:
163
+ Thinking is a feature that allows the language model to have enhanced reasoning capabilities for complex tasks,
164
+ while also providing transparency into its step-by-step thought process before it delivers its final answer.
165
+ This feature is only available for certain models, starting from Claude 3.7 Sonnet.
166
+ It can be enabled by setting the `thinking` parameter to `True`.
167
+
168
+ When thinking is enabled, the amount of tokens allocated for the thinking process can be set via the
169
+ `thinking_budget` parameter. The `thinking_budget`:
170
+ 1. Must be greater than or equal to 1024.
171
+ 2. Must be less than the `max_tokens` hyperparameter, as the `thinking_budget` is allocated from the
172
+ `max_tokens`. For example, if `max_tokens=2048` and `thinking_budget=1024`, the language model will
173
+ allocate at most 1024 tokens for thinking and the remaining 1024 tokens for generating the response.
174
+
175
+ When enabled, the reasoning is stored in the `reasoning` attribute in the output.
176
+
177
+ Usage example:
178
+ ```python
179
+ lm_invoker = AnthropicLMInvoker(..., thinking=True, thinking_budget=1024)
180
+ ```
181
+
182
+ Output example:
183
+ ```python
184
+ LMOutput(
185
+ response="Golden retriever is a good dog breed.",
186
+ reasoning=[Reasoning(type="thinking", reasoning="Let me think about it...", signature="x")],
187
+ )
188
+ ```
189
+
190
+ When streaming is enabled, the thinking token will be streamed with the `EventType.DATA` event type.
191
+
192
+ Streaming output example:
193
+ ```python
194
+ {"type": "data", "value": \'{"data_type": "thinking_start", "data_value": ""}\', ...}
195
+ {"type": "data", "value": \'{"data_type": "thinking", "data_value": "Let me think "}\', ...}
196
+ {"type": "data", "value": \'{"data_type": "thinking", "data_value": "about it..."}\', ...}
197
+ {"type": "data", "value": \'{"data_type": "thinking_end", "data_value": ""}\', ...}
198
+ {"type": "response", "value": "Golden retriever ", ...}
199
+ {"type": "response", "value": "is a good dog breed.", ...}
200
+ ```
201
+
202
+ Output types:
203
+ The output of the `AnthropicLMInvoker` can either be:
204
+ 1. `str`: The text response if no additional output is needed.
205
+ 2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
206
+ 2.1. response (str): The text response.
207
+ 2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
208
+ model decides to invoke tools. Defaults to an empty list.
209
+ 2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
210
+ parameter is defined. Defaults to None.
211
+ 2.4. token_usage (TokenUsage | None): The token usage information, if the `output_analytics` parameter is
212
+ set to `True`. Defaults to None.
213
+ 2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
214
+ parameter is set to `True`. Defaults to None.
215
+ 2.6. finish_details (dict[str, Any]): The details about how the generation finished, if the
216
+ `output_analytics` parameter is set to `True`. Defaults to an empty dictionary.
217
+ 2.7. reasoning (list[Reasoning]): The reasoning objects, if the `thinking` parameter is set to `True`.
218
+ Defaults to an empty list.
219
+ 2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
220
+ 2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
221
+ Defaults to an empty list.
222
+ '''
223
+ client: Incomplete
224
+ thinking: Incomplete
225
+ thinking_budget: Incomplete
226
+ def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, tools: list[Tool | LangChainTool] | None = None, response_schema: ResponseSchema | None = None, output_analytics: bool = False, retry_config: RetryConfig | None = None, thinking: bool = False, thinking_budget: int = ...) -> None:
227
+ """Initializes the AnthropicLmInvoker instance.
228
+
229
+ Args:
230
+ model_name (str): The name of the Anthropic language model.
231
+ api_key (str | None, optional): The Anthropic API key. Defaults to None, in which case the
232
+ `ANTHROPIC_API_KEY` environment variable will be used.
233
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Anthropic client.
234
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
235
+ Defaults to None.
236
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
237
+ Defaults to None, in which case an empty list is used.
238
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
239
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
240
+ dictionary. Defaults to None.
241
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
242
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
243
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
244
+ thinking (bool, optional): Whether to enable thinking. Only allowed for thinking models. Defaults to False.
245
+ thinking_budget (int, optional): The tokens allocated for the thinking process. Must be greater than or
246
+ equal to 1024. Only allowed for thinking models. Defaults to DEFAULT_THINKING_BUDGET.
247
+
248
+ Raises:
249
+ ValueError:
250
+ 1. `thinking` is True, but the `thinking_budget` is less than 1024.
251
+ 3. `response_schema` is provided, but `tools` or `thinking` are also provided.
252
+ """
253
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
254
+ """Sets the tools for the Anthropic language model.
255
+
256
+ This method sets the tools for the Anthropic language model. Any existing tools will be replaced.
257
+
258
+ Args:
259
+ tools (list[Tool | LangChainTool]): The list of tools to be used.
260
+
261
+ Raises:
262
+ ValueError: If `response_schema` exists.
263
+ """
264
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
265
+ """Sets the response schema for the Anthropic language model.
266
+
267
+ This method sets the response schema for the Anthropic language model. Any existing response schema will be
268
+ replaced.
269
+
270
+ Args:
271
+ response_schema (ResponseSchema | None): The response schema to be used.
272
+
273
+ Raises:
274
+ ValueError: If `tools` exists.
275
+ """
@@ -0,0 +1,253 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.schema.tool import Tool as Tool
3
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
4
+ from gllm_inference.constants import DEFAULT_AZURE_OPENAI_API_VERSION as DEFAULT_AZURE_OPENAI_API_VERSION, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
5
+ from gllm_inference.lm_invoker.openai_lm_invoker import OpenAILMInvoker as OpenAILMInvoker, ReasoningEffort as ReasoningEffort, ReasoningSummary as ReasoningSummary
6
+ from gllm_inference.lm_invoker.schema.openai import Key as Key
7
+ from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, ResponseSchema as ResponseSchema
8
+ from langchain_core.tools import Tool as LangChainTool
9
+ from typing import Any
10
+
11
+ class AzureOpenAILMInvoker(OpenAILMInvoker):
12
+ '''A language model invoker to interact with Azure OpenAI language models.
13
+
14
+ Attributes:
15
+ model_id (str): The model ID of the language model.
16
+ model_provider (str): The provider of the language model.
17
+ model_name (str): The name of the Azure OpenAI language model deployment.
18
+ client (AsyncAzureOpenAI): The Azure OpenAI client instance.
19
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
20
+ tools (list[Tool]): The list of tools provided to the model to enable tool calling.
21
+ response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
22
+ structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
23
+ output_analytics (bool): Whether to output the invocation analytics.
24
+ retry_config (RetryConfig): The retry configuration for the language model.
25
+ reasoning_effort (ReasoningEffort | None): The reasoning effort for reasoning models. Not allowed
26
+ for non-reasoning models. If None, the model will perform medium reasoning effort.
27
+ reasoning_summary (ReasoningSummary | None): The reasoning summary level for reasoning models. Not allowed
28
+ for non-reasoning models. If None, no summary will be generated.
29
+ code_interpreter (bool): Whether to enable the code interpreter. Currently not supported.
30
+ web_search (bool): Whether to enable the web search. Currently not supported.
31
+
32
+ Basic usage:
33
+ The `AzureOpenAILMInvoker` can be used as follows:
34
+ ```python
35
+ lm_invoker = AzureOpenAILMInvoker(
36
+ azure_endpoint="https://<your-azure-openai-endpoint>.openai.azure.com/",
37
+ azure_deployment="<your-azure-openai-deployment>",
38
+ )
39
+ result = await lm_invoker.invoke("Hi there!")
40
+ ```
41
+
42
+ Input types:
43
+ The `AzureOpenAILMInvoker` supports the following input types: text, document, and image.
44
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
45
+
46
+ Usage example:
47
+ ```python
48
+ text = "What animal is in this image?"
49
+ image = Attachment.from_path("path/to/local/image.png")
50
+ result = await lm_invoker.invoke([text, image])
51
+ ```
52
+
53
+ Tool calling:
54
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
55
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
56
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
57
+ `tool_calls` attribute in the output.
58
+
59
+ Usage example:
60
+ ```python
61
+ lm_invoker = AzureOpenAILMInvoker(..., tools=[tool_1, tool_2])
62
+ ```
63
+
64
+ Output example:
65
+ ```python
66
+ LMOutput(
67
+ response="Let me call the tools...",
68
+ tool_calls=[
69
+ ToolCall(id="123", name="tool_1", args={"key": "value"}),
70
+ ToolCall(id="456", name="tool_2", args={"key": "value"}),
71
+ ]
72
+ )
73
+ ```
74
+
75
+ Structured output:
76
+ Structured output is a feature that allows the language model to output a structured response.
77
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
78
+
79
+ The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
80
+ If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
81
+ For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
82
+
83
+ The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
84
+ invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
85
+
86
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
87
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
88
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
89
+
90
+ # Example 1: Using a JSON schema dictionary
91
+ Usage example:
92
+ ```python
93
+ schema = {
94
+ "title": "Animal",
95
+ "description": "A description of an animal.",
96
+ "properties": {
97
+ "color": {"title": "Color", "type": "string"},
98
+ "name": {"title": "Name", "type": "string"},
99
+ },
100
+ "required": ["name", "color"],
101
+ "type": "object",
102
+ }
103
+ lm_invoker = AzureOpenAILMInvoker(..., response_schema=schema)
104
+ ```
105
+ Output example:
106
+ ```python
107
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
108
+ ```
109
+
110
+ # Example 2: Using a Pydantic BaseModel class
111
+ Usage example:
112
+ ```python
113
+ class Animal(BaseModel):
114
+ name: str
115
+ color: str
116
+
117
+ lm_invoker = AzureOpenAILMInvoker(..., response_schema=Animal)
118
+ ```
119
+ Output example:
120
+ ```python
121
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
122
+ ```
123
+
124
+ Analytics tracking:
125
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
126
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
127
+ When enabled, the following attributes will be stored in the output:
128
+ 1. `token_usage`: The token usage.
129
+ 2. `duration`: The duration in seconds.
130
+ 3. `finish_details`: The details about how the generation finished.
131
+
132
+ Output example:
133
+ ```python
134
+ LMOutput(
135
+ response="Golden retriever is a good dog breed.",
136
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
137
+ duration=0.729,
138
+ finish_details={"status": "completed", "incomplete_details": {"reason": None}},
139
+ )
140
+ ```
141
+
142
+ Retry and timeout:
143
+ The `AzureOpenAILMInvoker` supports retry and timeout configuration.
144
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
145
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
146
+
147
+ Retry config examples:
148
+ ```python
149
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
150
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
151
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
152
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
153
+ ```
154
+
155
+ Usage example:
156
+ ```python
157
+ lm_invoker = AzureOpenAILMInvoker(..., retry_config=retry_config)
158
+ ```
159
+
160
+ Reasoning:
161
+ Azure OpenAI\'s o-series models are classified as reasoning models. Reasoning models think before they answer,
162
+ producing a long internal chain of thought before responding to the user. Reasoning models excel in
163
+ complex problem solving, coding, scientific reasoning, and multi-step planning for agentic workflows.
164
+
165
+ The reasoning effort of reasoning models can be set via the `reasoning_effort` parameter. This parameter
166
+ will guide the models on how many reasoning tokens it should generate before creating a response to the prompt.
167
+ Available options include:
168
+ 1. "low": Favors speed and economical token usage.
169
+ 2. "medium": Favors a balance between speed and reasoning accuracy.
170
+ 3. "high": Favors more complete reasoning at the cost of more tokens generated and slower responses.
171
+ When not set, the reasoning effort will be equivalent to `medium` by default.
172
+
173
+ Azure OpenAI doesn\'t expose the raw reasoning tokens. However, the summary of the reasoning tokens can still be
174
+ generated. The summary level can be set via the `reasoning_summary` parameter. Available options include:
175
+ 1. "auto": The model decides the summary level automatically.
176
+ 2. "detailed": The model will generate a detailed summary of the reasoning tokens.
177
+ Reasoning summary is not compatible with tool calling.
178
+ When enabled, the reasoning summary will be stored in the `reasoning` attribute in the output.
179
+
180
+ Output example:
181
+ ```python
182
+ LMOutput(
183
+ response="Golden retriever is a good dog breed.",
184
+ reasoning=[Reasoning(id="x", reasoning="Let me think about it...")],
185
+ )
186
+ ```
187
+
188
+ When streaming is enabled along with reasoning summary, the reasoning summary token will be streamed with the
189
+ `EventType.DATA` event type.
190
+
191
+ Streaming output example:
192
+ ```python
193
+ {"type": "data", "value": "Let me think ", ...} # Reasoning summary token
194
+ {"type": "data", "value": "about it...", ...} # Reasoning summary token
195
+ {"type": "response", "value": "Golden retriever ", ...} # Response token
196
+ {"type": "response", "value": "is a good dog breed.", ...} # Response token
197
+ ```
198
+
199
+ Setting reasoning-related parameters for non-reasoning models will raise an error.
200
+
201
+ Output types:
202
+ The output of the `AzureOpenAILMInvoker` can either be:
203
+ 1. `str`: The text response if no additional output is needed.
204
+ 2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
205
+ 2.1. response (str): The text response.
206
+ 2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
207
+ model decides to invoke tools. Defaults to an empty list.
208
+ 2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
209
+ parameter is defined. Defaults to None.
210
+ 2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
211
+ set to `True`. Defaults to None.
212
+ 2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
213
+ parameter is set to `True`. Defaults to None.
214
+ 2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
215
+ `output_analytics` parameter is set to `True`. Defaults to None.
216
+ 2.7. reasoning (list[Reasoning]): The reasoning objects, if the `reasoning_summary` parameter is provided
217
+ for reasoning models. Defaults to an empty list.
218
+ 2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
219
+ 2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
220
+ Defaults to an empty list.
221
+ '''
222
+ client: Incomplete
223
+ def __init__(self, azure_endpoint: str, azure_deployment: str, api_key: str | None = None, api_version: str = ..., model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, tools: list[Tool | LangChainTool] | None = None, response_schema: ResponseSchema | None = None, output_analytics: bool = False, retry_config: RetryConfig | None = None, reasoning_effort: ReasoningEffort | None = None, reasoning_summary: ReasoningSummary | None = None) -> None:
224
+ """Initializes a new instance of the AzureOpenAILMInvoker class.
225
+
226
+ Args:
227
+ azure_endpoint (str): The endpoint of the Azure OpenAI service.
228
+ azure_deployment (str): The deployment name of the Azure OpenAI service.
229
+ api_key (str | None, optional): The API key for authenticating with Azure OpenAI. Defaults to None, in
230
+ which case the `AZURE_OPENAI_API_KEY` environment variable will be used.
231
+ api_version (str, optional): The API version of the Azure OpenAI service. Defaults to
232
+ `DEFAULT_AZURE_OPENAI_API_VERSION`.
233
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
234
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
235
+ Defaults to None.
236
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
237
+ Defaults to None.
238
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
239
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
240
+ dictionary. Defaults to None.
241
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
242
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
243
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
244
+ reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
245
+ for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
246
+ reasoning_summary (ReasoningSummary | None, optional): The reasoning summary level for reasoning models.
247
+ Not allowed for non-reasoning models. If None, no summary will be generated. Defaults to None.
248
+
249
+ Raises:
250
+ ValueError:
251
+ 1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
252
+ 2. `reasoning_summary` is provided, but is not a valid ReasoningSummary.
253
+ """