gllm-inference-binary 0.5.40__cp311-cp311-win_amd64.whl → 0.5.66__cp311-cp311-win_amd64.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.
Files changed (57) hide show
  1. gllm_inference/builder/_build_invoker.pyi +28 -0
  2. gllm_inference/builder/build_em_invoker.pyi +12 -16
  3. gllm_inference/builder/build_lm_invoker.pyi +65 -17
  4. gllm_inference/constants.pyi +3 -2
  5. gllm_inference/em_invoker/__init__.pyi +3 -1
  6. gllm_inference/em_invoker/bedrock_em_invoker.pyi +16 -4
  7. gllm_inference/em_invoker/cohere_em_invoker.pyi +127 -0
  8. gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
  9. gllm_inference/em_invoker/schema/bedrock.pyi +7 -0
  10. gllm_inference/em_invoker/schema/cohere.pyi +20 -0
  11. gllm_inference/em_invoker/schema/jina.pyi +29 -0
  12. gllm_inference/exceptions/provider_error_map.pyi +1 -0
  13. gllm_inference/lm_invoker/__init__.pyi +3 -1
  14. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +95 -109
  15. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +92 -109
  16. gllm_inference/lm_invoker/batch/batch_operations.pyi +2 -1
  17. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +52 -65
  18. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +36 -36
  19. gllm_inference/lm_invoker/google_lm_invoker.pyi +195 -110
  20. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +52 -64
  21. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +86 -106
  22. gllm_inference/lm_invoker/lm_invoker.pyi +20 -1
  23. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +87 -107
  24. gllm_inference/lm_invoker/openai_lm_invoker.pyi +237 -186
  25. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -0
  26. gllm_inference/lm_invoker/schema/google.pyi +12 -0
  27. gllm_inference/lm_invoker/schema/openai.pyi +22 -0
  28. gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
  29. gllm_inference/lm_invoker/sea_lion_lm_invoker.pyi +48 -0
  30. gllm_inference/lm_invoker/xai_lm_invoker.pyi +94 -131
  31. gllm_inference/model/__init__.pyi +5 -1
  32. gllm_inference/model/em/cohere_em.pyi +17 -0
  33. gllm_inference/model/em/jina_em.pyi +22 -0
  34. gllm_inference/model/lm/anthropic_lm.pyi +2 -0
  35. gllm_inference/model/lm/google_lm.pyi +1 -0
  36. gllm_inference/model/lm/sea_lion_lm.pyi +16 -0
  37. gllm_inference/model/lm/xai_lm.pyi +19 -0
  38. gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
  39. gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
  40. gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
  41. gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
  42. gllm_inference/prompt_builder/prompt_builder.pyi +23 -6
  43. gllm_inference/schema/__init__.pyi +4 -3
  44. gllm_inference/schema/activity.pyi +13 -11
  45. gllm_inference/schema/attachment.pyi +20 -6
  46. gllm_inference/schema/enums.pyi +30 -1
  47. gllm_inference/schema/events.pyi +69 -73
  48. gllm_inference/schema/formatter.pyi +31 -0
  49. gllm_inference/schema/lm_output.pyi +245 -23
  50. gllm_inference/schema/model_id.pyi +27 -3
  51. gllm_inference/utils/validation.pyi +3 -0
  52. gllm_inference.cp311-win_amd64.pyd +0 -0
  53. gllm_inference.pyi +23 -13
  54. {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/METADATA +10 -6
  55. {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/RECORD +57 -40
  56. {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/WHEEL +0 -0
  57. {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/top_level.txt +0 -0
@@ -1,17 +1,23 @@
1
1
  from _typeshed import Incomplete
2
2
  from gllm_core.event import EventEmitter as EventEmitter
3
3
  from gllm_core.schema.tool import Tool as Tool
4
- from gllm_core.utils.retry import RetryConfig as RetryConfig
4
+ from gllm_core.utils import RetryConfig as RetryConfig
5
5
  from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES, OPENAI_DEFAULT_URL as OPENAI_DEFAULT_URL
6
6
  from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
7
7
  from gllm_inference.lm_invoker.schema.openai import InputType as InputType, Key as Key, OutputType as OutputType, ReasoningEffort as ReasoningEffort, ReasoningSummary as ReasoningSummary
8
- from gllm_inference.schema import ActivityEvent as ActivityEvent, Attachment as Attachment, AttachmentType as AttachmentType, CodeEvent as CodeEvent, CodeExecResult as CodeExecResult, LMOutput as LMOutput, MCPCall as MCPCall, MCPCallActivity as MCPCallActivity, MCPListToolsActivity as MCPListToolsActivity, MCPServer as MCPServer, Message as Message, MessageRole as MessageRole, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, ThinkingEvent as ThinkingEvent, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult, WebSearchActivity as WebSearchActivity
9
- from gllm_inference.utils import validate_string_enum as validate_string_enum
8
+ from gllm_inference.schema import ActivityEvent as ActivityEvent, Attachment as Attachment, AttachmentType as AttachmentType, BatchStatus as BatchStatus, CodeEvent as CodeEvent, CodeExecResult as CodeExecResult, LMOutput as LMOutput, MCPCall as MCPCall, MCPCallActivity as MCPCallActivity, MCPListToolsActivity as MCPListToolsActivity, MCPServer as MCPServer, Message as Message, MessageContent as MessageContent, MessageRole as MessageRole, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, ThinkingEvent as ThinkingEvent, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult, WebSearchActivity as WebSearchActivity
10
9
  from langchain_core.tools import Tool as LangChainTool
10
+ from openai import AsyncStream as AsyncStream
11
+ from openai.types.responses import Response as Response, ResponseFunctionWebSearch as ResponseFunctionWebSearch, ResponseOutputItem as ResponseOutputItem
12
+ from openai.types.responses.response_output_item import McpCall as McpCall, McpListTools as McpListTools
11
13
  from typing import Any
12
14
 
15
+ BATCH_STATUS_MAP: Incomplete
16
+ OPENAI_RESPONSES_API_ENDPOINT: str
17
+ DEFAULT_BATCH_COMPLETION_WINDOW: str
13
18
  SUPPORTED_ATTACHMENTS: Incomplete
14
- STREAM_DATA_TRANSITION_TYPE_MAP: Incomplete
19
+ STREAM_DATA_START_TYPE_MAP: Incomplete
20
+ STREAM_DATA_END_TYPE_MAP: Incomplete
15
21
  STREAM_DATA_CONTENT_TYPE_MAP: Incomplete
16
22
 
17
23
  class OpenAILMInvoker(BaseLMInvoker):
@@ -36,6 +42,7 @@ class OpenAILMInvoker(BaseLMInvoker):
36
42
  for non-reasoning models. If None, the model will perform medium reasoning effort.
37
43
  reasoning_summary (ReasoningSummary | None): The reasoning summary level for reasoning models. Not allowed
38
44
  for non-reasoning models. If None, no summary will be generated.
45
+ image_generation (bool): Whether to enable image generation.
39
46
  mcp_servers (list[MCPServer]): The list of MCP servers to enable MCP tool calling.
40
47
  code_interpreter (bool): Whether to enable the code interpreter.
41
48
  web_search (bool): Whether to enable the web search.
@@ -75,188 +82,135 @@ class OpenAILMInvoker(BaseLMInvoker):
75
82
  result = await lm_invoker.invoke([text, image])
76
83
  ```
77
84
 
78
- Tool calling:
79
- Tool calling is a feature that allows the language model to call tools to perform tasks.
80
- Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
81
- When tools are provided and the model decides to call a tool, the tool calls are stored in the
82
- `tool_calls` attribute in the output.
83
-
84
- Usage example:
85
- ```python
86
- lm_invoker = OpenAILMInvoker(..., tools=[tool_1, tool_2])
87
- ```
85
+ Text output:
86
+ The `OpenAILMInvoker` generates text outputs by default.
87
+ Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
88
+ via the `texts` (all text outputs) or `text` (first text output) properties.
88
89
 
89
90
  Output example:
90
91
  ```python
91
- LMOutput(
92
- response="Let me call the tools...",
93
- tool_calls=[
94
- ToolCall(id="123", name="tool_1", args={"key": "value"}),
95
- ToolCall(id="456", name="tool_2", args={"key": "value"}),
96
- ]
97
- )
92
+ LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
98
93
  ```
99
94
 
100
95
  Structured output:
101
- Structured output is a feature that allows the language model to output a structured response.
96
+ The `OpenAILMInvoker` can be configured to generate structured outputs.
102
97
  This feature can be enabled by providing a schema to the `response_schema` parameter.
103
98
 
104
- The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
105
- If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
106
- For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
99
+ Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
100
+ via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
107
101
 
108
- The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
109
- invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
110
-
111
- When enabled, the structured output is stored in the `structured_output` attribute in the output.
112
- 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
113
- 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
114
-
115
- # Example 1: Using a JSON schema dictionary
116
- Usage example:
117
- ```python
118
- schema = {
119
- "title": "Animal",
120
- "description": "A description of an animal.",
121
- "properties": {
122
- "color": {"title": "Color", "type": "string"},
123
- "name": {"title": "Name", "type": "string"},
124
- },
125
- "required": ["name", "color"],
126
- "type": "object",
127
- }
128
- lm_invoker = OpenAILMInvoker(..., response_schema=schema)
129
- ```
130
- Output example:
131
- ```python
132
- LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
133
- ```
102
+ The schema must either be one of the following:
103
+ 1. A Pydantic BaseModel class
104
+ The structured output will be a Pydantic model.
105
+ 2. A JSON schema dictionary
106
+ JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
107
+ Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
108
+ The structured output will be a dictionary.
134
109
 
135
- # Example 2: Using a Pydantic BaseModel class
136
110
  Usage example:
137
111
  ```python
138
112
  class Animal(BaseModel):
139
113
  name: str
140
114
  color: str
141
115
 
142
- lm_invoker = OpenAILMInvoker(..., response_schema=Animal)
116
+ json_schema = Animal.model_json_schema()
117
+
118
+ lm_invoker = OpenAILMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
119
+ lm_invoker = OpenAILMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
143
120
  ```
121
+
144
122
  Output example:
145
123
  ```python
146
- LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
124
+ # Using Pydantic BaseModel class outputs a Pydantic model
125
+ LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
126
+
127
+ # Using JSON schema dictionary outputs a dictionary
128
+ LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
147
129
  ```
148
130
 
149
- Analytics tracking:
150
- Analytics tracking is a feature that allows the module to output additional information about the invocation.
151
- This feature can be enabled by setting the `output_analytics` parameter to `True`.
152
- When enabled, the following attributes will be stored in the output:
153
- 1. `token_usage`: The token usage.
154
- 2. `duration`: The duration in seconds.
155
- 3. `finish_details`: The details about how the generation finished.
131
+ When structured output is enabled, streaming is disabled.
132
+
133
+ Image generation:
134
+ The `OpenAILMInvoker` can be configured to generate images.
135
+ This feature can be enabled by setting the `image_generation` parameter to `True`.
136
+
137
+ Image outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
138
+ via the `attachments` property.
139
+
140
+ Usage example:
141
+ ```python
142
+ lm_invoker = OpenAILMInvoker(..., image_generation=True)
143
+ result = await lm_invoker.invoke("Create a picture...")
144
+ result.attachments[0].write_to_file("path/to/local/image.png")
145
+ ```
156
146
 
157
147
  Output example:
158
148
  ```python
159
149
  LMOutput(
160
- response="Golden retriever is a good dog breed.",
161
- token_usage=TokenUsage(
162
- input_tokens=1500,
163
- output_tokens=200,
164
- input_token_details=InputTokenDetails(cached_tokens=1200, uncached_tokens=300),
165
- output_token_details=OutputTokenDetails(reasoning_tokens=180, response_tokens=20),
166
- ),
167
- duration=0.729,
168
- finish_details={"status": "completed", "incomplete_details": {"reason": None}},
150
+ outputs=[
151
+ LMOutputItem(
152
+ type="attachment",
153
+ output=Attachment(filename="image.png", mime_type="image/png", data=b"..."),
154
+ ),
155
+ ],
169
156
  )
170
157
  ```
171
158
 
172
- Retry and timeout:
173
- The `OpenAILMInvoker` supports retry and timeout configuration.
174
- By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
175
- They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
159
+ When image generation is enabled, streaming is disabled.
160
+ Image generation is only available for certain models.
176
161
 
177
- Retry config examples:
178
- ```python
179
- retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
180
- retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
181
- retry_config = RetryConfig(max_retries=5, timeout=None) # 5 max retries, no timeout
182
- retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
183
- ```
162
+ Tool calling:
163
+ The `OpenAILMInvoker` can be configured to call tools to perform certain tasks.
164
+ This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
165
+
166
+ Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
167
+ can be accessed via the `tool_calls` property.
184
168
 
185
169
  Usage example:
186
170
  ```python
187
- lm_invoker = OpenAILMInvoker(..., retry_config=retry_config)
171
+ lm_invoker = OpenAILMInvoker(..., tools=[tool_1, tool_2])
188
172
  ```
189
173
 
190
- Reasoning:
191
- OpenAI\'s GPT-5 models and o-series models are classified as reasoning models. Reasoning models think before
192
- they answer, producing a long internal chain of thought before responding to the user. Reasoning models
193
- excel in complex problem solving, coding, scientific reasoning, and multi-step planning for agentic workflows.
194
-
195
- The reasoning effort of reasoning models can be set via the `reasoning_effort` parameter. This parameter
196
- will guide the models on how many reasoning tokens it should generate before creating a response.
197
- Available options include:
198
- 1. "minimal": Favors the least amount of reasoning, only supported for GPT-5 models onwards.
199
- 2. "low": Favors speed and economical token usage.
200
- 3. "medium": Favors a balance between speed and reasoning accuracy.
201
- 4. "high": Favors more complete reasoning at the cost of more tokens generated and slower responses.
202
- When not set, the reasoning effort will be equivalent to `medium` by default.
203
-
204
- OpenAI doesn\'t expose the raw reasoning tokens. However, the summary of the reasoning tokens can still be
205
- generated. The summary level can be set via the `reasoning_summary` parameter. Available options include:
206
- 1. "auto": The model decides the summary level automatically.
207
- 2. "detailed": The model will generate a detailed summary of the reasoning tokens.
208
- Reasoning summary is not compatible with tool calling.
209
- When enabled, the reasoning summary will be stored in the `reasoning` attribute in the output.
210
-
211
174
  Output example:
212
175
  ```python
213
176
  LMOutput(
214
- response="Golden retriever is a good dog breed.",
215
- reasoning=[Reasoning(id="x", reasoning="Let me think about it...")],
177
+ outputs=[
178
+ LMOutputItem(type="text", output="I\'m using tools..."),
179
+ LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
180
+ LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
181
+ ]
216
182
  )
217
183
  ```
218
184
 
219
- Streaming output example:
220
- ```python
221
- {"type": "thinking_start", "value": ""}\', ...}
222
- {"type": "thinking", "value": "Let me think "}\', ...}
223
- {"type": "thinking", "value": "about it..."}\', ...}
224
- {"type": "thinking_end", "value": ""}\', ...}
225
- {"type": "response", "value": "Golden retriever ", ...}
226
- {"type": "response", "value": "is a good dog breed.", ...}
227
- ```
228
- Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
229
- To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
230
- LM invoker initialization. The legacy event format support will be removed in v0.6.
231
-
232
- Setting reasoning-related parameters for non-reasoning models will raise an error.
233
-
234
185
  MCP tool calling:
235
- The `OpenAILMInvoker` supports MCP tool calling. This feature can be enabled by providing a list of
236
- MCP servers to the `mcp_servers` parameter. When MCP servers are provided and the model decides to call
237
- an MCP tool, the MCP calls are stored in the `mcp_calls` attribute in the output.
186
+ The `OpenAILMInvoker` can be configured to call MCP tools to perform certain tasks.
187
+ This feature can be enabled by providing a list of MCP servers to the `mcp_servers` parameter.
188
+
189
+ MCP calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
190
+ can be accessed via the `mcp_calls` property.
238
191
 
239
192
  Usage example:
240
193
  ```python
241
194
  from gllm_inference.schema import MCPServer
242
- mcp_server_1 = MCPServer(
243
- url="https://mcp_server_1.com",
244
- name="mcp_server_1",
245
- )
195
+
196
+ mcp_server_1 = MCPServer(url="https://mcp_server_1.com", name="mcp_server_1")
246
197
  lm_invoker = OpenAILMInvoker(..., mcp_servers=[mcp_server_1])
247
198
  ```
248
199
 
249
200
  Output example:
250
201
  ```python
251
202
  LMOutput(
252
- response="The result is 10.",
253
- mcp_calls=[
254
- MCPCall(
255
- id="123",
256
- server_name="mcp_server_1",
257
- tool_name="mcp_tool_1",
258
- args={"key": "value"},
259
- output="The result is 10.",
203
+ outputs=[
204
+ LMOutputItem(type="text", output="I\'m using MCP tools..."),
205
+ LMOutputItem(
206
+ type="mcp_call",
207
+ output=MCPCall(
208
+ id="123",
209
+ server_name="mcp_server_1",
210
+ tool_name="mcp_tool_1",
211
+ args={"key": "value"},
212
+ output="The result is 10."
213
+ ),
260
214
  ),
261
215
  ],
262
216
  )
@@ -273,39 +227,83 @@ class OpenAILMInvoker(BaseLMInvoker):
273
227
  To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
274
228
  LM invoker initialization. The legacy event format support will be removed in v0.6.
275
229
 
276
- Code interpreter:
277
- The code interpreter is a feature that allows the language model to write and run Python code in a
278
- sandboxed environment to solve complex problems in domains like data analysis, coding, and math.
279
- This feature can be enabled by setting the `code_interpreter` parameter to `True`.
230
+ Reasoning:
231
+ The `OpenAILMInvoker` performs step-by-step reasoning before generating a response when reasoning
232
+ models are used, such as GPT-5 models and o-series models.
233
+
234
+ The reasoning effort can be set via the `reasoning_effort` parameter, which guides the models on the amount
235
+ of reasoning tokens to generate. Available options include `minimal`, `low`, `medium`, and `high`.
236
+
237
+ While the raw reasoning tokens are not available, the summary of the reasoning tokens can still be generated.
238
+ This can be done by passing the desired summary level via the `reasoning_summary` parameter.
239
+ Available options include `auto` and `detailed`.
240
+
241
+ Reasoning summaries are stored in the `outputs` attribute of the `LMOutput` object
242
+ and can be accessed via the `thinkings` property.
280
243
 
281
244
  Usage example:
282
245
  ```python
283
- lm_invoker = OpenAILMInvoker(..., code_interpreter=True)
246
+ lm_invoker = OpenAILMInvoker(..., reasoning_effort="high", reasoning_summary="detailed")
284
247
  ```
285
248
 
249
+ Output example:
250
+ ```python
251
+ LMOutput(
252
+ outputs=[
253
+ LMOutputItem(type="thinking", output=Reasoning(type="thinking", reasoning="I\'m thinking...", ...)),
254
+ LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
255
+ ]
256
+ )
257
+ ```
258
+
259
+ Streaming output example:
260
+ ```python
261
+ {"type": "thinking_start", "value": "", ...}
262
+ {"type": "thinking", "value": "I\'m ", ...}
263
+ {"type": "thinking", "value": "thinking...", ...}
264
+ {"type": "thinking_end", "value": "", ...}
265
+ {"type": "response", "value": "Golden retriever ", ...}
266
+ {"type": "response", "value": "is a good dog breed.", ...}
267
+ ```
268
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
269
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
270
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
271
+
272
+ Reasoning summary is not compatible with tool calling.
273
+
274
+ Code interpreter:
275
+ The `OpenAILMInvoker` can be configured to write and run Python code in a sandboxed environment.
276
+ This is useful for solving complex problems in domains like data analysis, coding, and math.
277
+ This feature can be enabled by setting the `code_interpreter` parameter to `True`.
278
+
286
279
  When code interpreter is enabled, it is highly recommended to instruct the model to use the "python tool"
287
280
  in the system message, as "python tool" is the term recognized by the model to refer to the code interpreter.
288
281
 
289
- Messages example:
282
+ Code execution results are stored in the `outputs` attribute of the `LMOutput` object and
283
+ can be accessed via the `code_exec_results` property.
284
+
285
+ Usage example:
290
286
  ```python
287
+ lm_invoker = OpenAILMInvoker(..., code_interpreter=True)
291
288
  messages = [
292
289
  Message.system("You are a data analyst. Use the python tool to generate a file."]),
293
290
  Message.user("Show an histogram of the following data: [1, 2, 1, 4, 1, 2, 4, 2, 3, 1]"),
294
291
  ]
292
+ result = await lm_invoker.invoke(messages)
295
293
  ```
296
294
 
297
- When code interpreter is enabled, the code execution results are stored in the `code_exec_results`
298
- attribute in the output.
299
-
300
295
  Output example:
301
296
  ```python
302
297
  LMOutput(
303
- response="The histogram is attached.",
304
- code_exec_results=[
305
- CodeExecResult(
306
- id="123",
307
- code="import matplotlib.pyplot as plt...",
308
- output=[Attachment(data=b"...", mime_type="image/png")],
298
+ outputs=[
299
+ LMOutputItem(type="text", output="The histogram is attached."),
300
+ LMOutputItem(
301
+ type="code_exec_result",
302
+ output=CodeExecResult(
303
+ id="123",
304
+ code="import matplotlib.pyplot as plt...",
305
+ output=[Attachment(data=b"...", mime_type="image/png")],
306
+ ),
309
307
  ),
310
308
  ],
311
309
  )
@@ -324,35 +322,24 @@ class OpenAILMInvoker(BaseLMInvoker):
324
322
  To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
325
323
  LM invoker initialization. The legacy event format support will be removed in v0.6.
326
324
 
327
- Web search:
328
- The web search is a feature that allows the language model to search the web for relevant information.
325
+ Web Search:
326
+ The `OpenAILMInvoker` can be configured to search the web for relevant information.
329
327
  This feature can be enabled by setting the `web_search` parameter to `True`.
330
328
 
329
+ Web search citations are stored in the `outputs` attribute of the `LMOutput` object and
330
+ can be accessed via the `citations` property.
331
+
331
332
  Usage example:
332
333
  ```python
333
334
  lm_invoker = OpenAILMInvoker(..., web_search=True)
334
335
  ```
335
336
 
336
- When web search is enabled, the language model will search the web for relevant information and may cite the
337
- relevant sources. The citations will be stored as `Chunk` objects in the `citations` attribute in the output.
338
- The content of the `Chunk` object is the type of the citation, e.g. "url_citation".
339
-
340
337
  Output example:
341
338
  ```python
342
339
  LMOutput(
343
- response="The winner of the match is team A ([Example title](https://www.example.com)).",
344
- citations=[
345
- Chunk(
346
- id="123",
347
- content="url_citation",
348
- metadata={
349
- "start_index": 164,
350
- "end_index": 275,
351
- "title": "Example title",
352
- "url": "https://www.example.com",
353
- "type": "url_citation",
354
- },
355
- ),
340
+ outputs=[
341
+ LMOutputItem(type="citation", output=Chunk(id="123", content="...", metadata={...}, score=None)),
342
+ LMOutputItem(type="text", output="According to recent reports... ([Source](https://example.com))."),
356
343
  ],
357
344
  )
358
345
  ```
@@ -360,30 +347,93 @@ class OpenAILMInvoker(BaseLMInvoker):
360
347
  Streaming output example:
361
348
  ```python
362
349
  {"type": "activity", "value": {"query": "search query"}, ...}
363
- {"type": "response", "value": "The winner of the match ", ...}
364
- {"type": "response", "value": "is team A ([Example title](https://www.example.com)).", ...}
350
+ {"type": "response", "value": "According to recent ", ...}
351
+ {"type": "response", "value": "reports... ([Source](https://example.com)).", ...}
365
352
  ```
366
353
  Note: By default, the activity token will be streamed with the legacy `EventType.DATA` event type.
367
354
  To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
368
355
  LM invoker initialization. The legacy event format support will be removed in v0.6.
369
356
 
370
- Output types:
371
- The output of the `OpenAILMInvoker` can either be:
372
- 1. `str`: A text response.
373
- 2. `LMOutput`: A Pydantic model that may contain the following attributes:
374
- 2.1. response (str)
375
- 2.2. tool_calls (list[ToolCall])
376
- 2.3. structured_output (dict[str, Any] | BaseModel | None)
377
- 2.4. token_usage (TokenUsage | None)
378
- 2.5. duration (float | None)
379
- 2.6. finish_details (dict[str, Any])
380
- 2.7. reasoning (list[Reasoning])
381
- 2.8. citations (list[Chunk])
382
- 2.9. code_exec_results (list[CodeExecResult])
383
- 2.10. mcp_calls (list[MCPCall])
357
+ Analytics tracking:
358
+ The `OpenAILMInvoker` can be configured to output additional information about the invocation.
359
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
360
+
361
+ When enabled, the following attributes will be stored in the output:
362
+ 1. `token_usage`: The token usage.
363
+ 2. `duration`: The duration in seconds.
364
+ 3. `finish_details`: The details about how the generation finished.
365
+
366
+ Output example:
367
+ ```python
368
+ LMOutput(
369
+ outputs=[...],
370
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
371
+ duration=0.729,
372
+ finish_details={"stop_reason": "end_turn"},
373
+ )
374
+ ```
375
+
376
+ Retry and timeout:
377
+ The `OpenAILMInvoker` supports retry and timeout configuration.
378
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
379
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
380
+
381
+ Retry config examples:
382
+ ```python
383
+ retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
384
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
385
+ ```
386
+
387
+ Usage example:
388
+ ```python
389
+ lm_invoker = OpenAILMInvoker(..., retry_config=retry_config)
390
+ ```
391
+
392
+ Batch processing:
393
+ The `OpenAILMInvoker` supports batch processing, which allows the language model to process multiple
394
+ requests in a single call. The batch processing operations include:
395
+
396
+ 1. Create a batch job:
397
+ ```python
398
+ requests = {"request_1": "What color is the sky?", "request_2": "What color is the grass?"}
399
+ batch_id = await lm_invoker.batch.create(requests)
400
+ ```
401
+ 2. Get the status of a batch job:
402
+ ```python
403
+ status = await lm_invoker.batch.status(batch_id)
404
+ ```
405
+ 3. Retrieve the results of a batch job:
406
+ Results are keyed by the request indices provided during batch creation.
407
+
408
+ ```python
409
+ results = await lm_invoker.batch.retrieve(batch_id)
410
+ ```
411
+ Output example:
412
+ ```python
413
+ {
414
+ "request_1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
415
+ "request_2": LMOutput(finish_details={"type": "error", "error": {"message": "...", ...}, ...}),
416
+ }
417
+ ```
418
+ 4. List the batch jobs:
419
+ ```python
420
+ batch_jobs = await lm_invoker.batch.list()
421
+ ```
422
+ Output example:
423
+ ```python
424
+ [
425
+ {"id": "batch_123", "status": "finished"},
426
+ {"id": "batch_456", "status": "in_progress"},
427
+ {"id": "batch_789", "status": "canceling"},
428
+ ]
429
+ ```
430
+ 5. Cancel a batch job:
431
+ ```python
432
+ await lm_invoker.batch.cancel(batch_id)
433
+ ```
384
434
  '''
385
435
  client_kwargs: Incomplete
386
- def __init__(self, model_name: str, api_key: str | None = None, base_url: 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, mcp_servers: list[MCPServer] | None = None, code_interpreter: bool = False, web_search: bool = False, simplify_events: bool = False) -> None:
436
+ def __init__(self, model_name: str, api_key: str | None = None, base_url: 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, image_generation: bool = False, mcp_servers: list[MCPServer] | None = None, code_interpreter: bool = False, web_search: bool = False, simplify_events: bool = False) -> None:
387
437
  '''Initializes a new instance of the OpenAILMInvoker class.
388
438
 
389
439
  Args:
@@ -408,6 +458,7 @@ class OpenAILMInvoker(BaseLMInvoker):
408
458
  for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
409
459
  reasoning_summary (ReasoningSummary | None, optional): The reasoning summary level for reasoning models.
410
460
  Not allowed for non-reasoning models. If None, no summary will be generated. Defaults to None.
461
+ image_generation (bool, optional): Whether to enable image generation. Defaults to False.
411
462
  mcp_servers (list[MCPServer] | None, optional): The MCP servers containing tools to be accessed by the
412
463
  language model. Defaults to None.
413
464
  code_interpreter (bool, optional): Whether to enable the code interpreter. Defaults to False.