1+ import { getEnvironmentVariable } from "@langchain/core/utils/env" ;
12import { WebApiClient } from "../clients/index.js" ;
23import {
34 BaseChatGoogle ,
@@ -6,16 +7,40 @@ import {
67 getGoogleChatModelParams ,
78} from "./base.js" ;
89
10+ /**
11+ * Configuration parameters for the ChatGoogleGenerativeAI model.
12+ *
13+ * This interface extends the base Google chat model parameters and adds
14+ * specific configuration options for the Generative AI API.
15+ */
916export interface ChatGoogleGenerativeAIParams extends BaseChatGoogleParams {
17+ /**
18+ * Google API key for authentication with the Generative AI API.
19+ *
20+ * If not provided, the model will attempt to use the `GOOGLE_API_KEY`
21+ * environment variable. You can obtain an API key from the
22+ * [Google AI Studio](https://makersuite.google.com/app/apikey).
23+ */
1024 apiKey ?: string ;
25+
1126 /** @deprecated Import from `@langchain/google/node` to configure google auth options */
1227 authOptions ?: never ;
1328}
1429
30+ /**
31+ * Call options for the ChatGoogleGenerativeAI model.
32+ *
33+ * This interface extends the base Google chat model call options and provides
34+ * configuration for individual model invocations. These options can be passed
35+ * when calling methods like `invoke()`, `stream()`, or `batch()` to customize
36+ * the behavior of a specific request.
37+ */
1538export interface ChatGoogleGenerativeAICallOptions
1639 extends BaseChatGoogleCallOptions { }
1740
1841export class ChatGoogleGenerativeAI extends BaseChatGoogle < ChatGoogleGenerativeAICallOptions > {
42+ apiKey ?: string ;
43+
1944 _llmType ( ) {
2045 return "generativeai" ;
2146 }
@@ -34,39 +59,69 @@ export class ChatGoogleGenerativeAI extends BaseChatGoogle<ChatGoogleGenerativeA
3459 paramsArg ?: Omit < ChatGoogleGenerativeAIParams , "model" >
3560 ) {
3661 const params = getGoogleChatModelParams ( modelOrParams , paramsArg ) ;
62+ params . apiKey = params ?. apiKey ?? getEnvironmentVariable ( "GOOGLE_API_KEY" ) ;
3763 const apiClient = params ?. apiClient ?? new WebApiClient ( params ) ;
3864 super ( { ...params , apiClient } ) ;
65+
66+ this . apiKey = params . apiKey ;
3967 }
4068}
4169
70+ /**
71+ * Parameters for configuring the ChatGoogleVertexAI model.
72+ *
73+ * This interface extends the base Google chat model parameters and provides
74+ * configuration options specific to Google Vertex AI. These parameters are
75+ * used when instantiating a new ChatGoogleVertexAI instance.
76+ */
4277export interface ChatGoogleVertexAIParams extends BaseChatGoogleParams {
78+ /**
79+ * Google API key for authentication with the Vertex AI API.
80+ *
81+ * If not provided, the model will attempt to use the `GOOGLE_API_KEY`
82+ * environment variable. You can obtain an API key from the
83+ * [Google Cloud Console](https://console.cloud.google.com/).
84+ */
4385 apiKey ?: string ;
86+
4487 /** @deprecated Import from `@langchain/google/node` to configure google auth options */
4588 authOptions ?: never ;
4689}
4790
91+ /**
92+ * Call options for the ChatGoogleVertexAI model.
93+ *
94+ * This interface extends the base Google chat model call options and provides
95+ * configuration options that can be passed when invoking the ChatGoogleVertexAI model.
96+ * These options allow you to customize the behavior of individual model calls.
97+ */
4898export interface ChatGoogleVertexAICallOptions
4999 extends BaseChatGoogleCallOptions { }
50100
51101export class ChatGoogleVertexAI extends BaseChatGoogle < ChatGoogleVertexAICallOptions > {
102+ apiKey ?: string ;
103+
104+ _llmType ( ) {
105+ return "vertexai" ;
106+ }
107+
108+ getBaseUrl ( ) {
109+ return new URL (
110+ `https://aiplatform.googleapis.com/v1/publishers/google/models/`
111+ ) ;
112+ }
113+
52114 constructor ( model : string , params ?: Omit < ChatGoogleVertexAIParams , "model" > ) ;
53115 constructor ( params : ChatGoogleVertexAIParams ) ;
54116 constructor (
55117 modelOrParams : string | ChatGoogleVertexAIParams ,
56118 paramsArg ?: Omit < ChatGoogleVertexAIParams , "model" >
57119 ) {
58120 const params = getGoogleChatModelParams ( modelOrParams , paramsArg ) ;
121+ params . apiKey = params ?. apiKey ?? getEnvironmentVariable ( "GOOGLE_API_KEY" ) ;
59122 const apiClient = params ?. apiClient ?? new WebApiClient ( params ) ;
60123 super ( { ...params , apiClient } ) ;
61- }
62124
63- _llmType ( ) {
64- return "vertexai" ;
65- }
66-
67- getBaseUrl ( ) {
68- return new URL (
69- `https://aiplatform.googleapis.com/v1/publishers/google/models/`
70- ) ;
125+ this . apiKey = params . apiKey ;
71126 }
72127}
0 commit comments