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/Interactions/InteractionBasic/InteractionBasic.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>
48 changes: 48 additions & 0 deletions DemoApp/Interactions/InteractionBasic/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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;

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);

if (isVertex)
{
Console.WriteLine("Interactions API is not yet supported on Vertex AI");
return;
}

CreateModelInteractionParams params1 = new()
{
Input = "Why is the sky blue?",
Model = Model.Gemini2_5Flash,
};

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

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}");
}
}
14 changes: 14 additions & 0 deletions DemoApp/Interactions/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/Interactions/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/Interactions/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/Interactions/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/Interactions/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
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>
Loading
Loading