Google lm invoker
Defines a module to interact with Google language models.
GoogleLMInvoker(model_name, api_key=None, credentials_path=None, project_id=None, location='us-central1', model_kwargs=None, default_hyperparameters=None, tools=None, response_schema=None, output_analytics=False, retry_config=None, thinking=None, data_stores=None, auto_upload=True, input_transformer=InputTransformerType.IDENTITY, output_transformer=OutputTransformerType.IDENTITY)
Bases: BaseLMInvoker
A language model invoker to interact with Google language models.
Examples:
lm_invoker = GoogleLMInvoker(model_name="gemini-2.5-flash")
result = await lm_invoker.invoke("Hi there!")
Authentication
The GoogleLMInvoker can use either Google Gen AI or Google Vertex AI.
Google Gen AI is recommended for quick prototyping and development. It requires a Gemini API key for authentication.
Usage example:
lm_invoker = GoogleLMInvoker(
model_name="gemini-2.5-flash",
api_key="your_api_key"
)
Google Vertex AI is recommended to build production-ready applications. It requires a service account JSON file for authentication.
Usage example:
lm_invoker = GoogleLMInvoker(
model_name="gemini-2.5-flash",
credentials_path="path/to/service_account.json"
)
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
Supported features
- Basic invocation
- Streaming output
- Message roles
- Multimodal input a. Text b. Audio c. Document d. Image e. Video
- Structured output
- Tool calling
- Native tools a. Code interpreter b. Data store c. Image generation d. Web search
- Thinking
- Output analytics
- Retry and timeout
- Extra capabilities a. Input transformer b. Output transformer c. Batch invocation d. File management e. Data store management
For full documentation and examples, please refer to the LM Invoker tutorial: https://gdplabs.gitbook.io/sdk/gen-ai-sdk/tutorials/inference/lm-invoker
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
The model ID of the language model. |
model_provider |
str
|
The provider of the language model. |
model_name |
str
|
The name of the language model. |
client_params |
dict[str, Any]
|
The Google client instance init parameters. |
default_config |
dict[str, Any]
|
Default config for invoking the model. |
tools |
list[Tool]
|
The list of tools provided to the model to enable tool calling. |
response_schema |
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. |
output_analytics |
bool
|
Whether to output the invocation analytics. |
retry_config |
RetryConfig | None
|
The retry configuration for the language model. |
thinking |
ThinkingConfig
|
The thinking configuration for the language model. |
image_generation |
bool
|
Whether to generate image. Only allowed for image generation models. |
data_stores |
list[AttachmentStore]
|
The data stores to retrieve internal knowledge from. |
auto_upload |
bool
|
Whether to automatically upload attachments to files API if the inputs total size exceeds the threshold of 20MB. |
input_transformer |
InputTransformerType
|
The type of input transformer to use. |
output_transformer |
OutputTransformerType
|
The type of output transformer to use. |
Initializes a new instance of the GoogleLMInvoker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the model to use. |
required |
api_key
|
str | None
|
Required for Google Gen AI authentication. Cannot be used together
with |
None
|
credentials_path
|
str | None
|
Required for Google Vertex AI authentication. Path to the service
account credentials JSON file. Cannot be used together with |
None
|
project_id
|
str | None
|
The Google Cloud project ID for Vertex AI. Only used when authenticating
with |
None
|
location
|
str
|
The location of the Google Cloud project for Vertex AI. Only used when
authenticating with |
'us-central1'
|
model_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments for the Google Vertex AI client. |
None
|
default_hyperparameters
|
dict[str, Any] | None
|
Default hyperparameters for invoking the model. Defaults to None. |
None
|
tools
|
list[LMTool] | None
|
Tools provided to the model to enable tool calling. Defaults to None. |
None
|
response_schema
|
ResponseSchema | None
|
The schema of the response. If provided, the model will output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary. Defaults to None. |
None
|
output_analytics
|
bool
|
Whether to output the invocation analytics. Defaults to False. |
False
|
retry_config
|
RetryConfig | None
|
The retry configuration for the language model. Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used. |
None
|
thinking
|
bool | ThinkingConfig | None
|
A boolean or ThinkingConfig object to configure thinking. Defaults to None. |
None
|
data_stores
|
list[AttachmentStore] | None
|
The data stores to retrieve internal knowledge from. Defaults to None, in which case no data stores will be used. |
None
|
auto_upload
|
bool
|
Whether to automatically upload attachments to files API if the inputs total size exceeds the threshold of 20MB. Defaults to True. |
True
|
input_transformer
|
InputTransformerType
|
The type of input transformer to use. Defaults to InputTransformerType.IDENTITY, which returns the input without transformation. |
IDENTITY
|
output_transformer
|
OutputTransformerType
|
The type of output transformer to use. Defaults to OutputTransformerType.IDENTITY, which returns the output without transformation. |
IDENTITY
|
Note
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
batch
cached
property
The batch operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
GoogleBatchOperations |
GoogleBatchOperations
|
The batch operations for the language model. |
data_store
cached
property
The data store operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
GoogleDataStoreOperations |
GoogleDataStoreOperations
|
The data store operations for the language model. |
file
cached
property
The file operations for the language model.
Returns:
| Name | Type | Description |
|---|---|---|
GoogleFileOperations |
GoogleFileOperations
|
The file operations for the language model. |
set_data_stores(data_stores)
Sets the data stores for the Google language model.
This method sets the data stores for the Google language model. Any existing data stores will be replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_stores
|
list[AttachmentStore]
|
The list of data stores to be used. |
required |
URLPattern
Defines specific Google related URL patterns.