Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class ThinkingBudgetWithTxtTest
{
private readonly GenAIFixture _fixture;
private readonly ThinkingBudgetWithTxt _sample;

public ThinkingBudgetWithTxtTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new ThinkingBudgetWithTxt();
}

[Fact]
public async Task TestThinkingBudgetWithTxt()
{
var response = await _sample.GenerateContent(_fixture.ProjectId);
Assert.NotEmpty(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class ThinkingIncludeThoughtsWithTxtTest
{
private readonly GenAIFixture _fixture;
private readonly ThinkingIncludeThoughtsWithTxt _sample;

public ThinkingIncludeThoughtsWithTxtTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new ThinkingIncludeThoughtsWithTxt();
}

[Fact]
public async Task TestThinkingIncludeThoughtsWithTxt()
{
var response = await _sample.GenerateContent(_fixture.ProjectId);
Assert.NotEmpty(response);
}
}
38 changes: 38 additions & 0 deletions genai/api/GenAI.Samples.Tests/Thinking/ThinkingWithTxtTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class ThinkingWithTxtTest
{
private readonly GenAIFixture _fixture;
private readonly ThinkingWithTxt _sample;

public ThinkingWithTxtTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new ThinkingWithTxt();
}

[Fact]
public async Task TestThinkingWithTxt()
{
var response = await _sample.GenerateContent(_fixture.ProjectId);
Assert.NotEmpty(response);
}
}
58 changes: 58 additions & 0 deletions genai/api/GenAI.Samples/Thinking/ThinkingBudgetWithTxt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.
*/

// [START googlegenaisdk_thinking_budget_with_txt]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Threading.Tasks;

public class ThinkingBudgetWithTxt
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-flash")
{
var client = new Client(project: projectId, location: location, vertexAI: true);

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: "solve x^2 + 4x + 4 = 0",
config: new GenerateContentConfig
{
ThinkingConfig = new ThinkingConfig { ThinkingBudget = 1024 }
});

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example reponse:
// To solve the equation $x^2 + 4x + 4 = 0$, we can use several methods:
// **Method 1: Factoring(Recognizing a Perfect Square Trinomial) * *
// Notice that the left side of the equation is a perfect square trinomial.
// It follows the pattern $a ^ 2 + 2ab + b ^ 2 = (a + b) ^ 2$.
// ...
// All methods yield the same solution.
// The solution is $x = -2$.

Console.WriteLine($"Token count for thinking: {response.UsageMetadata.ThoughtsTokenCount}");
// Example response:
// Token count for thinking: 804
return responseText;
}
}
// [END googlegenaisdk_thinking_budget_with_txt]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

// [START googlegenaisdk_thinking_includethoughts_with_txt]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Threading.Tasks;

public class ThinkingIncludeThoughtsWithTxt
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-pro")
{
var client = new Client(project: projectId, location: location, vertexAI: true);

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: "solve x^2 + 4x + 4 = 0",
config: new GenerateContentConfig
{
ThinkingConfig = new ThinkingConfig { IncludeThoughts = true }
});

foreach (Part part in response.Candidates[0].Content.Parts)
{
if (part.Thought.GetValueOrDefault(false))
{
Console.WriteLine(part.Text);
}
}
// Example response:
// Alright, let's break down this quadratic equation, `x^2 + 4x + 4 = 0`. First things first, I recognize
// this is a standard quadratic form, perfect for applying my knowledge.
// 1. **Analyze and Prep:**Okay, the user wants the solution.Got it. This is a quadratic in standard
// form, `ax ^ 2 + bx + c = 0`. That means I have several solution strategies at my disposal.
// 2. **Coefficients in Hand: ** `a` is 1, `b` is 4, and `c` is also 4.Easy enough.
// 3. **Method Selection - The Decision Point:**Now, I've got to choose the most efficient path.
// I could *always* use the quadratic formula, but that might be overkill. Factoring is always worth a
// look, especially when dealing with smaller coefficients. Completing the square is a possibility, but
// less elegant here. Graphing... well, that's more for visualization, not direct algebraic solution.
// 4. **Evaluate for *This * Case:**Let's see if factoring holds up.
// ...
// * End with a concise summary of the key takeaway, emphasizing that it's a repeated root.
// Perfect.The plan is set, the path is clear.
return response.Candidates[0].Content.Parts[0].Text;
}
}
// [END googlegenaisdk_thinking_includethoughts_with_txt]
50 changes: 50 additions & 0 deletions genai/api/GenAI.Samples/Thinking/ThinkingWithTxt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

// [START googlegenaisdk_thinking_with_txt]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Threading.Tasks;

public class ThinkingWithTxt
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-pro")
{
var client = new Client(project: projectId, location: location, vertexAI: true);

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: "solve x^2 + 4x + 4 = 0");

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example reponse:
// Of course! We can solve the equation **x² + 4x + 4 = 0** in a couple of ways.
// ### Method 1: Factoring
// This is the quickest method for this particular problem.
// 1. * *Recognize the pattern:**The expression `x² +4x + 4` is a perfect square trinomial
// ...
// Both methods give the same result.
// **The solution is x = -2.**
return responseText;
}
}
// [END googlegenaisdk_thinking_with_txt]