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.
- gllm_inference/builder/_build_invoker.pyi +28 -0
- gllm_inference/builder/build_em_invoker.pyi +12 -16
- gllm_inference/builder/build_lm_invoker.pyi +65 -17
- gllm_inference/constants.pyi +3 -2
- gllm_inference/em_invoker/__init__.pyi +3 -1
- gllm_inference/em_invoker/bedrock_em_invoker.pyi +16 -4
- gllm_inference/em_invoker/cohere_em_invoker.pyi +127 -0
- gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
- gllm_inference/em_invoker/schema/bedrock.pyi +7 -0
- gllm_inference/em_invoker/schema/cohere.pyi +20 -0
- gllm_inference/em_invoker/schema/jina.pyi +29 -0
- gllm_inference/exceptions/provider_error_map.pyi +1 -0
- gllm_inference/lm_invoker/__init__.pyi +3 -1
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +95 -109
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +92 -109
- gllm_inference/lm_invoker/batch/batch_operations.pyi +2 -1
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +52 -65
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +36 -36
- gllm_inference/lm_invoker/google_lm_invoker.pyi +195 -110
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +52 -64
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +86 -106
- gllm_inference/lm_invoker/lm_invoker.pyi +20 -1
- gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +87 -107
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +237 -186
- gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -0
- gllm_inference/lm_invoker/schema/google.pyi +12 -0
- gllm_inference/lm_invoker/schema/openai.pyi +22 -0
- gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
- gllm_inference/lm_invoker/sea_lion_lm_invoker.pyi +48 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +94 -131
- gllm_inference/model/__init__.pyi +5 -1
- gllm_inference/model/em/cohere_em.pyi +17 -0
- gllm_inference/model/em/jina_em.pyi +22 -0
- gllm_inference/model/lm/anthropic_lm.pyi +2 -0
- gllm_inference/model/lm/google_lm.pyi +1 -0
- gllm_inference/model/lm/sea_lion_lm.pyi +16 -0
- gllm_inference/model/lm/xai_lm.pyi +19 -0
- gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
- gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
- gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
- gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
- gllm_inference/prompt_builder/prompt_builder.pyi +23 -6
- gllm_inference/schema/__init__.pyi +4 -3
- gllm_inference/schema/activity.pyi +13 -11
- gllm_inference/schema/attachment.pyi +20 -6
- gllm_inference/schema/enums.pyi +30 -1
- gllm_inference/schema/events.pyi +69 -73
- gllm_inference/schema/formatter.pyi +31 -0
- gllm_inference/schema/lm_output.pyi +245 -23
- gllm_inference/schema/model_id.pyi +27 -3
- gllm_inference/utils/validation.pyi +3 -0
- gllm_inference.cp311-win_amd64.pyd +0 -0
- gllm_inference.pyi +23 -13
- {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/METADATA +10 -6
- {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/RECORD +57 -40
- {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/WHEEL +0 -0
- {gllm_inference_binary-0.5.40.dist-info → gllm_inference_binary-0.5.66.dist-info}/top_level.txt +0 -0
|
@@ -6,8 +6,9 @@ from gllm_inference.constants import GOOGLE_SCOPES as GOOGLE_SCOPES, SECONDS_TO_
|
|
|
6
6
|
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, convert_http_status_to_base_invoker_error as convert_http_status_to_base_invoker_error
|
|
7
7
|
from gllm_inference.exceptions.provider_error_map import GOOGLE_ERROR_MAPPING as GOOGLE_ERROR_MAPPING
|
|
8
8
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
9
|
-
from gllm_inference.lm_invoker.schema.google import InputType as InputType, Key as Key
|
|
10
|
-
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, LMOutput as LMOutput, 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
|
|
9
|
+
from gllm_inference.lm_invoker.schema.google import InputType as InputType, JobState as JobState, Key as Key
|
|
10
|
+
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, BatchStatus as BatchStatus, LMInput as LMInput, LMOutput as LMOutput, 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
|
|
11
|
+
from google.genai.types import GenerateContentResponse as GenerateContentResponse
|
|
11
12
|
from langchain_core.tools import Tool as LangChainTool
|
|
12
13
|
from typing import Any
|
|
13
14
|
|
|
@@ -15,7 +16,12 @@ SUPPORTED_ATTACHMENTS: Incomplete
|
|
|
15
16
|
DEFAULT_THINKING_BUDGET: int
|
|
16
17
|
REQUIRE_THINKING_MODEL_PREFIX: Incomplete
|
|
17
18
|
IMAGE_GENERATION_MODELS: Incomplete
|
|
18
|
-
|
|
19
|
+
BATCH_STATUS_MAP: Incomplete
|
|
20
|
+
|
|
21
|
+
class URLPattern:
|
|
22
|
+
"""Defines specific Google related URL patterns."""
|
|
23
|
+
GOOGLE_FILE: Incomplete
|
|
24
|
+
YOUTUBE: Incomplete
|
|
19
25
|
|
|
20
26
|
class GoogleLMInvoker(BaseLMInvoker):
|
|
21
27
|
'''A language model invoker to interact with Google language models.
|
|
@@ -31,10 +37,10 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
31
37
|
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
32
38
|
output_analytics (bool): Whether to output the invocation analytics.
|
|
33
39
|
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
34
|
-
generate_image (bool): Whether to generate image. Only allowed for image generation models.
|
|
35
40
|
thinking (bool): Whether to enable thinking. Only allowed for thinking models.
|
|
36
41
|
thinking_budget (int): The tokens allowed for thinking process. Only allowed for thinking models.
|
|
37
42
|
If set to -1, the model will control the budget automatically.
|
|
43
|
+
image_generation (bool): Whether to generate image. Only allowed for image generation models.
|
|
38
44
|
|
|
39
45
|
Basic usage:
|
|
40
46
|
The `GoogleLMInvoker` can be used as follows:
|
|
@@ -82,10 +88,61 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
82
88
|
result = await lm_invoker.invoke([text, image])
|
|
83
89
|
```
|
|
84
90
|
|
|
91
|
+
Text output:
|
|
92
|
+
The `GoogleLMInvoker` generates text outputs by default.
|
|
93
|
+
Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
94
|
+
via the `texts` (all text outputs) or `text` (first text output) properties.
|
|
95
|
+
|
|
96
|
+
Output example:
|
|
97
|
+
```python
|
|
98
|
+
LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Structured output:
|
|
102
|
+
The `GoogleLMInvoker` can be configured to generate structured outputs.
|
|
103
|
+
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
104
|
+
|
|
105
|
+
Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
106
|
+
via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
|
|
107
|
+
|
|
108
|
+
The schema must either be one of the following:
|
|
109
|
+
1. A Pydantic BaseModel class
|
|
110
|
+
The structured output will be a Pydantic model.
|
|
111
|
+
2. A JSON schema dictionary
|
|
112
|
+
JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
113
|
+
Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
114
|
+
The structured output will be a dictionary.
|
|
115
|
+
|
|
116
|
+
Usage example:
|
|
117
|
+
```python
|
|
118
|
+
class Animal(BaseModel):
|
|
119
|
+
name: str
|
|
120
|
+
color: str
|
|
121
|
+
|
|
122
|
+
json_schema = Animal.model_json_schema()
|
|
123
|
+
|
|
124
|
+
lm_invoker = GoogleLMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
|
|
125
|
+
lm_invoker = GoogleLMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Output example:
|
|
129
|
+
```python
|
|
130
|
+
# Using Pydantic BaseModel class outputs a Pydantic model
|
|
131
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
|
|
132
|
+
|
|
133
|
+
# Using JSON schema dictionary outputs a dictionary
|
|
134
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Structured output is not compatible with tool calling.
|
|
138
|
+
When structured output is enabled, streaming is disabled.
|
|
139
|
+
|
|
85
140
|
Image generation:
|
|
86
|
-
The `GoogleLMInvoker`
|
|
87
|
-
such as `gemini-2.5-flash-image`.
|
|
88
|
-
|
|
141
|
+
The `GoogleLMInvoker` can be configured to generate images.
|
|
142
|
+
This feature can be enabled by using an image generation model, such as `gemini-2.5-flash-image`.
|
|
143
|
+
|
|
144
|
+
Image outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
145
|
+
via the `attachments` property.
|
|
89
146
|
|
|
90
147
|
Usage example:
|
|
91
148
|
```python
|
|
@@ -97,16 +154,25 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
97
154
|
Output example:
|
|
98
155
|
```python
|
|
99
156
|
LMOutput(
|
|
100
|
-
|
|
101
|
-
|
|
157
|
+
outputs=[
|
|
158
|
+
LMOutputItem(type="text", output="Creating a picture..."),
|
|
159
|
+
LMOutputItem(
|
|
160
|
+
type="attachment",
|
|
161
|
+
output=Attachment(filename="image.png", mime_type="image/png", data=b"..."),
|
|
162
|
+
),
|
|
163
|
+
],
|
|
102
164
|
)
|
|
103
165
|
```
|
|
104
166
|
|
|
167
|
+
Image generation is not compatible with tool calling and thinking.
|
|
168
|
+
When image generation is enabled, streaming is disabled.
|
|
169
|
+
|
|
105
170
|
Tool calling:
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
`
|
|
171
|
+
The `GoogleLMInvoker` can be configured to call tools to perform certain tasks.
|
|
172
|
+
This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
|
|
173
|
+
|
|
174
|
+
Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
|
|
175
|
+
can be accessed via the `tool_calls` property.
|
|
110
176
|
|
|
111
177
|
Usage example:
|
|
112
178
|
```python
|
|
@@ -116,67 +182,60 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
116
182
|
Output example:
|
|
117
183
|
```python
|
|
118
184
|
LMOutput(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
ToolCall(id="123", name="tool_1", args={"key": "value"}),
|
|
122
|
-
ToolCall(id="456", name="tool_2", args={"key": "value"}),
|
|
185
|
+
outputs=[
|
|
186
|
+
LMOutputItem(type="text", output="I\'m using tools..."),
|
|
187
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
|
|
188
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
|
|
123
189
|
]
|
|
124
190
|
)
|
|
125
191
|
```
|
|
126
192
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
This feature can be enabled by
|
|
130
|
-
|
|
131
|
-
The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
|
|
132
|
-
If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
133
|
-
For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
134
|
-
|
|
135
|
-
Structured output is not compatible with tool calling. The language model also doesn\'t need to stream
|
|
136
|
-
anything when structured output is enabled. Thus, standard invocation will be performed regardless of
|
|
137
|
-
whether the `event_emitter` parameter is provided or not.
|
|
193
|
+
Thinking:
|
|
194
|
+
The `GoogleLMInvoker` can be configured to perform step-by-step thinking process before answering.
|
|
195
|
+
This feature can be enabled by setting the `thinking` parameter to `True`.
|
|
138
196
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
|
|
197
|
+
Thinking outputs are stored in the `outputs` attribute of the `LMOutput` object
|
|
198
|
+
and can be accessed via the `thinkings` property.
|
|
142
199
|
|
|
143
|
-
# Example 1: Using a JSON schema dictionary
|
|
144
200
|
Usage example:
|
|
145
201
|
```python
|
|
146
|
-
|
|
147
|
-
"title": "Animal",
|
|
148
|
-
"description": "A description of an animal.",
|
|
149
|
-
"properties": {
|
|
150
|
-
"color": {"title": "Color", "type": "string"},
|
|
151
|
-
"name": {"title": "Name", "type": "string"},
|
|
152
|
-
},
|
|
153
|
-
"required": ["name", "color"],
|
|
154
|
-
"type": "object",
|
|
155
|
-
}
|
|
156
|
-
lm_invoker = GoogleLMInvoker(..., response_schema=schema)
|
|
202
|
+
lm_invoker = GoogleLMInvoker(..., thinking=True, thinking_budget=1024)
|
|
157
203
|
```
|
|
204
|
+
|
|
158
205
|
Output example:
|
|
159
206
|
```python
|
|
160
|
-
LMOutput(
|
|
207
|
+
LMOutput(
|
|
208
|
+
outputs=[
|
|
209
|
+
LMOutputItem(type="thinking", output=Reasoning(type="thinking", reasoning="I\'m thinking...", ...)),
|
|
210
|
+
LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
|
|
211
|
+
]
|
|
212
|
+
)
|
|
161
213
|
```
|
|
162
214
|
|
|
163
|
-
|
|
164
|
-
Usage example:
|
|
165
|
-
```python
|
|
166
|
-
class Animal(BaseModel):
|
|
167
|
-
name: str
|
|
168
|
-
color: str
|
|
169
|
-
|
|
170
|
-
lm_invoker = GoogleLMInvoker(..., response_schema=Animal)
|
|
171
|
-
```
|
|
172
|
-
Output example:
|
|
215
|
+
Streaming output example:
|
|
173
216
|
```python
|
|
174
|
-
|
|
217
|
+
{"type": "thinking_start", "value": "", ...}
|
|
218
|
+
{"type": "thinking", "value": "I\'m ", ...}
|
|
219
|
+
{"type": "thinking", "value": "thinking...", ...}
|
|
220
|
+
{"type": "thinking_end", "value": "", ...}
|
|
221
|
+
{"type": "response", "value": "Golden retriever ", ...}
|
|
222
|
+
{"type": "response", "value": "is a good dog breed.", ...}
|
|
175
223
|
```
|
|
224
|
+
Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
|
|
225
|
+
To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
|
|
226
|
+
LM invoker initialization. The legacy event format support will be removed in v0.6.
|
|
227
|
+
|
|
228
|
+
The amount of tokens allocated for the thinking process can be set via the `thinking_budget` parameter.
|
|
229
|
+
For more information, please refer to the following documentation:
|
|
230
|
+
https://ai.google.dev/gemini-api/docs/thinking
|
|
231
|
+
|
|
232
|
+
Thinking is only available for certain models, starting from Gemini 2.5 series.
|
|
233
|
+
Thinking is required for Gemini 2.5 Pro models.
|
|
176
234
|
|
|
177
235
|
Analytics tracking:
|
|
178
|
-
|
|
236
|
+
The `GoogleLMInvoker` can be configured to output additional information about the invocation.
|
|
179
237
|
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
238
|
+
|
|
180
239
|
When enabled, the following attributes will be stored in the output:
|
|
181
240
|
1. `token_usage`: The token usage.
|
|
182
241
|
2. `duration`: The duration in seconds.
|
|
@@ -185,15 +244,10 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
185
244
|
Output example:
|
|
186
245
|
```python
|
|
187
246
|
LMOutput(
|
|
188
|
-
|
|
189
|
-
token_usage=TokenUsage(
|
|
190
|
-
input_tokens=1500,
|
|
191
|
-
output_tokens=200,
|
|
192
|
-
input_token_details=InputTokenDetails(cached_tokens=1200, uncached_tokens=300),
|
|
193
|
-
output_token_details=OutputTokenDetails(reasoning_tokens=180, response_tokens=20),
|
|
194
|
-
),
|
|
247
|
+
outputs=[...],
|
|
248
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
195
249
|
duration=0.729,
|
|
196
|
-
finish_details={"
|
|
250
|
+
finish_details={"stop_reason": "end_turn"},
|
|
197
251
|
)
|
|
198
252
|
```
|
|
199
253
|
|
|
@@ -205,8 +259,6 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
205
259
|
Retry config examples:
|
|
206
260
|
```python
|
|
207
261
|
retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
|
|
208
|
-
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
209
|
-
retry_config = RetryConfig(max_retries=5, timeout=None) # 5 max retries, no timeout
|
|
210
262
|
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
211
263
|
```
|
|
212
264
|
|
|
@@ -215,63 +267,96 @@ class GoogleLMInvoker(BaseLMInvoker):
|
|
|
215
267
|
lm_invoker = GoogleLMInvoker(..., retry_config=retry_config)
|
|
216
268
|
```
|
|
217
269
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
It can be enabled by setting the `thinking` parameter to `True`.
|
|
270
|
+
Batch processing:
|
|
271
|
+
The `GoogleLMInvoker` supports batch processing, which allows the language model to process multiple
|
|
272
|
+
requests in a single call. Batch processing is supported through the `batch` attribute.
|
|
222
273
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
274
|
+
Due to Google SDK limitations with batch processing:
|
|
275
|
+
1. Only inline requests are currently supported (not file-based or BigQuery sources).
|
|
276
|
+
2. The total size of all requests must be under 20MB.
|
|
277
|
+
3. Original request indices are not preserved in the results. The results are keyed by request index in the
|
|
278
|
+
format \'1\', \'2\', etc, in which order are preserved based on the original request order. If you want to use
|
|
279
|
+
custom request IDs, you can pass them as a list of strings to the `custom_request_ids` keyword argument
|
|
227
280
|
|
|
228
281
|
Usage example:
|
|
229
282
|
```python
|
|
230
|
-
|
|
283
|
+
requests = {"1": "What color is the sky?", "2": "What color is the grass?"}
|
|
284
|
+
results = await lm_invoker.batch.invoke(requests)
|
|
231
285
|
```
|
|
232
286
|
|
|
233
287
|
Output example:
|
|
234
288
|
```python
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
289
|
+
{
|
|
290
|
+
"1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
|
|
291
|
+
"2": LMOutput(finish_details={"type": "error", "message": "..."}),
|
|
292
|
+
}
|
|
239
293
|
```
|
|
240
294
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
295
|
+
The `GoogleLMInvoker` also supports the following standalone batch processing operations:
|
|
296
|
+
|
|
297
|
+
1. Create a batch job:
|
|
298
|
+
```python
|
|
299
|
+
requests = {"1": "What color is the sky?", "2": "What color is the grass?"}
|
|
300
|
+
batch_id = await lm_invoker.batch.create(requests)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
2. Get the status of a batch job:
|
|
304
|
+
```python
|
|
305
|
+
status = await lm_invoker.batch.status(batch_id)
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
3. Retrieve the results of a batch job:
|
|
309
|
+
|
|
310
|
+
In default, the results will be keyed by request index in the format \'1\', \'2\', etc,
|
|
311
|
+
in which order are preserved based on the original request order.
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
```python
|
|
315
|
+
results = await lm_invoker.batch.retrieve(batch_id)
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Output example:
|
|
319
|
+
```python
|
|
320
|
+
{
|
|
321
|
+
"1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
|
|
322
|
+
"2": LMOutput(finish_details={"type": "error", "error": {"message": "...", ...}, ...}),
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
If you pass custom_request_ids to the create method, the results will be keyed by the custom_request_ids.
|
|
327
|
+
```python
|
|
328
|
+
results = await lm_invoker.batch.retrieve(batch_id, custom_request_ids=["request_1", "request_2"])
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Output example:
|
|
332
|
+
```python
|
|
333
|
+
{
|
|
334
|
+
"request_1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
|
|
335
|
+
"request_2": LMOutput(finish_details={"type": "error", "error": {"message": "...", ...}, ...}),
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
4. List the batch jobs:
|
|
340
|
+
```python
|
|
341
|
+
batch_jobs = await lm_invoker.batch.list()
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Output example:
|
|
345
|
+
```python
|
|
346
|
+
[
|
|
347
|
+
{"id": "batch_123", "status": "finished"},
|
|
348
|
+
{"id": "batch_456", "status": "in_progress"},
|
|
349
|
+
{"id": "batch_789", "status": "canceling"},
|
|
350
|
+
]
|
|
351
|
+
```
|
|
253
352
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
For more details, please refer to https://ai.google.dev/gemini-api/docs/thinking
|
|
259
|
-
|
|
260
|
-
Output types:
|
|
261
|
-
The output of the `GoogleLMInvoker` can either be:
|
|
262
|
-
1. `str`: A text response.
|
|
263
|
-
2. `LMOutput`: A Pydantic model that may contain the following attributes:
|
|
264
|
-
2.1. response (str)
|
|
265
|
-
2.2. attachments (list[Attachment])
|
|
266
|
-
2.3. tool_calls (list[ToolCall])
|
|
267
|
-
2.4. structured_output (dict[str, Any] | BaseModel | None)
|
|
268
|
-
2.5. token_usage (TokenUsage | None)
|
|
269
|
-
2.6. duration (float | None)
|
|
270
|
-
2.7. finish_details (dict[str, Any])
|
|
271
|
-
2.8. reasoning (list[Reasoning])
|
|
353
|
+
5. Cancel a batch job:
|
|
354
|
+
```python
|
|
355
|
+
await lm_invoker.batch.cancel(batch_id)
|
|
356
|
+
```
|
|
272
357
|
'''
|
|
273
358
|
client_params: Incomplete
|
|
274
|
-
|
|
359
|
+
image_generation: Incomplete
|
|
275
360
|
thinking: Incomplete
|
|
276
361
|
thinking_budget: Incomplete
|
|
277
362
|
def __init__(self, model_name: str, api_key: str | None = None, credentials_path: str | None = None, project_id: str | None = None, location: str = 'us-central1', 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 | None = None, thinking_budget: int = ..., simplify_events: bool = False) -> None:
|
|
@@ -78,81 +78,82 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
78
78
|
result = await lm_invoker.invoke([text, image])
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`tool_calls` attribute in the output.
|
|
86
|
-
|
|
87
|
-
Usage example:
|
|
88
|
-
```python
|
|
89
|
-
lm_invoker = LangChainLMInvoker(..., tools=[tool_1, tool_2])
|
|
90
|
-
```
|
|
81
|
+
Text output:
|
|
82
|
+
The `LangChainLMInvoker` generates text outputs by default.
|
|
83
|
+
Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
84
|
+
via the `texts` (all text outputs) or `text` (first text output) properties.
|
|
91
85
|
|
|
92
86
|
Output example:
|
|
93
87
|
```python
|
|
94
|
-
LMOutput(
|
|
95
|
-
response="Let me call the tools...",
|
|
96
|
-
tool_calls=[
|
|
97
|
-
ToolCall(id="123", name="tool_1", args={"key": "value"}),
|
|
98
|
-
ToolCall(id="456", name="tool_2", args={"key": "value"}),
|
|
99
|
-
]
|
|
100
|
-
)
|
|
88
|
+
LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
|
|
101
89
|
```
|
|
102
90
|
|
|
103
91
|
Structured output:
|
|
104
|
-
|
|
92
|
+
The `LangChainLMInvoker` can be configured to generate structured outputs.
|
|
105
93
|
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
110
|
-
|
|
111
|
-
Structured output is not compatible with tool calling. The language model also doesn\'t need to stream
|
|
112
|
-
anything when structured output is enabled. Thus, standard invocation will be performed regardless of
|
|
113
|
-
whether the `event_emitter` parameter is provided or not.
|
|
95
|
+
Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
96
|
+
via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
|
|
114
97
|
|
|
115
|
-
|
|
116
|
-
1.
|
|
117
|
-
|
|
98
|
+
The schema must either be one of the following:
|
|
99
|
+
1. A Pydantic BaseModel class
|
|
100
|
+
The structured output will be a Pydantic model.
|
|
101
|
+
2. A JSON schema dictionary
|
|
102
|
+
JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
103
|
+
Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
104
|
+
The structured output will be a dictionary.
|
|
118
105
|
|
|
119
|
-
# Example 1: Using a JSON schema dictionary
|
|
120
106
|
Usage example:
|
|
121
107
|
```python
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
"type": "object",
|
|
131
|
-
}
|
|
132
|
-
lm_invoker = LangChainLMInvoker(..., response_schema=schema)
|
|
108
|
+
class Animal(BaseModel):
|
|
109
|
+
name: str
|
|
110
|
+
color: str
|
|
111
|
+
|
|
112
|
+
json_schema = Animal.model_json_schema()
|
|
113
|
+
|
|
114
|
+
lm_invoker = LangChainLMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
|
|
115
|
+
lm_invoker = LangChainLMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
|
|
133
116
|
```
|
|
117
|
+
|
|
134
118
|
Output example:
|
|
135
119
|
```python
|
|
136
|
-
|
|
120
|
+
# Using Pydantic BaseModel class outputs a Pydantic model
|
|
121
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
|
|
122
|
+
|
|
123
|
+
# Using JSON schema dictionary outputs a dictionary
|
|
124
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
|
|
137
125
|
```
|
|
138
126
|
|
|
139
|
-
|
|
127
|
+
Structured output is not compatible with tool calling.
|
|
128
|
+
When structured output is enabled, streaming is disabled.
|
|
129
|
+
|
|
130
|
+
Tool calling:
|
|
131
|
+
The `LangChainLMInvoker` can be configured to call tools to perform certain tasks.
|
|
132
|
+
This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
|
|
133
|
+
|
|
134
|
+
Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
|
|
135
|
+
can be accessed via the `tool_calls` property.
|
|
136
|
+
|
|
140
137
|
Usage example:
|
|
141
138
|
```python
|
|
142
|
-
|
|
143
|
-
name: str
|
|
144
|
-
color: str
|
|
145
|
-
|
|
146
|
-
lm_invoker = LangChainLMInvoker(..., response_schema=Animal)
|
|
139
|
+
lm_invoker = LangChainLMInvoker(..., tools=[tool_1, tool_2])
|
|
147
140
|
```
|
|
141
|
+
|
|
148
142
|
Output example:
|
|
149
143
|
```python
|
|
150
|
-
LMOutput(
|
|
144
|
+
LMOutput(
|
|
145
|
+
outputs=[
|
|
146
|
+
LMOutputItem(type="text", output="I\'m using tools..."),
|
|
147
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
|
|
148
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
|
|
149
|
+
]
|
|
150
|
+
)
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
Analytics tracking:
|
|
154
|
-
|
|
154
|
+
The `LangChainLMInvoker` can be configured to output additional information about the invocation.
|
|
155
155
|
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
156
|
+
|
|
156
157
|
When enabled, the following attributes will be stored in the output:
|
|
157
158
|
1. `token_usage`: The token usage.
|
|
158
159
|
2. `duration`: The duration in seconds.
|
|
@@ -161,10 +162,10 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
161
162
|
Output example:
|
|
162
163
|
```python
|
|
163
164
|
LMOutput(
|
|
164
|
-
|
|
165
|
+
outputs=[...],
|
|
165
166
|
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
166
167
|
duration=0.729,
|
|
167
|
-
finish_details={"
|
|
168
|
+
finish_details={"stop_reason": "end_turn"},
|
|
168
169
|
)
|
|
169
170
|
```
|
|
170
171
|
|
|
@@ -176,8 +177,6 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
176
177
|
Retry config examples:
|
|
177
178
|
```python
|
|
178
179
|
retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
|
|
179
|
-
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
180
|
-
retry_config = RetryConfig(max_retries=5, timeout=None) # 5 max retries, no timeout
|
|
181
180
|
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
182
181
|
```
|
|
183
182
|
|
|
@@ -185,17 +184,6 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
185
184
|
```python
|
|
186
185
|
lm_invoker = LangChainLMInvoker(..., retry_config=retry_config)
|
|
187
186
|
```
|
|
188
|
-
|
|
189
|
-
Output types:
|
|
190
|
-
The output of the `LangChainLMInvoker` can either be:
|
|
191
|
-
1. `str`: A text response.
|
|
192
|
-
2. `LMOutput`: A Pydantic model that may contain the following attributes:
|
|
193
|
-
2.1. response (str)
|
|
194
|
-
2.2. tool_calls (list[ToolCall])
|
|
195
|
-
2.3. structured_output (dict[str, Any] | BaseModel | None)
|
|
196
|
-
2.4. token_usage (TokenUsage | None)
|
|
197
|
-
2.5. duration (float | None)
|
|
198
|
-
2.6. finish_details (dict[str, Any])
|
|
199
187
|
'''
|
|
200
188
|
model: Incomplete
|
|
201
189
|
def __init__(self, model: BaseChatModel | None = None, model_class_path: str | None = None, model_name: 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) -> None:
|