gllm-inference-binary 0.5.65__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.
- gllm_inference/__init__.pyi +0 -0
- gllm_inference/builder/__init__.pyi +6 -0
- gllm_inference/builder/_build_invoker.pyi +28 -0
- gllm_inference/builder/build_em_invoker.pyi +130 -0
- gllm_inference/builder/build_lm_invoker.pyi +222 -0
- gllm_inference/builder/build_lm_request_processor.pyi +88 -0
- gllm_inference/builder/build_output_parser.pyi +29 -0
- gllm_inference/catalog/__init__.pyi +4 -0
- gllm_inference/catalog/catalog.pyi +121 -0
- gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
- gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
- gllm_inference/constants.pyi +12 -0
- gllm_inference/em_invoker/__init__.pyi +12 -0
- gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
- gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
- gllm_inference/em_invoker/cohere_em_invoker.pyi +127 -0
- gllm_inference/em_invoker/em_invoker.pyi +90 -0
- gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
- gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
- gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
- gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
- gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
- gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
- gllm_inference/em_invoker/schema/__init__.pyi +0 -0
- gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
- gllm_inference/em_invoker/schema/cohere.pyi +20 -0
- gllm_inference/em_invoker/schema/google.pyi +9 -0
- gllm_inference/em_invoker/schema/jina.pyi +29 -0
- gllm_inference/em_invoker/schema/langchain.pyi +5 -0
- gllm_inference/em_invoker/schema/openai.pyi +7 -0
- gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
- gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
- gllm_inference/em_invoker/schema/voyage.pyi +15 -0
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
- gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
- gllm_inference/exceptions/__init__.pyi +4 -0
- gllm_inference/exceptions/error_parser.pyi +41 -0
- gllm_inference/exceptions/exceptions.pyi +132 -0
- gllm_inference/exceptions/provider_error_map.pyi +24 -0
- gllm_inference/lm_invoker/__init__.pyi +15 -0
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +320 -0
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +237 -0
- gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
- gllm_inference/lm_invoker/batch/batch_operations.pyi +128 -0
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +212 -0
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
- gllm_inference/lm_invoker/google_lm_invoker.pyi +421 -0
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +239 -0
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +224 -0
- gllm_inference/lm_invoker/lm_invoker.pyi +183 -0
- gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +252 -0
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +437 -0
- gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -0
- gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
- gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
- gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
- gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
- gllm_inference/lm_invoker/schema/google.pyi +36 -0
- gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
- gllm_inference/lm_invoker/schema/openai.pyi +109 -0
- gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
- gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
- gllm_inference/lm_invoker/schema/xai.pyi +31 -0
- gllm_inference/lm_invoker/sea_lion_lm_invoker.pyi +48 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +252 -0
- gllm_inference/model/__init__.pyi +13 -0
- gllm_inference/model/em/__init__.pyi +0 -0
- gllm_inference/model/em/cohere_em.pyi +17 -0
- gllm_inference/model/em/google_em.pyi +16 -0
- gllm_inference/model/em/jina_em.pyi +22 -0
- gllm_inference/model/em/openai_em.pyi +15 -0
- gllm_inference/model/em/twelvelabs_em.pyi +13 -0
- gllm_inference/model/em/voyage_em.pyi +20 -0
- gllm_inference/model/lm/__init__.pyi +0 -0
- gllm_inference/model/lm/anthropic_lm.pyi +22 -0
- gllm_inference/model/lm/google_lm.pyi +18 -0
- gllm_inference/model/lm/openai_lm.pyi +27 -0
- gllm_inference/model/lm/sea_lion_lm.pyi +16 -0
- gllm_inference/model/lm/xai_lm.pyi +19 -0
- gllm_inference/output_parser/__init__.pyi +3 -0
- gllm_inference/output_parser/json_output_parser.pyi +60 -0
- gllm_inference/output_parser/output_parser.pyi +27 -0
- gllm_inference/prompt_builder/__init__.pyi +3 -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 +73 -0
- gllm_inference/prompt_formatter/__init__.pyi +7 -0
- gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
- gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
- gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
- gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
- gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
- gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
- gllm_inference/realtime_chat/__init__.pyi +3 -0
- gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
- gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
- gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
- gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
- gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
- gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
- gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
- gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
- gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
- gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
- gllm_inference/request_processor/__init__.pyi +4 -0
- gllm_inference/request_processor/lm_request_processor.pyi +101 -0
- gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
- gllm_inference/schema/__init__.pyi +19 -0
- gllm_inference/schema/activity.pyi +64 -0
- gllm_inference/schema/attachment.pyi +102 -0
- gllm_inference/schema/code_exec_result.pyi +14 -0
- gllm_inference/schema/config.pyi +15 -0
- gllm_inference/schema/enums.pyi +82 -0
- gllm_inference/schema/events.pyi +105 -0
- gllm_inference/schema/formatter.pyi +31 -0
- gllm_inference/schema/lm_input.pyi +4 -0
- gllm_inference/schema/lm_output.pyi +266 -0
- gllm_inference/schema/mcp.pyi +31 -0
- gllm_inference/schema/message.pyi +52 -0
- gllm_inference/schema/model_id.pyi +176 -0
- gllm_inference/schema/reasoning.pyi +15 -0
- gllm_inference/schema/token_usage.pyi +75 -0
- gllm_inference/schema/tool_call.pyi +14 -0
- gllm_inference/schema/tool_result.pyi +11 -0
- gllm_inference/schema/type_alias.pyi +11 -0
- gllm_inference/utils/__init__.pyi +5 -0
- gllm_inference/utils/io_utils.pyi +26 -0
- gllm_inference/utils/langchain.pyi +30 -0
- gllm_inference/utils/validation.pyi +15 -0
- gllm_inference.build/.gitignore +1 -0
- gllm_inference.cpython-313-darwin.so +0 -0
- gllm_inference.pyi +156 -0
- gllm_inference_binary-0.5.65.dist-info/METADATA +138 -0
- gllm_inference_binary-0.5.65.dist-info/RECORD +140 -0
- gllm_inference_binary-0.5.65.dist-info/WHEEL +5 -0
- gllm_inference_binary-0.5.65.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_core.event import EventEmitter as EventEmitter
|
|
3
|
+
from gllm_core.schema.tool import Tool
|
|
4
|
+
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
5
|
+
from gllm_inference.constants import GOOGLE_SCOPES as GOOGLE_SCOPES, SECONDS_TO_MILLISECONDS as SECONDS_TO_MILLISECONDS
|
|
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
|
+
from gllm_inference.exceptions.provider_error_map import GOOGLE_ERROR_MAPPING as GOOGLE_ERROR_MAPPING
|
|
8
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
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
|
|
12
|
+
from langchain_core.tools import Tool as LangChainTool
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
16
|
+
DEFAULT_THINKING_BUDGET: int
|
|
17
|
+
REQUIRE_THINKING_MODEL_PREFIX: Incomplete
|
|
18
|
+
IMAGE_GENERATION_MODELS: Incomplete
|
|
19
|
+
BATCH_STATUS_MAP: Incomplete
|
|
20
|
+
|
|
21
|
+
class URLPattern:
|
|
22
|
+
"""Defines specific Google related URL patterns."""
|
|
23
|
+
GOOGLE_FILE: Incomplete
|
|
24
|
+
YOUTUBE: Incomplete
|
|
25
|
+
|
|
26
|
+
class GoogleLMInvoker(BaseLMInvoker):
|
|
27
|
+
'''A language model invoker to interact with Google language models.
|
|
28
|
+
|
|
29
|
+
Attributes:
|
|
30
|
+
model_id (str): The model ID of the language model.
|
|
31
|
+
model_provider (str): The provider of the language model.
|
|
32
|
+
model_name (str): The name of the language model.
|
|
33
|
+
client_params (dict[str, Any]): The Google client instance init parameters.
|
|
34
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
|
35
|
+
tools (list[Any]): The list of tools provided to the model to enable tool calling.
|
|
36
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
|
37
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
38
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
|
39
|
+
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
40
|
+
thinking (bool): Whether to enable thinking. Only allowed for thinking models.
|
|
41
|
+
thinking_budget (int): The tokens allowed for thinking process. Only allowed for thinking models.
|
|
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.
|
|
44
|
+
|
|
45
|
+
Basic usage:
|
|
46
|
+
The `GoogleLMInvoker` can be used as follows:
|
|
47
|
+
```python
|
|
48
|
+
lm_invoker = GoogleLMInvoker(model_name="gemini-2.5-flash")
|
|
49
|
+
result = await lm_invoker.invoke("Hi there!")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Authentication:
|
|
53
|
+
The `GoogleLMInvoker` can use either Google Gen AI or Google Vertex AI.
|
|
54
|
+
|
|
55
|
+
Google Gen AI is recommended for quick prototyping and development.
|
|
56
|
+
It requires a Gemini API key for authentication.
|
|
57
|
+
|
|
58
|
+
Usage example:
|
|
59
|
+
```python
|
|
60
|
+
lm_invoker = GoogleLMInvoker(
|
|
61
|
+
model_name="gemini-2.5-flash",
|
|
62
|
+
api_key="your_api_key"
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Google Vertex AI is recommended to build production-ready applications.
|
|
67
|
+
It requires a service account JSON file for authentication.
|
|
68
|
+
|
|
69
|
+
Usage example:
|
|
70
|
+
```python
|
|
71
|
+
lm_invoker = GoogleLMInvoker(
|
|
72
|
+
model_name="gemini-2.5-flash",
|
|
73
|
+
credentials_path="path/to/service_account.json"
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
|
|
78
|
+
The `GOOGLE_API_KEY` environment variable will be used for authentication.
|
|
79
|
+
|
|
80
|
+
Input types:
|
|
81
|
+
The `GoogleLMInvoker` supports the following input types: text, audio, document, image, and video.
|
|
82
|
+
Non-text inputs can be passed as an `Attachment` object with either the `user` or `assistant` role.
|
|
83
|
+
|
|
84
|
+
Usage example:
|
|
85
|
+
```python
|
|
86
|
+
text = "What animal is in this image?"
|
|
87
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
88
|
+
result = await lm_invoker.invoke([text, image])
|
|
89
|
+
```
|
|
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
|
+
|
|
140
|
+
Image generation:
|
|
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.
|
|
146
|
+
|
|
147
|
+
Usage example:
|
|
148
|
+
```python
|
|
149
|
+
lm_invoker = GoogleLMInvoker("gemini-2.5-flash-image")
|
|
150
|
+
result = await lm_invoker.invoke("Create a picture...")
|
|
151
|
+
result.attachments[0].write_to_file("path/to/local/image.png")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Output example:
|
|
155
|
+
```python
|
|
156
|
+
LMOutput(
|
|
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
|
+
],
|
|
164
|
+
)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Image generation is not compatible with tool calling and thinking.
|
|
168
|
+
When image generation is enabled, streaming is disabled.
|
|
169
|
+
|
|
170
|
+
Tool calling:
|
|
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.
|
|
176
|
+
|
|
177
|
+
Usage example:
|
|
178
|
+
```python
|
|
179
|
+
lm_invoker = GoogleLMInvoker(..., tools=[tool_1, tool_2])
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Output example:
|
|
183
|
+
```python
|
|
184
|
+
LMOutput(
|
|
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"})),
|
|
189
|
+
]
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
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`.
|
|
196
|
+
|
|
197
|
+
Thinking outputs are stored in the `outputs` attribute of the `LMOutput` object
|
|
198
|
+
and can be accessed via the `thinkings` property.
|
|
199
|
+
|
|
200
|
+
Usage example:
|
|
201
|
+
```python
|
|
202
|
+
lm_invoker = GoogleLMInvoker(..., thinking=True, thinking_budget=1024)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Output example:
|
|
206
|
+
```python
|
|
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
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Streaming output example:
|
|
216
|
+
```python
|
|
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.", ...}
|
|
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.
|
|
234
|
+
|
|
235
|
+
Analytics tracking:
|
|
236
|
+
The `GoogleLMInvoker` can be configured to output additional information about the invocation.
|
|
237
|
+
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
238
|
+
|
|
239
|
+
When enabled, the following attributes will be stored in the output:
|
|
240
|
+
1. `token_usage`: The token usage.
|
|
241
|
+
2. `duration`: The duration in seconds.
|
|
242
|
+
3. `finish_details`: The details about how the generation finished.
|
|
243
|
+
|
|
244
|
+
Output example:
|
|
245
|
+
```python
|
|
246
|
+
LMOutput(
|
|
247
|
+
outputs=[...],
|
|
248
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
249
|
+
duration=0.729,
|
|
250
|
+
finish_details={"stop_reason": "end_turn"},
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Retry and timeout:
|
|
255
|
+
The `GoogleLMInvoker` supports retry and timeout configuration.
|
|
256
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
257
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
258
|
+
|
|
259
|
+
Retry config examples:
|
|
260
|
+
```python
|
|
261
|
+
retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
|
|
262
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Usage example:
|
|
266
|
+
```python
|
|
267
|
+
lm_invoker = GoogleLMInvoker(..., retry_config=retry_config)
|
|
268
|
+
```
|
|
269
|
+
|
|
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.
|
|
273
|
+
|
|
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
|
|
280
|
+
|
|
281
|
+
Usage example:
|
|
282
|
+
```python
|
|
283
|
+
requests = {"1": "What color is the sky?", "2": "What color is the grass?"}
|
|
284
|
+
results = await lm_invoker.batch.invoke(requests)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Output example:
|
|
288
|
+
```python
|
|
289
|
+
{
|
|
290
|
+
"1": LMOutput(outputs=[LMOutputItem(type="text", output="The sky is blue.")]),
|
|
291
|
+
"2": LMOutput(finish_details={"type": "error", "message": "..."}),
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
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
|
+
```
|
|
352
|
+
|
|
353
|
+
5. Cancel a batch job:
|
|
354
|
+
```python
|
|
355
|
+
await lm_invoker.batch.cancel(batch_id)
|
|
356
|
+
```
|
|
357
|
+
'''
|
|
358
|
+
client_params: Incomplete
|
|
359
|
+
image_generation: Incomplete
|
|
360
|
+
thinking: Incomplete
|
|
361
|
+
thinking_budget: Incomplete
|
|
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:
|
|
363
|
+
'''Initializes a new instance of the GoogleLMInvoker class.
|
|
364
|
+
|
|
365
|
+
Args:
|
|
366
|
+
model_name (str): The name of the model to use.
|
|
367
|
+
api_key (str | None, optional): Required for Google Gen AI authentication. Cannot be used together
|
|
368
|
+
with `credentials_path`. Defaults to None.
|
|
369
|
+
credentials_path (str | None, optional): Required for Google Vertex AI authentication. Path to the service
|
|
370
|
+
account credentials JSON file. Cannot be used together with `api_key`. Defaults to None.
|
|
371
|
+
project_id (str | None, optional): The Google Cloud project ID for Vertex AI. Only used when authenticating
|
|
372
|
+
with `credentials_path`. Defaults to None, in which case it will be loaded from the credentials file.
|
|
373
|
+
location (str, optional): The location of the Google Cloud project for Vertex AI. Only used when
|
|
374
|
+
authenticating with `credentials_path`. Defaults to "us-central1".
|
|
375
|
+
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Google Vertex AI
|
|
376
|
+
client.
|
|
377
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
378
|
+
Defaults to None.
|
|
379
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
|
|
380
|
+
Defaults to None.
|
|
381
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
|
382
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
|
383
|
+
dictionary. Defaults to None.
|
|
384
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
|
385
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
|
386
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
387
|
+
thinking (bool | None, optional): Whether to enable thinking. Only allowed for thinking models.
|
|
388
|
+
Defaults to True for Gemini 2.5 Pro models and False for other models.
|
|
389
|
+
thinking_budget (int, optional): The tokens allowed for thinking process. Only allowed for thinking models.
|
|
390
|
+
Defaults to -1, in which case the model will control the budget automatically.
|
|
391
|
+
simplify_events (bool, optional): Temporary parameter to control the streamed events format.
|
|
392
|
+
When True, uses the simplified events format. When False, uses the legacy events format for
|
|
393
|
+
backward compatibility. Will be removed in v0.6. Defaults to False.
|
|
394
|
+
|
|
395
|
+
Note:
|
|
396
|
+
If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
|
|
397
|
+
The `GOOGLE_API_KEY` environment variable will be used for authentication.
|
|
398
|
+
'''
|
|
399
|
+
def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
|
|
400
|
+
"""Sets the tools for the Google language model.
|
|
401
|
+
|
|
402
|
+
This method sets the tools for the Google language model. Any existing tools will be replaced.
|
|
403
|
+
|
|
404
|
+
Args:
|
|
405
|
+
tools (list[Tool | LangChainTool]): The list of tools to be used.
|
|
406
|
+
|
|
407
|
+
Raises:
|
|
408
|
+
ValueError: If `response_schema` exists.
|
|
409
|
+
"""
|
|
410
|
+
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
411
|
+
"""Sets the response schema for the Google language model.
|
|
412
|
+
|
|
413
|
+
This method sets the response schema for the Google language model. Any existing response schema will be
|
|
414
|
+
replaced.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
response_schema (ResponseSchema | None): The response schema to be used.
|
|
418
|
+
|
|
419
|
+
Raises:
|
|
420
|
+
ValueError: If `tools` exists.
|
|
421
|
+
"""
|
|
@@ -0,0 +1,239 @@
|
|
|
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
|
|
5
|
+
from gllm_inference.constants import INVOKER_DEFAULT_TIMEOUT as INVOKER_DEFAULT_TIMEOUT, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
6
|
+
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, InvokerRuntimeError as InvokerRuntimeError, build_debug_info as build_debug_info
|
|
7
|
+
from gllm_inference.exceptions.provider_error_map import ALL_PROVIDER_ERROR_MAPPINGS as ALL_PROVIDER_ERROR_MAPPINGS, LANGCHAIN_ERROR_CODE_MAPPING as LANGCHAIN_ERROR_CODE_MAPPING
|
|
8
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
9
|
+
from gllm_inference.lm_invoker.schema.langchain 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, ResponseSchema as ResponseSchema, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult
|
|
11
|
+
from gllm_inference.utils import load_langchain_model as load_langchain_model, parse_model_data as parse_model_data
|
|
12
|
+
from langchain_core.language_models import BaseChatModel as BaseChatModel
|
|
13
|
+
from langchain_core.messages import BaseMessage as BaseMessage
|
|
14
|
+
from langchain_core.tools import Tool as LangChainTool
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
18
|
+
MESSAGE_CLASS_MAP: Incomplete
|
|
19
|
+
|
|
20
|
+
class LangChainLMInvoker(BaseLMInvoker):
|
|
21
|
+
'''A language model invoker to interact with LangChain\'s BaseChatModel.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
model_id (str): The model ID of the language model.
|
|
25
|
+
model_provider (str): The provider of the language model.
|
|
26
|
+
model_name (str): The name of the language model.
|
|
27
|
+
model (BaseChatModel): The LangChain\'s BaseChatModel instance.
|
|
28
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
|
29
|
+
tools (list[Any]): The list of tools provided to the model to enable tool calling.
|
|
30
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
|
31
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
32
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
|
33
|
+
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
34
|
+
|
|
35
|
+
Basic usage:
|
|
36
|
+
The `LangChainLMInvoker` can be used as follows:
|
|
37
|
+
```python
|
|
38
|
+
lm_invoker = LangChainLMInvoker(
|
|
39
|
+
model_class_path="langchain_openai.ChatOpenAI",
|
|
40
|
+
model_name="gpt-5-nano",
|
|
41
|
+
)
|
|
42
|
+
result = await lm_invoker.invoke("Hi there!")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Initialization:
|
|
46
|
+
The `LangChainLMInvoker` can be initialized by either passing:
|
|
47
|
+
|
|
48
|
+
1. A LangChain\'s BaseChatModel instance:
|
|
49
|
+
Usage example:
|
|
50
|
+
```python
|
|
51
|
+
from langchain_openai import ChatOpenAI
|
|
52
|
+
|
|
53
|
+
model = ChatOpenAI(model="gpt-5-nano", api_key="your_api_key")
|
|
54
|
+
lm_invoker = LangChainLMInvoker(model=model)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
2. A model path in the format of "<package>.<class>":
|
|
58
|
+
Usage example:
|
|
59
|
+
```python
|
|
60
|
+
lm_invoker = LangChainLMInvoker(
|
|
61
|
+
model_class_path="langchain_openai.ChatOpenAI",
|
|
62
|
+
model_name="gpt-5-nano",
|
|
63
|
+
model_kwargs={"api_key": "your_api_key"}
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
For the list of supported providers, please refer to the following table:
|
|
67
|
+
https://python.langchain.com/docs/integrations/chat/#featured-providers
|
|
68
|
+
|
|
69
|
+
Input types:
|
|
70
|
+
The `LangChainLMInvoker` supports the following input types: text and image.
|
|
71
|
+
Non-text inputs can be passed as an `Attachment` object and with specific roles,
|
|
72
|
+
depending on the language model\'s capabilities.
|
|
73
|
+
|
|
74
|
+
Usage example:
|
|
75
|
+
```python
|
|
76
|
+
text = "What animal is in this image?"
|
|
77
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
78
|
+
result = await lm_invoker.invoke([text, image])
|
|
79
|
+
```
|
|
80
|
+
|
|
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.
|
|
85
|
+
|
|
86
|
+
Output example:
|
|
87
|
+
```python
|
|
88
|
+
LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Structured output:
|
|
92
|
+
The `LangChainLMInvoker` can be configured to generate structured outputs.
|
|
93
|
+
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
94
|
+
|
|
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.
|
|
97
|
+
|
|
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.
|
|
105
|
+
|
|
106
|
+
Usage example:
|
|
107
|
+
```python
|
|
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
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Output example:
|
|
119
|
+
```python
|
|
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"})])
|
|
125
|
+
```
|
|
126
|
+
|
|
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
|
+
|
|
137
|
+
Usage example:
|
|
138
|
+
```python
|
|
139
|
+
lm_invoker = LangChainLMInvoker(..., tools=[tool_1, tool_2])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Output example:
|
|
143
|
+
```python
|
|
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
|
+
```
|
|
152
|
+
|
|
153
|
+
Analytics tracking:
|
|
154
|
+
The `LangChainLMInvoker` can be configured to output additional information about the invocation.
|
|
155
|
+
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
156
|
+
|
|
157
|
+
When enabled, the following attributes will be stored in the output:
|
|
158
|
+
1. `token_usage`: The token usage.
|
|
159
|
+
2. `duration`: The duration in seconds.
|
|
160
|
+
3. `finish_details`: The details about how the generation finished.
|
|
161
|
+
|
|
162
|
+
Output example:
|
|
163
|
+
```python
|
|
164
|
+
LMOutput(
|
|
165
|
+
outputs=[...],
|
|
166
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
167
|
+
duration=0.729,
|
|
168
|
+
finish_details={"stop_reason": "end_turn"},
|
|
169
|
+
)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Retry and timeout:
|
|
173
|
+
The `LangChainLMInvoker` 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.
|
|
176
|
+
|
|
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=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Usage example:
|
|
184
|
+
```python
|
|
185
|
+
lm_invoker = LangChainLMInvoker(..., retry_config=retry_config)
|
|
186
|
+
```
|
|
187
|
+
'''
|
|
188
|
+
model: Incomplete
|
|
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:
|
|
190
|
+
'''Initializes a new instance of the LangChainLMInvoker class.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
model (BaseChatModel | None, optional): The LangChain\'s BaseChatModel instance. If provided, will take
|
|
194
|
+
precedence over the `model_class_path` parameter. Defaults to None.
|
|
195
|
+
model_class_path (str | None, optional): The LangChain\'s BaseChatModel class path. Must be formatted as
|
|
196
|
+
"<package>.<class>" (e.g. "langchain_openai.ChatOpenAI"). Ignored if `model` is provided.
|
|
197
|
+
Defaults to None.
|
|
198
|
+
model_name (str | None, optional): The model name. Only used if `model_class_path` is provided.
|
|
199
|
+
Defaults to None.
|
|
200
|
+
model_kwargs (dict[str, Any] | None, optional): The additional keyword arguments. Only used if
|
|
201
|
+
`model_class_path` is provided. Defaults to None.
|
|
202
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
203
|
+
Defaults to None.
|
|
204
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
|
|
205
|
+
Defaults to None.
|
|
206
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
|
207
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
|
208
|
+
dictionary. Defaults to None.
|
|
209
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
|
210
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
|
211
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
212
|
+
|
|
213
|
+
Raises:
|
|
214
|
+
ValueError: If `response_schema` is provided, but `tools` are also provided.
|
|
215
|
+
'''
|
|
216
|
+
tools: Incomplete
|
|
217
|
+
def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
|
|
218
|
+
"""Sets the tools for LangChain's BaseChatModel.
|
|
219
|
+
|
|
220
|
+
This method sets the tools for LangChain's BaseChatModel. Any existing tools will be replaced.
|
|
221
|
+
|
|
222
|
+
Args:
|
|
223
|
+
tools (list[Tool]): The list of tools to be used.
|
|
224
|
+
|
|
225
|
+
Raises:
|
|
226
|
+
ValueError: If `response_schema` exists.
|
|
227
|
+
"""
|
|
228
|
+
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
229
|
+
"""Sets the response schema for the LangChain's BaseChatModel.
|
|
230
|
+
|
|
231
|
+
This method sets the response schema for the LangChain's BaseChatModel. Any existing response schema will be
|
|
232
|
+
replaced.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
response_schema (ResponseSchema | None): The response schema to be used.
|
|
236
|
+
|
|
237
|
+
Raises:
|
|
238
|
+
ValueError: If `tools` exists.
|
|
239
|
+
"""
|