gllm-inference-binary 0.5.51b3__cp313-cp313-macosx_11_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.
Files changed (137) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/_build_invoker.pyi +28 -0
  4. gllm_inference/builder/build_em_invoker.pyi +130 -0
  5. gllm_inference/builder/build_lm_invoker.pyi +213 -0
  6. gllm_inference/builder/build_lm_request_processor.pyi +88 -0
  7. gllm_inference/builder/build_output_parser.pyi +29 -0
  8. gllm_inference/catalog/__init__.pyi +4 -0
  9. gllm_inference/catalog/catalog.pyi +121 -0
  10. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  11. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  12. gllm_inference/constants.pyi +13 -0
  13. gllm_inference/em_invoker/__init__.pyi +12 -0
  14. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  15. gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
  16. gllm_inference/em_invoker/cohere_em_invoker.pyi +128 -0
  17. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  18. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  19. gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
  20. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  21. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  22. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  23. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
  24. gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
  25. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  26. gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
  27. gllm_inference/em_invoker/schema/cohere.pyi +20 -0
  28. gllm_inference/em_invoker/schema/google.pyi +9 -0
  29. gllm_inference/em_invoker/schema/jina.pyi +29 -0
  30. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  31. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  32. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  33. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  34. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  35. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  36. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  37. gllm_inference/exceptions/__init__.pyi +4 -0
  38. gllm_inference/exceptions/error_parser.pyi +41 -0
  39. gllm_inference/exceptions/exceptions.pyi +132 -0
  40. gllm_inference/exceptions/provider_error_map.pyi +24 -0
  41. gllm_inference/lm_invoker/__init__.pyi +14 -0
  42. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +334 -0
  43. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +254 -0
  44. gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
  45. gllm_inference/lm_invoker/batch/batch_operations.pyi +127 -0
  46. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +226 -0
  47. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
  48. gllm_inference/lm_invoker/google_lm_invoker.pyi +336 -0
  49. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +251 -0
  50. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +244 -0
  51. gllm_inference/lm_invoker/lm_invoker.pyi +164 -0
  52. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +272 -0
  53. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
  54. gllm_inference/lm_invoker/openai_lm_invoker.pyi +433 -0
  55. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +260 -0
  56. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  57. gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
  58. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  59. gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
  60. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  61. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  62. gllm_inference/lm_invoker/schema/openai.pyi +106 -0
  63. gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
  64. gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
  65. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  66. gllm_inference/lm_invoker/xai_lm_invoker.pyi +289 -0
  67. gllm_inference/model/__init__.pyi +12 -0
  68. gllm_inference/model/em/__init__.pyi +0 -0
  69. gllm_inference/model/em/cohere_em.pyi +17 -0
  70. gllm_inference/model/em/google_em.pyi +16 -0
  71. gllm_inference/model/em/jina_em.pyi +22 -0
  72. gllm_inference/model/em/openai_em.pyi +15 -0
  73. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  74. gllm_inference/model/em/voyage_em.pyi +20 -0
  75. gllm_inference/model/lm/__init__.pyi +0 -0
  76. gllm_inference/model/lm/anthropic_lm.pyi +22 -0
  77. gllm_inference/model/lm/google_lm.pyi +18 -0
  78. gllm_inference/model/lm/openai_lm.pyi +27 -0
  79. gllm_inference/model/lm/xai_lm.pyi +19 -0
  80. gllm_inference/output_parser/__init__.pyi +3 -0
  81. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  82. gllm_inference/output_parser/output_parser.pyi +27 -0
  83. gllm_inference/prompt_builder/__init__.pyi +3 -0
  84. gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
  85. gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
  86. gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
  87. gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
  88. gllm_inference/prompt_builder/prompt_builder.pyi +69 -0
  89. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  90. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  91. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  92. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  93. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  94. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  95. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  96. gllm_inference/realtime_chat/__init__.pyi +3 -0
  97. gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
  98. gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
  99. gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
  100. gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
  101. gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
  102. gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
  103. gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
  104. gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
  105. gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
  106. gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
  107. gllm_inference/request_processor/__init__.pyi +4 -0
  108. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  109. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  110. gllm_inference/schema/__init__.pyi +18 -0
  111. gllm_inference/schema/activity.pyi +64 -0
  112. gllm_inference/schema/attachment.pyi +88 -0
  113. gllm_inference/schema/code_exec_result.pyi +14 -0
  114. gllm_inference/schema/config.pyi +15 -0
  115. gllm_inference/schema/enums.pyi +69 -0
  116. gllm_inference/schema/events.pyi +105 -0
  117. gllm_inference/schema/lm_input.pyi +4 -0
  118. gllm_inference/schema/lm_output.pyi +44 -0
  119. gllm_inference/schema/mcp.pyi +31 -0
  120. gllm_inference/schema/message.pyi +52 -0
  121. gllm_inference/schema/model_id.pyi +176 -0
  122. gllm_inference/schema/reasoning.pyi +15 -0
  123. gllm_inference/schema/token_usage.pyi +75 -0
  124. gllm_inference/schema/tool_call.pyi +14 -0
  125. gllm_inference/schema/tool_result.pyi +11 -0
  126. gllm_inference/schema/type_alias.pyi +11 -0
  127. gllm_inference/utils/__init__.pyi +5 -0
  128. gllm_inference/utils/io_utils.pyi +26 -0
  129. gllm_inference/utils/langchain.pyi +30 -0
  130. gllm_inference/utils/validation.pyi +12 -0
  131. gllm_inference.build/.gitignore +1 -0
  132. gllm_inference.cpython-313-darwin.so +0 -0
  133. gllm_inference.pyi +157 -0
  134. gllm_inference_binary-0.5.51b3.dist-info/METADATA +138 -0
  135. gllm_inference_binary-0.5.51b3.dist-info/RECORD +137 -0
  136. gllm_inference_binary-0.5.51b3.dist-info/WHEEL +5 -0
  137. gllm_inference_binary-0.5.51b3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,336 @@
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, 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
11
+ from langchain_core.tools import Tool as LangChainTool
12
+ from typing import Any
13
+
14
+ SUPPORTED_ATTACHMENTS: Incomplete
15
+ DEFAULT_THINKING_BUDGET: int
16
+ REQUIRE_THINKING_MODEL_PREFIX: Incomplete
17
+ IMAGE_GENERATION_MODELS: Incomplete
18
+ YOUTUBE_URL_PATTERN: Incomplete
19
+
20
+ class GoogleLMInvoker(BaseLMInvoker):
21
+ '''A language model invoker to interact with Google language models.
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
+ client_params (dict[str, Any]): The Google client instance init parameters.
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
+ generate_image (bool): Whether to generate image. Only allowed for image generation models.
35
+ thinking (bool): Whether to enable thinking. Only allowed for thinking models.
36
+ thinking_budget (int): The tokens allowed for thinking process. Only allowed for thinking models.
37
+ If set to -1, the model will control the budget automatically.
38
+
39
+ Basic usage:
40
+ The `GoogleLMInvoker` can be used as follows:
41
+ ```python
42
+ lm_invoker = GoogleLMInvoker(model_name="gemini-2.5-flash")
43
+ result = await lm_invoker.invoke("Hi there!")
44
+ ```
45
+
46
+ Authentication:
47
+ The `GoogleLMInvoker` can use either Google Gen AI or Google Vertex AI.
48
+
49
+ Google Gen AI is recommended for quick prototyping and development.
50
+ It requires a Gemini API key for authentication.
51
+
52
+ Usage example:
53
+ ```python
54
+ lm_invoker = GoogleLMInvoker(
55
+ model_name="gemini-2.5-flash",
56
+ api_key="your_api_key"
57
+ )
58
+ ```
59
+
60
+ Google Vertex AI is recommended to build production-ready applications.
61
+ It requires a service account JSON file for authentication.
62
+
63
+ Usage example:
64
+ ```python
65
+ lm_invoker = GoogleLMInvoker(
66
+ model_name="gemini-2.5-flash",
67
+ credentials_path="path/to/service_account.json"
68
+ )
69
+ ```
70
+
71
+ If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
72
+ The `GOOGLE_API_KEY` environment variable will be used for authentication.
73
+
74
+ Input types:
75
+ The `GoogleLMInvoker` supports the following input types: text, audio, document, image, and video.
76
+ Non-text inputs can be passed as an `Attachment` object with either the `user` or `assistant` role.
77
+
78
+ Usage example:
79
+ ```python
80
+ text = "What animal is in this image?"
81
+ image = Attachment.from_path("path/to/local/image.png")
82
+ result = await lm_invoker.invoke([text, image])
83
+ ```
84
+
85
+ Image generation:
86
+ The `GoogleLMInvoker` supports image generation. This can be done by using an image generation model,
87
+ such as `gemini-2.5-flash-image`. Streaming is disabled for image generation models.
88
+ The generated image will be stored in the `attachments` attribute in the output.
89
+
90
+ Usage example:
91
+ ```python
92
+ lm_invoker = GoogleLMInvoker("gemini-2.5-flash-image")
93
+ result = await lm_invoker.invoke("Create a picture...")
94
+ result.attachments[0].write_to_file("path/to/local/image.png")
95
+ ```
96
+
97
+ Output example:
98
+ ```python
99
+ LMOutput(
100
+ response="Let me call the tools...",
101
+ attachments=[Attachment(filename="image.png", mime_type="image/png", data=b"...")],
102
+ )
103
+ ```
104
+
105
+ Tool calling:
106
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
107
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
108
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
109
+ `tool_calls` attribute in the output.
110
+
111
+ Usage example:
112
+ ```python
113
+ lm_invoker = GoogleLMInvoker(..., tools=[tool_1, tool_2])
114
+ ```
115
+
116
+ Output example:
117
+ ```python
118
+ LMOutput(
119
+ response="Let me call the tools...",
120
+ tool_calls=[
121
+ ToolCall(id="123", name="tool_1", args={"key": "value"}),
122
+ ToolCall(id="456", name="tool_2", args={"key": "value"}),
123
+ ]
124
+ )
125
+ ```
126
+
127
+ Structured output:
128
+ Structured output is a feature that allows the language model to output a structured response.
129
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
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.
138
+
139
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
140
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
141
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
142
+
143
+ # Example 1: Using a JSON schema dictionary
144
+ Usage example:
145
+ ```python
146
+ schema = {
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)
157
+ ```
158
+ Output example:
159
+ ```python
160
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
161
+ ```
162
+
163
+ # Example 2: Using a Pydantic BaseModel class
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:
173
+ ```python
174
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
175
+ ```
176
+
177
+ Analytics tracking:
178
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
179
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
180
+ When enabled, the following attributes will be stored in the output:
181
+ 1. `token_usage`: The token usage.
182
+ 2. `duration`: The duration in seconds.
183
+ 3. `finish_details`: The details about how the generation finished.
184
+
185
+ Output example:
186
+ ```python
187
+ LMOutput(
188
+ response="Golden retriever is a good dog breed.",
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
+ ),
195
+ duration=0.729,
196
+ finish_details={"finish_reason": "STOP", "finish_message": None},
197
+ )
198
+ ```
199
+
200
+ Retry and timeout:
201
+ The `GoogleLMInvoker` supports retry and timeout configuration.
202
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
203
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
204
+
205
+ Retry config examples:
206
+ ```python
207
+ 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
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
211
+ ```
212
+
213
+ Usage example:
214
+ ```python
215
+ lm_invoker = GoogleLMInvoker(..., retry_config=retry_config)
216
+ ```
217
+
218
+ Thinking:
219
+ Thinking is a feature that allows the language model to have enhanced reasoning capabilities for complex tasks,
220
+ while also providing transparency into its step-by-step thought process before it delivers its final answer.
221
+ It can be enabled by setting the `thinking` parameter to `True`.
222
+
223
+ Thinking is only available for certain models, starting from Gemini 2.5 series, and is required for
224
+ Gemini 2.5 Pro models. Therefore, `thinking` defaults to `True` for Gemini 2.5 Pro models and `False`
225
+ for other models. Setting `thinking` to `False` for Gemini 2.5 Pro models will raise a `ValueError`.
226
+ When enabled, the reasoning is stored in the `reasoning` attribute in the output.
227
+
228
+ Usage example:
229
+ ```python
230
+ lm_invoker = GoogleLMInvoker(..., thinking=True, thinking_budget=1024)
231
+ ```
232
+
233
+ Output example:
234
+ ```python
235
+ LMOutput(
236
+ response="Golden retriever is a good dog breed.",
237
+ reasoning=[Reasoning(reasoning="Let me think about it...")],
238
+ )
239
+ ```
240
+
241
+ Streaming output example:
242
+ ```python
243
+ {"type": "thinking_start", "value": "", ...}
244
+ {"type": "thinking", "value": "Let me think "\', ...}
245
+ {"type": "thinking", "value": "about it...", ...}
246
+ {"type": "thinking_end", "value": ""}\', ...}
247
+ {"type": "response", "value": "Golden retriever ", ...}
248
+ {"type": "response", "value": "is a good dog breed.", ...}
249
+ ```
250
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
251
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
252
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
253
+
254
+ When thinking is enabled, the amount of tokens allocated for the thinking process can be set via the
255
+ `thinking_budget` parameter. The `thinking_budget`:
256
+ 1. Defaults to -1, in which case the model will control the budget automatically.
257
+ 2. Must be greater than the model\'s minimum thinking budget.
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])
272
+ '''
273
+ client_params: Incomplete
274
+ generate_image: Incomplete
275
+ thinking: Incomplete
276
+ thinking_budget: Incomplete
277
+ 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:
278
+ '''Initializes a new instance of the GoogleLMInvoker class.
279
+
280
+ Args:
281
+ model_name (str): The name of the model to use.
282
+ api_key (str | None, optional): Required for Google Gen AI authentication. Cannot be used together
283
+ with `credentials_path`. Defaults to None.
284
+ credentials_path (str | None, optional): Required for Google Vertex AI authentication. Path to the service
285
+ account credentials JSON file. Cannot be used together with `api_key`. Defaults to None.
286
+ project_id (str | None, optional): The Google Cloud project ID for Vertex AI. Only used when authenticating
287
+ with `credentials_path`. Defaults to None, in which case it will be loaded from the credentials file.
288
+ location (str, optional): The location of the Google Cloud project for Vertex AI. Only used when
289
+ authenticating with `credentials_path`. Defaults to "us-central1".
290
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Google Vertex AI
291
+ client.
292
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
293
+ Defaults to None.
294
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
295
+ Defaults to None.
296
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
297
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
298
+ dictionary. Defaults to None.
299
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
300
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
301
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
302
+ thinking (bool | None, optional): Whether to enable thinking. Only allowed for thinking models.
303
+ Defaults to True for Gemini 2.5 Pro models and False for other models.
304
+ thinking_budget (int, optional): The tokens allowed for thinking process. Only allowed for thinking models.
305
+ Defaults to -1, in which case the model will control the budget automatically.
306
+ simplify_events (bool, optional): Temporary parameter to control the streamed events format.
307
+ When True, uses the simplified events format. When False, uses the legacy events format for
308
+ backward compatibility. Will be removed in v0.6. Defaults to False.
309
+
310
+ Note:
311
+ If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
312
+ The `GOOGLE_API_KEY` environment variable will be used for authentication.
313
+ '''
314
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
315
+ """Sets the tools for the Google language model.
316
+
317
+ This method sets the tools for the Google language model. Any existing tools will be replaced.
318
+
319
+ Args:
320
+ tools (list[Tool | LangChainTool]): The list of tools to be used.
321
+
322
+ Raises:
323
+ ValueError: If `response_schema` exists.
324
+ """
325
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
326
+ """Sets the response schema for the Google language model.
327
+
328
+ This method sets the response schema for the Google language model. Any existing response schema will be
329
+ replaced.
330
+
331
+ Args:
332
+ response_schema (ResponseSchema | None): The response schema to be used.
333
+
334
+ Raises:
335
+ ValueError: If `tools` exists.
336
+ """
@@ -0,0 +1,251 @@
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
+ Tool calling:
82
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
83
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
84
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
85
+ `tool_calls` attribute in the output.
86
+
87
+ Usage example:
88
+ ```python
89
+ lm_invoker = LangChainLMInvoker(..., tools=[tool_1, tool_2])
90
+ ```
91
+
92
+ Output example:
93
+ ```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
+ )
101
+ ```
102
+
103
+ Structured output:
104
+ Structured output is a feature that allows the language model to output a structured response.
105
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
106
+
107
+ The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
108
+ If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
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.
114
+
115
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
116
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
117
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
118
+
119
+ # Example 1: Using a JSON schema dictionary
120
+ Usage example:
121
+ ```python
122
+ schema = {
123
+ "title": "Animal",
124
+ "description": "A description of an animal.",
125
+ "properties": {
126
+ "color": {"title": "Color", "type": "string"},
127
+ "name": {"title": "Name", "type": "string"},
128
+ },
129
+ "required": ["name", "color"],
130
+ "type": "object",
131
+ }
132
+ lm_invoker = LangChainLMInvoker(..., response_schema=schema)
133
+ ```
134
+ Output example:
135
+ ```python
136
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
137
+ ```
138
+
139
+ # Example 2: Using a Pydantic BaseModel class
140
+ Usage example:
141
+ ```python
142
+ class Animal(BaseModel):
143
+ name: str
144
+ color: str
145
+
146
+ lm_invoker = LangChainLMInvoker(..., response_schema=Animal)
147
+ ```
148
+ Output example:
149
+ ```python
150
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
151
+ ```
152
+
153
+ Analytics tracking:
154
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
155
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
156
+ When enabled, the following attributes will be stored in the output:
157
+ 1. `token_usage`: The token usage.
158
+ 2. `duration`: The duration in seconds.
159
+ 3. `finish_details`: The details about how the generation finished.
160
+
161
+ Output example:
162
+ ```python
163
+ LMOutput(
164
+ response="Golden retriever is a good dog breed.",
165
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
166
+ duration=0.729,
167
+ finish_details={"finish_reason": "stop"},
168
+ )
169
+ ```
170
+
171
+ Retry and timeout:
172
+ The `LangChainLMInvoker` supports retry and timeout configuration.
173
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
174
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
175
+
176
+ Retry config examples:
177
+ ```python
178
+ 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
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
182
+ ```
183
+
184
+ Usage example:
185
+ ```python
186
+ lm_invoker = LangChainLMInvoker(..., retry_config=retry_config)
187
+ ```
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
+ '''
200
+ model: Incomplete
201
+ 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:
202
+ '''Initializes a new instance of the LangChainLMInvoker class.
203
+
204
+ Args:
205
+ model (BaseChatModel | None, optional): The LangChain\'s BaseChatModel instance. If provided, will take
206
+ precedence over the `model_class_path` parameter. Defaults to None.
207
+ model_class_path (str | None, optional): The LangChain\'s BaseChatModel class path. Must be formatted as
208
+ "<package>.<class>" (e.g. "langchain_openai.ChatOpenAI"). Ignored if `model` is provided.
209
+ Defaults to None.
210
+ model_name (str | None, optional): The model name. Only used if `model_class_path` is provided.
211
+ Defaults to None.
212
+ model_kwargs (dict[str, Any] | None, optional): The additional keyword arguments. Only used if
213
+ `model_class_path` is provided. Defaults to None.
214
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
215
+ Defaults to None.
216
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
217
+ Defaults to None.
218
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
219
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
220
+ dictionary. Defaults to None.
221
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
222
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
223
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
224
+
225
+ Raises:
226
+ ValueError: If `response_schema` is provided, but `tools` are also provided.
227
+ '''
228
+ tools: Incomplete
229
+ def set_tools(self, tools: list[Tool | LangChainTool]) -> None:
230
+ """Sets the tools for LangChain's BaseChatModel.
231
+
232
+ This method sets the tools for LangChain's BaseChatModel. Any existing tools will be replaced.
233
+
234
+ Args:
235
+ tools (list[Tool]): The list of tools to be used.
236
+
237
+ Raises:
238
+ ValueError: If `response_schema` exists.
239
+ """
240
+ def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
241
+ """Sets the response schema for the LangChain's BaseChatModel.
242
+
243
+ This method sets the response schema for the LangChain's BaseChatModel. Any existing response schema will be
244
+ replaced.
245
+
246
+ Args:
247
+ response_schema (ResponseSchema | None): The response schema to be used.
248
+
249
+ Raises:
250
+ ValueError: If `tools` exists.
251
+ """