Skip to content

Commit 0412b4f

Browse files
fix(google-genai): Support larger range of temperatures for Gemini models (#7703)
Co-authored-by: Jacob Lee <[email protected]>
1 parent dd581e4 commit 0412b4f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface GoogleGenerativeAIChatInput
101101
/**
102102
* Controls the randomness of the output.
103103
*
104-
* Values can range from [0.0,1.0], inclusive. A value closer to 1.0
104+
* Values can range from [0.0,2.0], inclusive. A value closer to 2.0
105105
* will produce responses that are more varied and creative, while
106106
* a value closer to 0.0 will typically result in less surprising
107107
* responses from the model.
@@ -644,8 +644,8 @@ export class ChatGoogleGenerativeAI
644644
}
645645

646646
this.temperature = fields?.temperature ?? this.temperature;
647-
if (this.temperature && (this.temperature < 0 || this.temperature > 1)) {
648-
throw new Error("`temperature` must be in the range of [0.0,1.0]");
647+
if (this.temperature && (this.temperature < 0 || this.temperature > 2)) {
648+
throw new Error("`temperature` must be in the range of [0.0,2.0]");
649649
}
650650

651651
this.topP = fields?.topP ?? this.topP;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function extractKeys(obj: Record<string, any>, keys: string[] = []) {
2828
return keys;
2929
}
3030

31-
test("Google AI - `temperature` must be in range [0.0,1.0]", async () => {
31+
test("Google AI - `temperature` must be in range [0.0,2.0]", async () => {
3232
expect(
3333
() =>
3434
new ChatGoogleGenerativeAI({
@@ -38,7 +38,7 @@ test("Google AI - `temperature` must be in range [0.0,1.0]", async () => {
3838
expect(
3939
() =>
4040
new ChatGoogleGenerativeAI({
41-
temperature: 1.1,
41+
temperature: 2.1,
4242
})
4343
).toThrow();
4444
});

0 commit comments

Comments
 (0)