gllm-inference-binary 0.5.55__cp313-cp313-macosx_13_0_arm64.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 (137) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/_build_invoker.pyi +28 -0
  4. gllm_inference/builder/build_em_invoker.pyi +130 -0
  5. gllm_inference/builder/build_lm_invoker.pyi +213 -0
  6. gllm_inference/builder/build_lm_request_processor.pyi +88 -0
  7. gllm_inference/builder/build_output_parser.pyi +29 -0
  8. gllm_inference/catalog/__init__.pyi +4 -0
  9. gllm_inference/catalog/catalog.pyi +121 -0
  10. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  11. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  12. gllm_inference/constants.pyi +12 -0
  13. gllm_inference/em_invoker/__init__.pyi +12 -0
  14. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  15. gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
  16. gllm_inference/em_invoker/cohere_em_invoker.pyi +128 -0
  17. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  18. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  19. gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
  20. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  21. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  22. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  23. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
  24. gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
  25. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  26. gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
  27. gllm_inference/em_invoker/schema/cohere.pyi +20 -0
  28. gllm_inference/em_invoker/schema/google.pyi +9 -0
  29. gllm_inference/em_invoker/schema/jina.pyi +29 -0
  30. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  31. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  32. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  33. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  34. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  35. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  36. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  37. gllm_inference/exceptions/__init__.pyi +4 -0
  38. gllm_inference/exceptions/error_parser.pyi +41 -0
  39. gllm_inference/exceptions/exceptions.pyi +132 -0
  40. gllm_inference/exceptions/provider_error_map.pyi +24 -0
  41. gllm_inference/lm_invoker/__init__.pyi +14 -0
  42. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +318 -0
  43. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +237 -0
  44. gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
  45. gllm_inference/lm_invoker/batch/batch_operations.pyi +127 -0
  46. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +212 -0
  47. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
  48. gllm_inference/lm_invoker/google_lm_invoker.pyi +327 -0
  49. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +239 -0
  50. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +224 -0
  51. gllm_inference/lm_invoker/lm_invoker.pyi +165 -0
  52. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +253 -0
  53. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
  54. gllm_inference/lm_invoker/openai_lm_invoker.pyi +404 -0
  55. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -0
  56. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  57. gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
  58. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  59. gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
  60. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  61. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  62. gllm_inference/lm_invoker/schema/openai.pyi +106 -0
  63. gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
  64. gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
  65. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  66. gllm_inference/lm_invoker/xai_lm_invoker.pyi +253 -0
  67. gllm_inference/model/__init__.pyi +12 -0
  68. gllm_inference/model/em/__init__.pyi +0 -0
  69. gllm_inference/model/em/cohere_em.pyi +17 -0
  70. gllm_inference/model/em/google_em.pyi +16 -0
  71. gllm_inference/model/em/jina_em.pyi +22 -0
  72. gllm_inference/model/em/openai_em.pyi +15 -0
  73. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  74. gllm_inference/model/em/voyage_em.pyi +20 -0
  75. gllm_inference/model/lm/__init__.pyi +0 -0
  76. gllm_inference/model/lm/anthropic_lm.pyi +22 -0
  77. gllm_inference/model/lm/google_lm.pyi +18 -0
  78. gllm_inference/model/lm/openai_lm.pyi +27 -0
  79. gllm_inference/model/lm/xai_lm.pyi +19 -0
  80. gllm_inference/output_parser/__init__.pyi +3 -0
  81. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  82. gllm_inference/output_parser/output_parser.pyi +27 -0
  83. gllm_inference/prompt_builder/__init__.pyi +3 -0
  84. gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
  85. gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
  86. gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
  87. gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
  88. gllm_inference/prompt_builder/prompt_builder.pyi +69 -0
  89. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  90. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  91. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  92. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  93. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  94. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  95. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  96. gllm_inference/realtime_chat/__init__.pyi +3 -0
  97. gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
  98. gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
  99. gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
  100. gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
  101. gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
  102. gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
  103. gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
  104. gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
  105. gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
  106. gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
  107. gllm_inference/request_processor/__init__.pyi +4 -0
  108. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  109. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  110. gllm_inference/schema/__init__.pyi +18 -0
  111. gllm_inference/schema/activity.pyi +64 -0
  112. gllm_inference/schema/attachment.pyi +88 -0
  113. gllm_inference/schema/code_exec_result.pyi +14 -0
  114. gllm_inference/schema/config.pyi +15 -0
  115. gllm_inference/schema/enums.pyi +80 -0
  116. gllm_inference/schema/events.pyi +105 -0
  117. gllm_inference/schema/lm_input.pyi +4 -0
  118. gllm_inference/schema/lm_output.pyi +188 -0
  119. gllm_inference/schema/mcp.pyi +31 -0
  120. gllm_inference/schema/message.pyi +52 -0
  121. gllm_inference/schema/model_id.pyi +176 -0
  122. gllm_inference/schema/reasoning.pyi +15 -0
  123. gllm_inference/schema/token_usage.pyi +75 -0
  124. gllm_inference/schema/tool_call.pyi +14 -0
  125. gllm_inference/schema/tool_result.pyi +11 -0
  126. gllm_inference/schema/type_alias.pyi +11 -0
  127. gllm_inference/utils/__init__.pyi +5 -0
  128. gllm_inference/utils/io_utils.pyi +26 -0
  129. gllm_inference/utils/langchain.pyi +30 -0
  130. gllm_inference/utils/validation.pyi +12 -0
  131. gllm_inference.build/.gitignore +1 -0
  132. gllm_inference.cpython-313-darwin.so +0 -0
  133. gllm_inference.pyi +154 -0
  134. gllm_inference_binary-0.5.55.dist-info/METADATA +138 -0
  135. gllm_inference_binary-0.5.55.dist-info/RECORD +137 -0
  136. gllm_inference_binary-0.5.55.dist-info/WHEEL +5 -0
  137. gllm_inference_binary-0.5.55.dist-info/top_level.txt +1 -0
@@ -0,0 +1,318 @@
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, BatchStatus as BatchStatus, LMInput as LMInput, LMOutput as LMOutput, Message as Message, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, ThinkingEvent as ThinkingEvent, 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
+ BATCH_STATUS_MAP: Incomplete
16
+
17
+ class AnthropicLMInvoker(BaseLMInvoker):
18
+ '''A language model invoker to interact with Anthropic language models.
19
+
20
+ Attributes:
21
+ model_id (str): The model ID of the language model.
22
+ model_provider (str): The provider of the language model.
23
+ model_name (str): The name of the language model.
24
+ client (AsyncAnthropic): The Anthropic client instance.
25
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
26
+ tools (list[Tool]): Tools provided to the model to enable tool calling.
27
+ response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
28
+ structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
29
+ output_analytics (bool): Whether to output the invocation analytics.
30
+ retry_config (RetryConfig): The retry configuration for the language model.
31
+ thinking (bool): Whether to enable thinking. Only allowed for thinking models.
32
+ thinking_budget (int): The tokens allocated for the thinking process. Only allowed for thinking models.
33
+
34
+ Basic usage:
35
+ The `AnthropicLMInvoker` can be used as follows:
36
+ ```python
37
+ lm_invoker = AnthropicLMInvoker(model_name="claude-sonnet-4-20250514")
38
+ result = await lm_invoker.invoke("Hi there!")
39
+ ```
40
+
41
+ Input types:
42
+ The `AnthropicLMInvoker` supports the following input types: text, image, and document.
43
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
44
+
45
+ Usage example:
46
+ ```python
47
+ text = "What animal is in this image?"
48
+ image = Attachment.from_path("path/to/local/image.png")
49
+ result = await lm_invoker.invoke([text, image])
50
+ ```
51
+
52
+ Text output:
53
+ The `AnthropicLMInvoker` generates text outputs by default.
54
+ Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
55
+ via the `texts` (all text outputs) or `text` (first text output) properties.
56
+
57
+ Output example:
58
+ ```python
59
+ LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
60
+ ```
61
+
62
+ Structured output:
63
+ The `AnthropicLMInvoker` can be configured to generate structured outputs.
64
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
65
+
66
+ Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
67
+ via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
68
+
69
+ The schema must either be one of the following:
70
+ 1. A Pydantic BaseModel class
71
+ The structured output will be a Pydantic model.
72
+ 2. A JSON schema dictionary
73
+ JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
74
+ Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
75
+ The structured output will be a dictionary.
76
+
77
+ Usage example:
78
+ ```python
79
+ class Animal(BaseModel):
80
+ name: str
81
+ color: str
82
+
83
+ json_schema = Animal.model_json_schema()
84
+
85
+ lm_invoker = AnthropicLMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
86
+ lm_invoker = AnthropicLMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
87
+ ```
88
+
89
+ Output example:
90
+ ```python
91
+ # Using Pydantic BaseModel class outputs a Pydantic model
92
+ LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
93
+
94
+ # Using JSON schema dictionary outputs a dictionary
95
+ LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
96
+ ```
97
+
98
+ Structured output is not compatible with tool calling or thinking.
99
+ When structured output is enabled, streaming is disabled.
100
+
101
+ Tool calling:
102
+ The `AnthropicLMInvoker` can be configured to call tools to perform certain tasks.
103
+ This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
104
+
105
+ Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
106
+ can be accessed via the `tool_calls` property.
107
+
108
+ Usage example:
109
+ ```python
110
+ lm_invoker = AnthropicLMInvoker(..., tools=[tool_1, tool_2])
111
+ ```
112
+
113
+ Output example:
114
+ ```python
115
+ LMOutput(
116
+ outputs=[
117
+ LMOutputItem(type="text", output="I\'m using tools..."),
118
+ LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
119
+ LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
120
+ ]
121
+ )
122
+ ```
123
+
124
+ Thinking:
125
+ The `AnthropicLMInvoker` can be configured to perform step-by-step thinking process before answering.
126
+ This feature can be enabled by setting the `thinking` parameter to `True`.
127
+
128
+ Thinking outputs are stored in the `outputs` attribute of the `LMOutput` object
129
+ and can be accessed via the `thinkings` property.
130
+
131
+ Usage example:
132
+ ```python
133
+ lm_invoker = AnthropicLMInvoker(..., thinking=True, thinking_budget=1024)
134
+ ```
135
+
136
+ Output example:
137
+ ```python
138
+ LMOutput(
139
+ outputs=[
140
+ LMOutputItem(type="thinking", output=Reasoning(type="thinking", reasoning="I\'m thinking...", ...)),
141
+ LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
142
+ ]
143
+ )
144
+ ```
145
+
146
+ Streaming output example:
147
+ ```python
148
+ {"type": "thinking_start", "value": "", ...}
149
+ {"type": "thinking", "value": "I\'m ", ...}
150
+ {"type": "thinking", "value": "thinking...", ...}
151
+ {"type": "thinking_end", "value": "", ...}
152
+ {"type": "response", "value": "Golden retriever ", ...}
153
+ {"type": "response", "value": "is a good dog breed.", ...}
154
+ ```
155
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
156
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
157
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
158
+
159
+ The amount of tokens allocated for the thinking process can be set via the `thinking_budget` parameter.
160
+ For more information, please refer to the following documentation:
161
+ https://docs.claude.com/en/docs/build-with-claude/extended-thinking#working-with-thinking-budgets.
162
+
163
+ Thinking is only available for certain models, starting from Claude Sonnet 3.7.
164
+
165
+ Analytics tracking:
166
+ The `AnthropicLMInvoker` can be configured to output additional information about the invocation.
167
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
168
+
169
+ When enabled, the following attributes will be stored in the output:
170
+ 1. `token_usage`: The token usage.
171
+ 2. `duration`: The duration in seconds.
172
+ 3. `finish_details`: The details about how the generation finished.
173
+
174
+ Output example:
175
+ ```python
176
+ LMOutput(
177
+ outputs=[...],
178
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
179
+ duration=0.729,
180
+ finish_details={"stop_reason": "end_turn"},
181
+ )
182
+ ```
183
+
184
+ Retry and timeout:
185
+ The `AnthropicLMInvoker` supports retry and timeout configuration.
186
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
187
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
188
+
189
+ Retry config examples:
190
+ ```python
191
+ retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
192
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
193
+ ```
194
+
195
+ Usage example:
196
+ ```python
197
+ lm_invoker = AnthropicLMInvoker(..., retry_config=retry_config)
198
+ ```
199
+
200
+ Batch processing:
201
+ The `AnthropicLMInvoker` supports batch processing, which allows the language model to process multiple
202
+ requests in a single call. Batch processing is supported through the `batch` attribute.
203
+
204
+ Usage example:
205
+ ```python
206
+ requests = {"request_1": "What color is the sky?", "request_2": "What color is the grass?"}
207
+ results = await lm_invoker.batch.invoke(requests)
208
+ ```
209
+
210
+ Output example:
211
+ ```python
212
+ {
213
+ "request_1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
214
+ "request_2": LMOutput(finish_details={"type": "error", "error": {"message": "...", ...}, ...}),
215
+ }
216
+ ```
217
+
218
+ The `AnthropicLMInvoker` also supports the following standalone batch processing operations:
219
+
220
+ 1. Create a batch job:
221
+ ```python
222
+ requests = {"request_1": "What color is the sky?", "request_2": "What color is the grass?"}
223
+ batch_id = await lm_invoker.batch.create(requests)
224
+ ```
225
+
226
+ 2. Get the status of a batch job:
227
+ ```python
228
+ status = await lm_invoker.batch.status(batch_id)
229
+ ```
230
+
231
+ 3. Retrieve the results of a batch job:
232
+ ```python
233
+ results = await lm_invoker.batch.retrieve(batch_id)
234
+ ```
235
+
236
+ Output example:
237
+ ```python
238
+ {
239
+ "request_1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
240
+ "request_2": LMOutput(finish_details={"type": "error", "error": {"message": "...", ...}, ...}),
241
+ }
242
+ ```
243
+
244
+ 4. List the batch jobs:
245
+ ```python
246
+ batch_jobs = await lm_invoker.batch.list()
247
+ ```
248
+
249
+ Output example:
250
+ ```python
251
+ [
252
+ {"id": "batch_123", "status": "finished"},
253
+ {"id": "batch_456", "status": "in_progress"},
254
+ {"id": "batch_789", "status": "canceling"},
255
+ ]
256
+ ```
257
+
258
+ 5. Cancel a batch job:
259
+ ```python
260
+ await lm_invoker.batch.cancel(batch_id)
261
+ ```
262
+ '''
263
+ client: Incomplete
264
+ thinking: Incomplete
265
+ thinking_budget: Incomplete
266
+ 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 = ..., simplify_events: bool = False) -> None:
267
+ """Initializes the AnthropicLmInvoker instance.
268
+
269
+ Args:
270
+ model_name (str): The name of the Anthropic language model.
271
+ api_key (str | None, optional): The Anthropic API key. Defaults to None, in which case the
272
+ `ANTHROPIC_API_KEY` environment variable will be used.
273
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Anthropic client.
274
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
275
+ Defaults to None.
276
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
277
+ Defaults to None, in which case an empty list is used.
278
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
279
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
280
+ dictionary. Defaults to None.
281
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
282
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
283
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
284
+ thinking (bool, optional): Whether to enable thinking. Only allowed for thinking models. Defaults to False.
285
+ thinking_budget (int, optional): The tokens allocated for the thinking process. Must be greater than or
286
+ equal to 1024. Only allowed for thinking models. Defaults to DEFAULT_THINKING_BUDGET.
287
+ simplify_events (bool, optional): Temporary parameter to control the streamed events format.
288
+ When True, uses the simplified events format. When False, uses the legacy events format for
289
+ backward compatibility. Will be removed in v0.6. Defaults to False.
290
+
291
+ Raises:
292
+ ValueError:
293
+ 1. `thinking` is True, but the `thinking_budget` is less than 1024.
294
+ 3. `response_schema` is provided, but `tools` or `thinking` are also provided.
295
+ """
296
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
297
+ """Sets the tools for the Anthropic language model.
298
+
299
+ This method sets the tools for the Anthropic language model. Any existing tools will be replaced.
300
+
301
+ Args:
302
+ tools (list[Tool | LangChainTool]): The list of tools to be used.
303
+
304
+ Raises:
305
+ ValueError: If `response_schema` exists.
306
+ """
307
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
308
+ """Sets the response schema for the Anthropic language model.
309
+
310
+ This method sets the response schema for the Anthropic language model. Any existing response schema will be
311
+ replaced.
312
+
313
+ Args:
314
+ response_schema (ResponseSchema | None): The response schema to be used.
315
+
316
+ Raises:
317
+ ValueError: If `tools` exists.
318
+ """
@@ -0,0 +1,237 @@
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 AZURE_OPENAI_URL_SUFFIX as AZURE_OPENAI_URL_SUFFIX, 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_kwargs (dict[str, Any]): The keyword arguments for the Azure OpenAI client.
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
+ mcp_servers (list[MCPServer]): The list of MCP servers to enable MCP tool calling.
30
+ code_interpreter (bool): Whether to enable the code interpreter. Currently not supported.
31
+ web_search (bool): Whether to enable the web search. Currently not supported.
32
+
33
+ Basic usage:
34
+ The `AzureOpenAILMInvoker` can be used as follows:
35
+ ```python
36
+ lm_invoker = AzureOpenAILMInvoker(
37
+ azure_endpoint="https://<your-azure-openai-endpoint>.openai.azure.com/openai/v1",
38
+ azure_deployment="<your-azure-openai-deployment>",
39
+ )
40
+ result = await lm_invoker.invoke("Hi there!")
41
+ ```
42
+
43
+ Input types:
44
+ The `AzureOpenAILMInvoker` supports the following input types: text, document, and image.
45
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
46
+
47
+ Usage example:
48
+ ```python
49
+ text = "What animal is in this image?"
50
+ image = Attachment.from_path("path/to/local/image.png")
51
+ result = await lm_invoker.invoke([text, image])
52
+ ```
53
+
54
+ Text output:
55
+ The `AzureOpenAILMInvoker` generates text outputs by default.
56
+ Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
57
+ via the `texts` (all text outputs) or `text` (first text output) properties.
58
+
59
+ Output example:
60
+ ```python
61
+ LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
62
+ ```
63
+
64
+ Structured output:
65
+ The `AzureOpenAILMInvoker` can be configured to generate structured outputs.
66
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
67
+
68
+ Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
69
+ via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
70
+
71
+ The schema must either be one of the following:
72
+ 1. A Pydantic BaseModel class
73
+ The structured output will be a Pydantic model.
74
+ 2. A JSON schema dictionary
75
+ JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
76
+ Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
77
+ The structured output will be a dictionary.
78
+
79
+ Usage example:
80
+ ```python
81
+ class Animal(BaseModel):
82
+ name: str
83
+ color: str
84
+
85
+ json_schema = Animal.model_json_schema()
86
+
87
+ lm_invoker = AzureOpenAILMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
88
+ lm_invoker = AzureOpenAILMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
89
+ ```
90
+
91
+ Output example:
92
+ ```python
93
+ # Using Pydantic BaseModel class outputs a Pydantic model
94
+ LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
95
+
96
+ # Using JSON schema dictionary outputs a dictionary
97
+ LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
98
+ ```
99
+
100
+ When structured output is enabled, streaming is disabled.
101
+
102
+ Tool calling:
103
+ The `AzureOpenAILMInvoker` can be configured to call tools to perform certain tasks.
104
+ This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
105
+
106
+ Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
107
+ can be accessed via the `tool_calls` property.
108
+
109
+ Usage example:
110
+ ```python
111
+ lm_invoker = AzureOpenAILMInvoker(..., tools=[tool_1, tool_2])
112
+ ```
113
+
114
+ Output example:
115
+ ```python
116
+ LMOutput(
117
+ outputs=[
118
+ LMOutputItem(type="text", output="I\'m using tools..."),
119
+ LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
120
+ LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
121
+ ]
122
+ )
123
+ ```
124
+
125
+ Reasoning:
126
+ The `AzureOpenAILMInvoker` performs step-by-step reasoning before generating a response when reasoning
127
+ models are used, such as GPT-5 models and o-series models.
128
+
129
+ The reasoning effort can be set via the `reasoning_effort` parameter, which guides the models on the amount
130
+ of reasoning tokens to generate. Available options include `minimal`, `low`, `medium`, and `high`.
131
+
132
+ While the raw reasoning tokens are not available, the summary of the reasoning tokens can still be generated.
133
+ This can be done by passing the desired summary level via the `reasoning_summary` parameter.
134
+ Available options include `auto` and `detailed`.
135
+
136
+ Reasoning summaries are stored in the `outputs` attribute of the `LMOutput` object
137
+ and can be accessed via the `thinkings` property.
138
+
139
+ Usage example:
140
+ ```python
141
+ lm_invoker = AzureOpenAILMInvoker(..., reasoning_effort="high", reasoning_summary="detailed")
142
+ ```
143
+
144
+ Output example:
145
+ ```python
146
+ LMOutput(
147
+ outputs=[
148
+ LMOutputItem(type="thinking", output=Reasoning(type="thinking", reasoning="I\'m thinking...", ...)),
149
+ LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
150
+ ]
151
+ )
152
+ ```
153
+
154
+ Streaming output example:
155
+ ```python
156
+ {"type": "thinking_start", "value": "", ...}
157
+ {"type": "thinking", "value": "I\'m ", ...}
158
+ {"type": "thinking", "value": "thinking...", ...}
159
+ {"type": "thinking_end", "value": "", ...}
160
+ {"type": "response", "value": "Golden retriever ", ...}
161
+ {"type": "response", "value": "is a good dog breed.", ...}
162
+ ```
163
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
164
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
165
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
166
+
167
+ Reasoning summary is not compatible with tool calling.
168
+
169
+ Analytics tracking:
170
+ The `AzureOpenAILMInvoker` can be configured to output additional information about the invocation.
171
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
172
+
173
+ When enabled, the following attributes will be stored in the output:
174
+ 1. `token_usage`: The token usage.
175
+ 2. `duration`: The duration in seconds.
176
+ 3. `finish_details`: The details about how the generation finished.
177
+
178
+ Output example:
179
+ ```python
180
+ LMOutput(
181
+ outputs=[...],
182
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
183
+ duration=0.729,
184
+ finish_details={"stop_reason": "end_turn"},
185
+ )
186
+ ```
187
+
188
+ Retry and timeout:
189
+ The `AzureOpenAILMInvoker` supports retry and timeout configuration.
190
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
191
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
192
+
193
+ Retry config examples:
194
+ ```python
195
+ retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
196
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
197
+ ```
198
+
199
+ Usage example:
200
+ ```python
201
+ lm_invoker = AzureOpenAILMInvoker(..., retry_config=retry_config)
202
+ ```
203
+ '''
204
+ client_kwargs: Incomplete
205
+ def __init__(self, azure_endpoint: str, azure_deployment: str, api_key: str | None = None, api_version: 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, reasoning_effort: ReasoningEffort | None = None, reasoning_summary: ReasoningSummary | None = None, simplify_events: bool = False) -> None:
206
+ """Initializes a new instance of the AzureOpenAILMInvoker class.
207
+
208
+ Args:
209
+ azure_endpoint (str): The endpoint of the Azure OpenAI service.
210
+ azure_deployment (str): The deployment name of the Azure OpenAI service.
211
+ api_key (str | None, optional): The API key for authenticating with Azure OpenAI. Defaults to None, in
212
+ which case the `AZURE_OPENAI_API_KEY` environment variable will be used.
213
+ api_version (str | None, optional): Deprecated parameter to be removed in v0.6. Defaults to None.
214
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
215
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
216
+ Defaults to None.
217
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
218
+ Defaults to None.
219
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
220
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
221
+ dictionary. Defaults to None.
222
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
223
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
224
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
225
+ reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
226
+ for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
227
+ reasoning_summary (ReasoningSummary | None, optional): The reasoning summary level for reasoning models.
228
+ Not allowed for non-reasoning models. If None, no summary will be generated. Defaults to None.
229
+ simplify_events (bool, optional): Temporary parameter to control the streamed events format.
230
+ When True, uses the simplified events format. When False, uses the legacy events format for
231
+ backward compatibility. Will be removed in v0.6. Defaults to False.
232
+
233
+ Raises:
234
+ ValueError:
235
+ 1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
236
+ 2. `reasoning_summary` is provided, but is not a valid ReasoningSummary.
237
+ """
@@ -0,0 +1,3 @@
1
+ from gllm_inference.lm_invoker.batch.batch_operations import BatchOperations as BatchOperations
2
+
3
+ __all__ = ['BatchOperations']