Skip to content

Commit fee24fe

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: [EXPERIMANTAL] Add interactions support.
FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/google-gemini/private-dotnet-genai/pull/75 from google-gemini:vertex b423641c927b1c5e587c4ddb533afec002844b2d PiperOrigin-RevId: 903935900
1 parent 75b52c7 commit fee24fe

208 files changed

Lines changed: 40633 additions & 4797 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DemoApp/Files/packages.lock.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"dependencies": {
5252
"Google.Apis.Auth": "[1.69.0, )",
5353
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
54-
"MimeTypes": "[2.5.2, )"
54+
"MimeTypes": "[2.5.2, )",
55+
"System.Collections.Immutable": "[9.0.0, )",
56+
"System.Net.ServerSentEvents": "[9.0.0, )"
5557
}
5658
},
5759
"Google.Apis.Auth": {
@@ -80,6 +82,18 @@
8082
"resolved": "2.5.2",
8183
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
8284
},
85+
"System.Collections.Immutable": {
86+
"type": "CentralTransitive",
87+
"requested": "[9.0.0, )",
88+
"resolved": "9.0.0",
89+
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
90+
},
91+
"System.Net.ServerSentEvents": {
92+
"type": "CentralTransitive",
93+
"requested": "[9.0.0, )",
94+
"resolved": "9.0.0",
95+
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
96+
},
8397
"System.Text.Json": {
8498
"type": "CentralTransitive",
8599
"requested": "[10.0.4, )",

DemoApp/GenerateContentSimpleText/packages.lock.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"dependencies": {
5252
"Google.Apis.Auth": "[1.69.0, )",
5353
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
54-
"MimeTypes": "[2.5.2, )"
54+
"MimeTypes": "[2.5.2, )",
55+
"System.Collections.Immutable": "[9.0.0, )",
56+
"System.Net.ServerSentEvents": "[9.0.0, )"
5557
}
5658
},
5759
"Google.Apis.Auth": {
@@ -80,6 +82,18 @@
8082
"resolved": "2.5.2",
8183
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
8284
},
85+
"System.Collections.Immutable": {
86+
"type": "CentralTransitive",
87+
"requested": "[9.0.0, )",
88+
"resolved": "9.0.0",
89+
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
90+
},
91+
"System.Net.ServerSentEvents": {
92+
"type": "CentralTransitive",
93+
"requested": "[9.0.0, )",
94+
"resolved": "9.0.0",
95+
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
96+
},
8397
"System.Text.Json": {
8498
"type": "CentralTransitive",
8599
"requested": "[10.0.4, )",

DemoApp/GenerateContentStreamSimpleText/packages.lock.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"dependencies": {
5252
"Google.Apis.Auth": "[1.69.0, )",
5353
"Microsoft.Extensions.AI.Abstractions": "[10.4.0, )",
54-
"MimeTypes": "[2.5.2, )"
54+
"MimeTypes": "[2.5.2, )",
55+
"System.Collections.Immutable": "[9.0.0, )",
56+
"System.Net.ServerSentEvents": "[9.0.0, )"
5557
}
5658
},
5759
"Google.Apis.Auth": {
@@ -80,6 +82,18 @@
8082
"resolved": "2.5.2",
8183
"contentHash": "vm4xrNt+i6OVRQ8vhfCcmDIUg3qvjyCTkSTNVTDFohsG6CXEpMaVFkidECL6yRYpHDnz4TqXhDoEQAcnHCu/tw=="
8284
},
85+
"System.Collections.Immutable": {
86+
"type": "CentralTransitive",
87+
"requested": "[9.0.0, )",
88+
"resolved": "9.0.0",
89+
"contentHash": "QhkXUl2gNrQtvPmtBTQHb0YsUrDiDQ2QS09YbtTTiSjGcf7NBqtYbrG/BE06zcBPCKEwQGzIv13IVdXNOSub2w=="
90+
},
91+
"System.Net.ServerSentEvents": {
92+
"type": "CentralTransitive",
93+
"requested": "[9.0.0, )",
94+
"resolved": "9.0.0",
95+
"contentHash": "VTWjeyx9nPb4+hkjGcAaDw1nOckypMtvABmxSWm6PPYwrXoIiVG3jwtNlAGhaGVjDkBrERABox67wYTAcHxg7Q=="
96+
},
8397
"System.Text.Json": {
8498
"type": "CentralTransitive",
8599
"requested": "[10.0.4, )",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>net8.0</TargetFramework>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
</Project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.GenAI;
18+
using Google.GenAI.Interactions.Models.Interactions;
19+
20+
bool isVertex = args.Contains("--vertex", StringComparer.OrdinalIgnoreCase);
21+
Console.WriteLine(isVertex ? "Running in Vertex AI mode." : "Running in Gemini API mode.");
22+
23+
Client client = new Client(vertexAI: isVertex);
24+
25+
CreateModelInteractionParams parameters = new()
26+
{
27+
Input = "What is your name?",
28+
Model = Model.Gemini2_5Flash,
29+
};
30+
31+
Interaction interaction = await client.Interactions.Create(new() { Body = parameters });
32+
33+
Console.WriteLine($"Interaction ID: {interaction.ID}");
34+
Console.WriteLine($"Status: {interaction.Status}");
35+
36+
foreach (var output in interaction?.Outputs ?? [])
37+
{
38+
if (output.TryPickText(out var text))
39+
{
40+
Console.WriteLine($"Output: {text.Text}");
41+
}
42+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1. Perform these steps when you are in the directory of this README file.
2+
2. Set the `GOOGLE_API_KEY` environment variable to your API key.
3+
3. Run `dotnet run` to run the demo
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
4+
<ItemGroup>
5+
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
6+
</ItemGroup>
7+
8+
<PropertyGroup>
9+
<OutputType>Exe</OutputType>
10+
<TargetFramework>net8.0</TargetFramework>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
<Nullable>enable</Nullable>
13+
</PropertyGroup>
14+
15+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Google.GenAI;
18+
using Google.GenAI.Interactions.Models.Interactions;
19+
20+
bool isVertex = args.Contains("--vertex", StringComparer.OrdinalIgnoreCase);
21+
Console.WriteLine(isVertex ? "Running in Vertex AI mode." : "Running in Gemini API mode.");
22+
23+
Client client = new Client(vertexAI: isVertex);
24+
25+
CreateModelInteractionParams parameters = new()
26+
{
27+
Input = "Tell me a story in 300 words.",
28+
Model = Model.Gemini2_5Flash,
29+
};
30+
31+
await foreach (var messageEvent in client.Interactions.CreateStreaming(new() { Body = parameters }))
32+
{
33+
if (messageEvent.TryPickContentDelta(out var contentDelta) && contentDelta.Delta.TryPickText(out var deltaText))
34+
{
35+
Console.Write(deltaText.TextValue);
36+
}
37+
}
38+
39+
Console.WriteLine();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1. Perform these steps when you are in the directory of this README file.
2+
2. Set the `GOOGLE_API_KEY` environment variable to your API key.
3+
3. Run `dotnet run` to run the demo
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\Google.GenAI\Google.GenAI.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>net8.0</TargetFramework>
10+
<ImplicitUsings>enable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
</Project>

0 commit comments

Comments
 (0)