From b393bec81bdcebcc8bd54ac8db7e1738047c7376 Mon Sep 17 00:00:00 2001 From: Guiners Date: Mon, 11 Aug 2025 16:52:10 +0200 Subject: [PATCH 1/9] adding samples, test, lints --- genai/test/thinking-budget-with-txt.test.js | 29 ++++++++++ .../thinking-includethoughts-with-txt.test.js | 29 ++++++++++ genai/test/thinking-with-txt.test.js | 29 ++++++++++ genai/thinking/thinking-budget-with-txt.js | 51 +++++++++++++++++ .../thinking-includethoughts-with-txt.js | 57 +++++++++++++++++++ genai/thinking/thinking-with-txt.js | 46 +++++++++++++++ 6 files changed, 241 insertions(+) create mode 100644 genai/test/thinking-budget-with-txt.test.js create mode 100644 genai/test/thinking-includethoughts-with-txt.test.js create mode 100644 genai/test/thinking-with-txt.test.js create mode 100644 genai/thinking/thinking-budget-with-txt.js create mode 100644 genai/thinking/thinking-includethoughts-with-txt.js create mode 100644 genai/thinking/thinking-with-txt.js diff --git a/genai/test/thinking-budget-with-txt.test.js b/genai/test/thinking-budget-with-txt.test.js new file mode 100644 index 0000000000..05818e9d90 --- /dev/null +++ b/genai/test/thinking-budget-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../thinking/thinking-budget-with-txt.js'); + +describe('thinking-budget-with-txt', async () => { + it('should return Thought Process', async function () { + this.timeout(50000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/test/thinking-includethoughts-with-txt.test.js b/genai/test/thinking-includethoughts-with-txt.test.js new file mode 100644 index 0000000000..7f76664469 --- /dev/null +++ b/genai/test/thinking-includethoughts-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../thinking/thinking-includethoughts-with-txt.js'); + +describe('thinking-includethoughts-with-txt', async () => { + it('should return Thought Process ', async function () { + this.timeout(50000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/test/thinking-with-txt.test.js b/genai/test/thinking-with-txt.test.js new file mode 100644 index 0000000000..69637860f8 --- /dev/null +++ b/genai/test/thinking-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); + +const projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../thinking/thinking-with-txt.js'); + +describe('thinking-with-txt', async () => { + it('should return Thought Process', async function () { + this.timeout(50000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/thinking/thinking-budget-with-txt.js b/genai/thinking/thinking-budget-with-txt.js new file mode 100644 index 0000000000..948fb89ee8 --- /dev/null +++ b/genai/thinking/thinking-budget-with-txt.js @@ -0,0 +1,51 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +// [START googlegenaisdk_thinking_budget_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: 'solve x^2 + 4x + 4 = 0', + config: { + thinkingConfig: { + thinkingBudget: 1024, + }, + }, + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_thinking_budget_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/thinking/thinking-includethoughts-with-txt.js b/genai/thinking/thinking-includethoughts-with-txt.js new file mode 100644 index 0000000000..09b63e9be1 --- /dev/null +++ b/genai/thinking/thinking-includethoughts-with-txt.js @@ -0,0 +1,57 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +// [START googlegenaisdk_thinking_includethoughts_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-pro', + contents: 'solve x^2 + 4x + 4 = 0', + config: { + thinkingConfig: { + includeThoughts: true, + }, + }, + }); + + console.log(response.text); + + for (const part of response.candidates[0].content.parts) { + if (part && part.thought) { + console.log(part.text); + } + } + + return response.text; +} +// [END googlegenaisdk_thinking_includethoughts_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/thinking/thinking-with-txt.js b/genai/thinking/thinking-with-txt.js new file mode 100644 index 0000000000..e1b966db88 --- /dev/null +++ b/genai/thinking/thinking-with-txt.js @@ -0,0 +1,46 @@ +// Copyright 2025 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +// [START googlegenaisdk_thinking_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-pro', + contents: 'solve x^2 + 4x + 4 = 0', + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_thinking_with_txt] + +module.exports = { + generateContent, +}; From 6780e2aa95542198f895940cafa58a6305bd87f1 Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 20 Aug 2025 13:04:13 +0200 Subject: [PATCH 2/9] adding samples, test, lints --- genai/thinking/thinking-budget-with-txt.js | 18 +++++++ .../thinking-includethoughts-with-txt.js | 41 ++++++++++++++- genai/thinking/thinking-with-txt.js | 51 +++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/genai/thinking/thinking-budget-with-txt.js b/genai/thinking/thinking-budget-with-txt.js index 948fb89ee8..d5efbc94cc 100644 --- a/genai/thinking/thinking-budget-with-txt.js +++ b/genai/thinking/thinking-budget-with-txt.js @@ -41,7 +41,25 @@ async function generateContent( }); console.log(response.text); + // Example response: + // To solve the equation $x^2 + 4x + 4 = 0$, you can use several methods: + // **Method 1: Factoring** + // 1. Look for two numbers that multiply to the constant term (4) and add up to the coefficient of the $x$ term (4). + // 2. The numbers are 2 and 2 ($2 \times 2 = 4$ and $2 + 2 = 4$). + // ... + // ... + // All three methods yield the same solution. This quadratic equation has exactly one distinct solution (a repeated root). + // The solution is **x = -2**. + // Token count for `Thinking` + console.log(response.usageMetadata.thoughtsTokenCount); + // Example response: + // 886 + + // Total token count + console.log(response.usageMetadata.totalTokenCount); + // Example response: + // 1525 return response.text; } // [END googlegenaisdk_thinking_budget_with_txt] diff --git a/genai/thinking/thinking-includethoughts-with-txt.js b/genai/thinking/thinking-includethoughts-with-txt.js index 09b63e9be1..f4dc68aad6 100644 --- a/genai/thinking/thinking-includethoughts-with-txt.js +++ b/genai/thinking/thinking-includethoughts-with-txt.js @@ -41,13 +41,52 @@ async function generateContent( }); console.log(response.text); + // Example Response: + // Okay, let's solve the quadratic equation x² + 4x + 4 = 0. + // ... + // **Answer:** + // The solution to the equation x² + 4x + 4 = 0 is x = -2. This is a repeated root (or a root with multiplicity 2). for (const part of response.candidates[0].content.parts) { if (part && part.thought) { console.log(part.text); } } - + // Example Response: + // **My Thought Process for Solving the Quadratic Equation** + // + // Alright, let's break down this quadratic, x² + 4x + 4 = 0. First things first: + // it's a quadratic; the x² term gives it away, and we know the general form is + // ax² + bx + c = 0. + // + // So, let's identify the coefficients: a = 1, b = 4, and c = 4. Now, what's the + // most efficient path to the solution? My gut tells me to try factoring; it's + // often the fastest route if it works. If that fails, I'll default to the quadratic + // formula, which is foolproof. Completing the square? It's good for deriving the + // formula or when factoring is difficult, but not usually my first choice for + // direct solving, but it can't hurt to keep it as an option. + // + // Factoring, then. I need to find two numbers that multiply to 'c' (4) and add + // up to 'b' (4). Let's see... 1 and 4 don't work (add up to 5). 2 and 2? Bingo! + // They multiply to 4 and add up to 4. This means I can rewrite the equation as + // (x + 2)(x + 2) = 0, or more concisely, (x + 2)² = 0. Solving for x is now + // trivial: x + 2 = 0, thus x = -2. + // + // Okay, just to be absolutely certain, I'll run the quadratic formula just to + // double-check. x = [-b ± √(b² - 4ac)] / 2a. Plugging in the values, x = [-4 ± + // √(4² - 4 * 1 * 4)] / (2 * 1). That simplifies to x = [-4 ± √0] / 2. So, x = + // -2 again – a repeated root. Nice. + // + // Now, let's check via completing the square. Starting from the same equation, + // (x² + 4x) = -4. Take half of the b-value (4/2 = 2), square it (2² = 4), and + // add it to both sides, so x² + 4x + 4 = -4 + 4. Which simplifies into (x + 2)² + // = 0. The square root on both sides gives us x + 2 = 0, therefore x = -2, as + // expected. + // + // Always, *always* confirm! Let's substitute x = -2 back into the original + // equation: (-2)² + 4(-2) + 4 = 0. That's 4 - 8 + 4 = 0. It checks out. + // + // Conclusion: the solution is x = -2. Confirmed. return response.text; } // [END googlegenaisdk_thinking_includethoughts_with_txt] diff --git a/genai/thinking/thinking-with-txt.js b/genai/thinking/thinking-with-txt.js index e1b966db88..d39ebad265 100644 --- a/genai/thinking/thinking-with-txt.js +++ b/genai/thinking/thinking-with-txt.js @@ -39,6 +39,57 @@ async function generateContent( return response.text; } +// Example Response: +// Okay, let's solve the quadratic equation x² + 4x + 4 = 0. +// +// We can solve this equation by factoring, using the quadratic formula, +// or by recognizing it as a perfect square trinomial. +// +// **Method 1: Factoring** +// +// 1. We need two numbers that multiply to the constant term (4) +// and add up to the coefficient of the x term (4). +// 2. The numbers 2 and 2 satisfy these conditions: 2 * 2 = 4 and 2 + 2 = 4. +// 3. So, we can factor the quadratic as: +// (x + 2)(x + 2) = 0 +// or +// (x + 2)² = 0 +// 4. For the product to be zero, the factor must be zero: +// x + 2 = 0 +// 5. Solve for x: +// x = -2 +// +// **Method 2: Quadratic Formula** +// +// The quadratic formula for an equation ax² + bx + c = 0 is: +// x = [-b ± sqrt(b² - 4ac)] / (2a) +// +// 1. In our equation x² + 4x + 4 = 0, we have a = 1, b = 4, and c = 4. +// 2. Substitute these values into the formula: +// x = [-4 ± sqrt(4² - 4 * 1 * 4)] / (2 * 1) +// x = [-4 ± sqrt(16 - 16)] / 2 +// x = [-4 ± sqrt(0)] / 2 +// x = [-4 ± 0] / 2 +// x = -4 / 2 +// x = -2 +// +// **Method 3: Perfect Square Trinomial** +// +// 1. Notice that the expression x² + 4x + 4 fits the pattern of a perfect square trinomial: +// a² + 2ab + b², where a = x and b = 2. +// 2. We can rewrite the equation as: +// (x + 2)² = 0 +// 3. Take the square root of both sides: +// x + 2 = 0 +// 4. Solve for x: +// x = -2 +// +// All methods lead to the same solution. +// +// **Answer:** +// The solution to the equation x² + 4x + 4 = 0 is x = -2. +// This is a repeated root (or a root with multiplicity 2). + // [END googlegenaisdk_thinking_with_txt] module.exports = { From 99dd8a5622c3dbd189beffab5faf98fa066132bb Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:23:07 +0200 Subject: [PATCH 3/9] Update genai/test/thinking-includethoughts-with-txt.test.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- genai/test/thinking-includethoughts-with-txt.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/thinking-includethoughts-with-txt.test.js b/genai/test/thinking-includethoughts-with-txt.test.js index 7f76664469..97f18d4fc0 100644 --- a/genai/test/thinking-includethoughts-with-txt.test.js +++ b/genai/test/thinking-includethoughts-with-txt.test.js @@ -21,7 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../thinking/thinking-includethoughts-with-txt.js'); describe('thinking-includethoughts-with-txt', async () => { - it('should return Thought Process ', async function () { + it('should return Thought Process', async function () { this.timeout(50000); const output = await sample.generateContent(projectId); assert(output.length > 0); From 257ed125292b925654bc6eb1749fda7687fed002 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:27:22 +0200 Subject: [PATCH 4/9] Update genai/test/thinking-budget-with-txt.test.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- genai/test/thinking-budget-with-txt.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/thinking-budget-with-txt.test.js b/genai/test/thinking-budget-with-txt.test.js index 05818e9d90..6d8901d074 100644 --- a/genai/test/thinking-budget-with-txt.test.js +++ b/genai/test/thinking-budget-with-txt.test.js @@ -20,7 +20,7 @@ const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../thinking/thinking-budget-with-txt.js'); -describe('thinking-budget-with-txt', async () => { +describe('thinking-budget-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); const output = await sample.generateContent(projectId); From aaaebee236e1d5faf8613d0bf4b7db2b6f656ff5 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:27:29 +0200 Subject: [PATCH 5/9] Update genai/test/thinking-with-txt.test.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- genai/test/thinking-with-txt.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/thinking-with-txt.test.js b/genai/test/thinking-with-txt.test.js index 69637860f8..af6277a4bd 100644 --- a/genai/test/thinking-with-txt.test.js +++ b/genai/test/thinking-with-txt.test.js @@ -20,7 +20,7 @@ const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../thinking/thinking-with-txt.js'); -describe('thinking-with-txt', async () => { +describe('thinking-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); const output = await sample.generateContent(projectId); From 6d3ba66029b5084a7dab748e8ff24e1a893d6608 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:27:36 +0200 Subject: [PATCH 6/9] Update genai/test/thinking-includethoughts-with-txt.test.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- genai/test/thinking-includethoughts-with-txt.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/thinking-includethoughts-with-txt.test.js b/genai/test/thinking-includethoughts-with-txt.test.js index 97f18d4fc0..51826a7551 100644 --- a/genai/test/thinking-includethoughts-with-txt.test.js +++ b/genai/test/thinking-includethoughts-with-txt.test.js @@ -20,7 +20,7 @@ const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../thinking/thinking-includethoughts-with-txt.js'); -describe('thinking-includethoughts-with-txt', async () => { +describe('thinking-includethoughts-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); const output = await sample.generateContent(projectId); From 45650cfec005b8acbb580475fad1a06ee9cacb63 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 4 Sep 2025 11:04:36 +0200 Subject: [PATCH 7/9] adding samples, test, lints --- .../thinking-includethoughts-with-txt.js | 2 + genai/thinking/thinking-with-txt.js | 101 +++++++++--------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/genai/thinking/thinking-includethoughts-with-txt.js b/genai/thinking/thinking-includethoughts-with-txt.js index f4dc68aad6..c951ae8a9c 100644 --- a/genai/thinking/thinking-includethoughts-with-txt.js +++ b/genai/thinking/thinking-includethoughts-with-txt.js @@ -52,6 +52,7 @@ async function generateContent( console.log(part.text); } } + // Example Response: // **My Thought Process for Solving the Quadratic Equation** // @@ -87,6 +88,7 @@ async function generateContent( // equation: (-2)² + 4(-2) + 4 = 0. That's 4 - 8 + 4 = 0. It checks out. // // Conclusion: the solution is x = -2. Confirmed. + return response.text; } // [END googlegenaisdk_thinking_includethoughts_with_txt] diff --git a/genai/thinking/thinking-with-txt.js b/genai/thinking/thinking-with-txt.js index d39ebad265..3c97150cf2 100644 --- a/genai/thinking/thinking-with-txt.js +++ b/genai/thinking/thinking-with-txt.js @@ -37,58 +37,59 @@ async function generateContent( console.log(response.text); + // Example Response: + // Okay, let's solve the quadratic equation x² + 4x + 4 = 0. + // + // We can solve this equation by factoring, using the quadratic formula, + // or by recognizing it as a perfect square trinomial. + // + // **Method 1: Factoring** + // + // 1. We need two numbers that multiply to the constant term (4) + // and add up to the coefficient of the x term (4). + // 2. The numbers 2 and 2 satisfy these conditions: 2 * 2 = 4 and 2 + 2 = 4. + // 3. So, we can factor the quadratic as: + // (x + 2)(x + 2) = 0 + // or + // (x + 2)² = 0 + // 4. For the product to be zero, the factor must be zero: + // x + 2 = 0 + // 5. Solve for x: + // x = -2 + // + // **Method 2: Quadratic Formula** + // + // The quadratic formula for an equation ax² + bx + c = 0 is: + // x = [-b ± sqrt(b² - 4ac)] / (2a) + // + // 1. In our equation x² + 4x + 4 = 0, we have a = 1, b = 4, and c = 4. + // 2. Substitute these values into the formula: + // x = [-4 ± sqrt(4² - 4 * 1 * 4)] / (2 * 1) + // x = [-4 ± sqrt(16 - 16)] / 2 + // x = [-4 ± sqrt(0)] / 2 + // x = [-4 ± 0] / 2 + // x = -4 / 2 + // x = -2 + // + // **Method 3: Perfect Square Trinomial** + // + // 1. Notice that the expression x² + 4x + 4 fits the pattern of a perfect square trinomial: + // a² + 2ab + b², where a = x and b = 2. + // 2. We can rewrite the equation as: + // (x + 2)² = 0 + // 3. Take the square root of both sides: + // x + 2 = 0 + // 4. Solve for x: + // x = -2 + // + // All methods lead to the same solution. + // + // **Answer:** + // The solution to the equation x² + 4x + 4 = 0 is x = -2. + // This is a repeated root (or a root with multiplicity 2). + return response.text; } -// Example Response: -// Okay, let's solve the quadratic equation x² + 4x + 4 = 0. -// -// We can solve this equation by factoring, using the quadratic formula, -// or by recognizing it as a perfect square trinomial. -// -// **Method 1: Factoring** -// -// 1. We need two numbers that multiply to the constant term (4) -// and add up to the coefficient of the x term (4). -// 2. The numbers 2 and 2 satisfy these conditions: 2 * 2 = 4 and 2 + 2 = 4. -// 3. So, we can factor the quadratic as: -// (x + 2)(x + 2) = 0 -// or -// (x + 2)² = 0 -// 4. For the product to be zero, the factor must be zero: -// x + 2 = 0 -// 5. Solve for x: -// x = -2 -// -// **Method 2: Quadratic Formula** -// -// The quadratic formula for an equation ax² + bx + c = 0 is: -// x = [-b ± sqrt(b² - 4ac)] / (2a) -// -// 1. In our equation x² + 4x + 4 = 0, we have a = 1, b = 4, and c = 4. -// 2. Substitute these values into the formula: -// x = [-4 ± sqrt(4² - 4 * 1 * 4)] / (2 * 1) -// x = [-4 ± sqrt(16 - 16)] / 2 -// x = [-4 ± sqrt(0)] / 2 -// x = [-4 ± 0] / 2 -// x = -4 / 2 -// x = -2 -// -// **Method 3: Perfect Square Trinomial** -// -// 1. Notice that the expression x² + 4x + 4 fits the pattern of a perfect square trinomial: -// a² + 2ab + b², where a = x and b = 2. -// 2. We can rewrite the equation as: -// (x + 2)² = 0 -// 3. Take the square root of both sides: -// x + 2 = 0 -// 4. Solve for x: -// x = -2 -// -// All methods lead to the same solution. -// -// **Answer:** -// The solution to the equation x² + 4x + 4 = 0 is x = -2. -// This is a repeated root (or a root with multiplicity 2). // [END googlegenaisdk_thinking_with_txt] From a74be4289ad005aed4eb89ffb4f9eb3d0bd279ba Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 5 Sep 2025 10:26:42 +0200 Subject: [PATCH 8/9] adding samples, test, lints --- genai/thinking/thinking-budget-with-txt.js | 4 ++-- genai/thinking/thinking-includethoughts-with-txt.js | 4 ++-- genai/thinking/thinking-with-txt.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/genai/thinking/thinking-budget-with-txt.js b/genai/thinking/thinking-budget-with-txt.js index d5efbc94cc..ab1b1e6f71 100644 --- a/genai/thinking/thinking-budget-with-txt.js +++ b/genai/thinking/thinking-budget-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'solve x^2 + 4x + 4 = 0', config: { diff --git a/genai/thinking/thinking-includethoughts-with-txt.js b/genai/thinking/thinking-includethoughts-with-txt.js index c951ae8a9c..158af17aea 100644 --- a/genai/thinking/thinking-includethoughts-with-txt.js +++ b/genai/thinking/thinking-includethoughts-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-pro', contents: 'solve x^2 + 4x + 4 = 0', config: { diff --git a/genai/thinking/thinking-with-txt.js b/genai/thinking/thinking-with-txt.js index 3c97150cf2..3b727abc9e 100644 --- a/genai/thinking/thinking-with-txt.js +++ b/genai/thinking/thinking-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-pro', contents: 'solve x^2 + 4x + 4 = 0', }); From 2b62432a9e4ae498e2ea0430c1eef42c83966b02 Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 10 Sep 2025 10:52:47 +0200 Subject: [PATCH 9/9] fixing functions names --- genai/test/thinking-budget-with-txt.test.js | 2 +- genai/test/thinking-includethoughts-with-txt.test.js | 2 +- genai/test/thinking-with-txt.test.js | 2 +- genai/thinking/thinking-budget-with-txt.js | 4 ++-- genai/thinking/thinking-includethoughts-with-txt.js | 4 ++-- genai/thinking/thinking-with-txt.js | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/genai/test/thinking-budget-with-txt.test.js b/genai/test/thinking-budget-with-txt.test.js index 6d8901d074..5daaa2997f 100644 --- a/genai/test/thinking-budget-with-txt.test.js +++ b/genai/test/thinking-budget-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../thinking/thinking-budget-with-txt.js'); describe('thinking-budget-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); - const output = await sample.generateContent(projectId); + const output = await sample.generateWithThoughts(projectId); assert(output.length > 0); }); }); diff --git a/genai/test/thinking-includethoughts-with-txt.test.js b/genai/test/thinking-includethoughts-with-txt.test.js index 51826a7551..69a8a32800 100644 --- a/genai/test/thinking-includethoughts-with-txt.test.js +++ b/genai/test/thinking-includethoughts-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../thinking/thinking-includethoughts-with-txt.js'); describe('thinking-includethoughts-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); - const output = await sample.generateContent(projectId); + const output = await sample.generateWithThoughts(projectId); assert(output.length > 0); }); }); diff --git a/genai/test/thinking-with-txt.test.js b/genai/test/thinking-with-txt.test.js index af6277a4bd..0ed201f75a 100644 --- a/genai/test/thinking-with-txt.test.js +++ b/genai/test/thinking-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../thinking/thinking-with-txt.js'); describe('thinking-with-txt', () => { it('should return Thought Process', async function () { this.timeout(50000); - const output = await sample.generateContent(projectId); + const output = await sample.generateWithThoughts(projectId); assert(output.length > 0); }); }); diff --git a/genai/thinking/thinking-budget-with-txt.js b/genai/thinking/thinking-budget-with-txt.js index ab1b1e6f71..879ac159e2 100644 --- a/genai/thinking/thinking-budget-with-txt.js +++ b/genai/thinking/thinking-budget-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateWithThoughts( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -65,5 +65,5 @@ async function generateContent( // [END googlegenaisdk_thinking_budget_with_txt] module.exports = { - generateContent, + generateWithThoughts, }; diff --git a/genai/thinking/thinking-includethoughts-with-txt.js b/genai/thinking/thinking-includethoughts-with-txt.js index 158af17aea..ff0b5e7fef 100644 --- a/genai/thinking/thinking-includethoughts-with-txt.js +++ b/genai/thinking/thinking-includethoughts-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateWithThoughts( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -94,5 +94,5 @@ async function generateContent( // [END googlegenaisdk_thinking_includethoughts_with_txt] module.exports = { - generateContent, + generateWithThoughts, }; diff --git a/genai/thinking/thinking-with-txt.js b/genai/thinking/thinking-with-txt.js index 3b727abc9e..babaa00320 100644 --- a/genai/thinking/thinking-with-txt.js +++ b/genai/thinking/thinking-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateWithThoughts( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -94,5 +94,5 @@ async function generateContent( // [END googlegenaisdk_thinking_with_txt] module.exports = { - generateContent, + generateWithThoughts, };