Skip to content

fix(google-genai): Support larger range of temperatures for Gemini models #7703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libs/langchain-google-genai/src/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export interface GoogleGenerativeAIChatInput
/**
* Controls the randomness of the output.
*
* Values can range from [0.0,1.0], inclusive. A value closer to 1.0
* Values can range from [0.0,2.0], inclusive. A value closer to 2.0
* will produce responses that are more varied and creative, while
* a value closer to 0.0 will typically result in less surprising
* responses from the model.
Expand Down Expand Up @@ -644,8 +644,8 @@ export class ChatGoogleGenerativeAI
}

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

this.topP = fields?.topP ?? this.topP;
Expand Down
4 changes: 2 additions & 2 deletions libs/langchain-google-genai/src/tests/chat_models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function extractKeys(obj: Record<string, any>, keys: string[] = []) {
return keys;
}

test("Google AI - `temperature` must be in range [0.0,1.0]", async () => {
test("Google AI - `temperature` must be in range [0.0,2.0]", async () => {
expect(
() =>
new ChatGoogleGenerativeAI({
Expand All @@ -38,7 +38,7 @@ test("Google AI - `temperature` must be in range [0.0,1.0]", async () => {
expect(
() =>
new ChatGoogleGenerativeAI({
temperature: 1.1,
temperature: 2.1,
})
).toThrow();
});
Expand Down
Loading