Skip to content

Commit ad1dc8a

Browse files
@langchain/google-genai [feature]: support Google genai API version and base URL (#5426)
* feat: support Google genai API version and base URL * run lint n format --------- Co-authored-by: Brace Sproul <[email protected]>
1 parent 561b271 commit ad1dc8a

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

libs/langchain-google-genai/src/chat_models.ts

+31-11
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ export interface GoogleGenerativeAIChatInput extends BaseChatModelParams {
114114
*/
115115
apiKey?: string;
116116

117+
/**
118+
* Google API version to use
119+
*/
120+
apiVersion?: string;
121+
122+
/**
123+
* Google API base URL to use
124+
*/
125+
baseUrl?: string;
126+
117127
/** Whether to stream the results or not */
118128
streaming?: boolean;
119129
}
@@ -181,6 +191,10 @@ export class ChatGoogleGenerativeAI
181191

182192
apiKey?: string;
183193

194+
apiVersion?: string = "v1";
195+
196+
baseUrl?: string = "https://generativeai.googleapis.com";
197+
184198
streaming = false;
185199

186200
private client: GenerativeModel;
@@ -249,18 +263,24 @@ export class ChatGoogleGenerativeAI
249263

250264
this.streaming = fields?.streaming ?? this.streaming;
251265

252-
this.client = new GenerativeAI(this.apiKey).getGenerativeModel({
253-
model: this.model,
254-
safetySettings: this.safetySettings as SafetySetting[],
255-
generationConfig: {
256-
candidateCount: 1,
257-
stopSequences: this.stopSequences,
258-
maxOutputTokens: this.maxOutputTokens,
259-
temperature: this.temperature,
260-
topP: this.topP,
261-
topK: this.topK,
266+
this.client = new GenerativeAI(this.apiKey).getGenerativeModel(
267+
{
268+
model: this.model,
269+
safetySettings: this.safetySettings as SafetySetting[],
270+
generationConfig: {
271+
candidateCount: 1,
272+
stopSequences: this.stopSequences,
273+
maxOutputTokens: this.maxOutputTokens,
274+
temperature: this.temperature,
275+
topP: this.topP,
276+
topK: this.topK,
277+
},
262278
},
263-
});
279+
{
280+
apiVersion: this.apiVersion,
281+
baseUrl: this.baseUrl,
282+
}
283+
);
264284
}
265285

266286
_combineLLMOutput() {

0 commit comments

Comments
 (0)