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
16 changes: 15 additions & 1 deletion DemoApp/Files/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"dependencies": {
"Google.Apis.Auth": "[1.69.0, )",
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
"MimeTypes": "[2.5.2, )"
"MimeTypes": "[2.5.2, )",
"System.Collections.Immutable": "[9.0.0, )",
"System.Net.ServerSentEvents": "[9.0.0, )"
}
},
"Google.Apis.Auth": {
Expand Down Expand Up @@ -80,6 +82,18 @@
"resolved": "2.5.2",
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
},
"System.Collections.Immutable": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
},
"System.Net.ServerSentEvents": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
},
"System.Text.Json": {
"type": "CentralTransitive",
"requested": "[10.0.4, )",
Expand Down
16 changes: 15 additions & 1 deletion DemoApp/GenerateContentSimpleText/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"dependencies": {
"Google.Apis.Auth": "[1.69.0, )",
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
"MimeTypes": "[2.5.2, )"
"MimeTypes": "[2.5.2, )",
"System.Collections.Immutable": "[9.0.0, )",
"System.Net.ServerSentEvents": "[9.0.0, )"
}
},
"Google.Apis.Auth": {
Expand Down Expand Up @@ -80,6 +82,18 @@
"resolved": "2.5.2",
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
},
"System.Collections.Immutable": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
},
"System.Net.ServerSentEvents": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
},
"System.Text.Json": {
"type": "CentralTransitive",
"requested": "[10.0.4, )",
Expand Down
16 changes: 15 additions & 1 deletion DemoApp/GenerateContentStreamSimpleText/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"dependencies": {
"Google.Apis.Auth": "[1.69.0, )",
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
"MimeTypes": "[2.5.2, )"
"MimeTypes": "[2.5.2, )",
"System.Collections.Immutable": "[9.0.0, )",
"System.Net.ServerSentEvents": "[9.0.0, )"
}
},
"Google.Apis.Auth": {
Expand Down Expand Up @@ -80,6 +82,18 @@
"resolved": "2.5.2",
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
},
"System.Collections.Immutable": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
},
"System.Net.ServerSentEvents": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
},
"System.Text.Json": {
"type": "CentralTransitive",
"requested": "[10.0.4, )",
Expand Down
14 changes: 14 additions & 0 deletions DemoApp/InteractionCreate/InteractionCreate.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
42 changes: 42 additions & 0 deletions DemoApp/InteractionCreate/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 Google.GenAI;
using Google.GenAI.Interactions.Models.Interactions;

bool isVertex = args.Contains("--vertex", StringComparer.OrdinalIgnoreCase);
Console.WriteLine(isVertex ? "Running in Vertex AI mode." : "Running in Gemini API mode.");

Client client = new Client(vertexAI: isVertex);

CreateModelInteractionParams parameters = new()
{
Input = "What is your name?",
Model = Model.Gemini2_5Flash,
};

Interaction interaction = await client.Interactions.Create(new() { Body = parameters });

Console.WriteLine($"Interaction ID: {interaction.ID}");
Console.WriteLine($"Status: {interaction.Status}");

foreach (var output in interaction?.Outputs ?? [])
{
if (output.TryPickText(out var text))
{
Console.WriteLine($"Output: {text.Text}");
}
}
3 changes: 3 additions & 0 deletions DemoApp/InteractionCreate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. Perform these steps when you are in the directory of this README file.
2. Set the `GOOGLE_API_KEY` environment variable to your API key.
3. Run `dotnet run` to run the demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
39 changes: 39 additions & 0 deletions DemoApp/InteractionCreateStreaming/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 Google.GenAI;
using Google.GenAI.Interactions.Models.Interactions;

bool isVertex = args.Contains("--vertex", StringComparer.OrdinalIgnoreCase);
Console.WriteLine(isVertex ? "Running in Vertex AI mode." : "Running in Gemini API mode.");

Client client = new Client(vertexAI: isVertex);

CreateModelInteractionParams parameters = new()
{
Input = "Tell me a story in 300 words.",
Model = Model.Gemini2_5Flash,
};

await foreach (var messageEvent in client.Interactions.CreateStreaming(new() { Body = parameters }))
{
if (messageEvent.TryPickContentDelta(out var contentDelta) && contentDelta.Delta.TryPickText(out var deltaText))
{
Console.Write(deltaText.TextValue);
}
}

Console.WriteLine();
3 changes: 3 additions & 0 deletions DemoApp/InteractionCreateStreaming/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. Perform these steps when you are in the directory of this README file.
2. Set the `GOOGLE_API_KEY` environment variable to your API key.
3. Run `dotnet run` to run the demo
14 changes: 14 additions & 0 deletions DemoApp/InteractionDeepResearch/InteractionDeepResearch.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
130 changes: 130 additions & 0 deletions DemoApp/InteractionDeepResearch/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright 2026 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 Google.GenAI;
using Google.GenAI.Interactions.Models.Interactions;

namespace InteractionDeepResearch;

class Program
{
static async Task Main(string[] args)
{
string? vertexAIEnv = System.Environment.GetEnvironmentVariable("GOOGLE_GENAI_USE_VERTEXAI");
bool isVertexAI = vertexAIEnv != null && vertexAIEnv.ToLower() == "true";

if (!isVertexAI)
{
Console.Error.WriteLine("Deep Research is only supported on Vertex AI. Please set GOOGLE_GENAI_USE_VERTEXAI=true.");
return;
}

Client client = new Client(vertexAI: true);

Console.WriteLine("--- Starting Deep Research Interaction ---");

var interactions = client.Interactions.WithOptions(options =>
{
options.ApiVersion = "v1beta1";
return options;
});

CreateAgentInteractionParams agentParams = new()
{
Agent = "deep-research-pro-preview-12-2025",
Input = "I want to learn more about the history of Hadrian's Wall",
Background = true,
};

var createParams = new InteractionCreateParams()
{
Body = agentParams
};

string? interactionId = null;

Console.WriteLine("--- Sending Create Request ---");

// We use CreateStreaming to see progress events
await foreach (var messageEvent in interactions.CreateStreaming(createParams))
{
if (messageEvent.TryPickStart(out var startEvent))
{
interactionId = startEvent.Interaction.ID;
Console.WriteLine($"Started Interaction ID: {interactionId}");
}

if (messageEvent.TryPickStatusUpdate(out var statusUpdate))
{
Console.WriteLine($"Event: StatusUpdate - {statusUpdate.Status}");
}
else if (messageEvent.TryPickContentDelta(out var contentDelta))
{
if (contentDelta.Delta.TryPickText(out var text))
{
Console.Write(text.TextValue);
}
else
{
Console.WriteLine("\n[Agent Activity]");
}
}
else if (messageEvent.TryPickComplete(out var complete))
{
Console.WriteLine("\nEvent: Complete");
break;
}

// We only want to capture the ID from the first few events and then we can let it run in background
// or we can wait. The Java example limits to 1 event to capture ID and then resumes.
// Let's mimic Java: capture ID from start event and then break to resume.
if (interactionId != null)
{
break;
}
}

if (interactionId == null)
{
Console.Error.WriteLine("Failed to capture interaction ID.");
return;
}

Console.WriteLine($"\n--- Resuming Interaction: {interactionId} ---");

// Resume the stream
await foreach (var messageEvent in interactions.GetStreaming(interactionId))
{
if (messageEvent.TryPickStatusUpdate(out var statusUpdate))
{
Console.WriteLine($"\n[Status update: {statusUpdate.Status}]");
}
else if (messageEvent.TryPickContentDelta(out var contentDelta))
{
if (contentDelta.Delta.TryPickText(out var text))
{
Console.Write(text.TextValue);
}
else
{
Console.WriteLine("\n[Agent Activity]");
}
}
}

Console.WriteLine();
}
}
16 changes: 15 additions & 1 deletion DemoApp/JsonParser/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"dependencies": {
"Google.Apis.Auth": "[1.69.0, )",
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
"MimeTypes": "[2.5.2, )"
"MimeTypes": "[2.5.2, )",
"System.Collections.Immutable": "[9.0.0, )",
"System.Net.ServerSentEvents": "[9.0.0, )"
}
},
"Google.Apis.Auth": {
Expand Down Expand Up @@ -80,6 +82,18 @@
"resolved": "2.5.2",
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
},
"System.Collections.Immutable": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
},
"System.Net.ServerSentEvents": {
"type": "CentralTransitive",
"requested": "[9.0.0, )",
"resolved": "9.0.0",
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
},
"System.Text.Json": {
"type": "CentralTransitive",
"requested": "[10.0.4, )",
Expand Down
Loading
Loading