Support custom base URL for ChatGoogleGenerativeAI (#4347)

feat: Support custom base URL for ChatGoogleGenerativeAI
This commit is contained in:
Hans
2025-04-27 12:15:17 +08:00
committed by GitHub
parent ac0450523a
commit fc6eea7653
2 changed files with 29 additions and 12 deletions
@@ -81,6 +81,8 @@ class LangchainChatGoogleGenerativeAI
apiKey?: string
baseUrl?: string
streaming = false
streamUsage = true
@@ -151,19 +153,24 @@ class LangchainChatGoogleGenerativeAI
}
async getClient(prompt?: Content[], tools?: Tool[]) {
this.client = new GenerativeAI(this.apiKey ?? '').getGenerativeModel({
model: this.modelName,
tools,
safetySettings: this.safetySettings as SafetySetting[],
generationConfig: {
candidateCount: 1,
stopSequences: this.stopSequences,
maxOutputTokens: this.maxOutputTokens,
temperature: this.temperature,
topP: this.topP,
topK: this.topK
this.client = new GenerativeAI(this.apiKey ?? '').getGenerativeModel(
{
model: this.modelName,
tools,
safetySettings: this.safetySettings as SafetySetting[],
generationConfig: {
candidateCount: 1,
stopSequences: this.stopSequences,
maxOutputTokens: this.maxOutputTokens,
temperature: this.temperature,
topP: this.topP,
topK: this.topK
}
},
{
baseUrl: this.baseUrl
}
})
)
if (this.contextCache) {
const cachedContent = await this.contextCache.lookup({
contents: prompt ? [{ ...prompt[0], parts: prompt[0].parts.slice(0, 1) }] : [],