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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.IO;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class TextGenWithLocalVideoTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithLocalVideo _sample;

public TextGenWithLocalVideoTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithLocalVideo();
}

[Fact]
public async Task TestTextGenWithLocalVideo()
{
string videoFilePath = Path.GetFullPath("../../../Resources/describe_video_content.mp4");
var response = await _sample.GenerateContent(projectId: _fixture.ProjectId, localVideoFilePath: videoFilePath);
Assert.NotEmpty(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.IO;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class TextGenWithMultiImgTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithMultiImg _sample;

public TextGenWithMultiImgTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithMultiImg();
}

[Fact]
public async Task TestTextGenWithMultiImg()
{
string localImageFilePath = Path.GetFullPath("../../../Resources/latte.jpg");
var response = await _sample.GenerateContent(projectId: _fixture.ProjectId, localImageFilePath: localImageFilePath);
Assert.NotEmpty(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.IO;
using System.Threading.Tasks;
using Xunit;

[Collection(nameof(GenAIFixture))]
public class TextGenWithMultiLocalImgTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithMultiLocalImg _sample;

public TextGenWithMultiLocalImgTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithMultiLocalImg();
}

[Fact]
public async Task TestTextGenWithLocalLocalImg()
{
string imageFilePath1 = Path.GetFullPath("../../../Resources/latte.jpg");
string imageFilePath2 = Path.GetFullPath("../../../Resources/scones.jpg");
var response = await _sample.GenerateContent(projectId: _fixture.ProjectId, localImgFilePath1: imageFilePath1, localImgFilePath2: imageFilePath2);
Assert.NotEmpty(response);
}
}
70 changes: 70 additions & 0 deletions genai/api/GenAI.Samples/TextGeneration/TextGenWithLocalVideo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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_textgen_with_local_video]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

public class TextGenWithLocalVideo
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-flash",
string localVideoFilePath = "path/to/local_video.mp4")
{
await using var client = new Client(
project: projectId,
location: location,
vertexAI: true,
httpOptions: new HttpOptions { ApiVersion = "v1" });

// Read local video content.
byte[] videoBytes = File.ReadAllBytes(localVideoFilePath);

var contents = new List<Content>
{
new Content
{
Role = "user",
Parts = new List<Part>
{
new Part { InlineData = new Blob { Data = videoBytes, MimeType = "video/mp4" } },
new Part { Text = "Write a short and engaging blog post based on this video." }
}
}
};

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: contents);

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example response:
// The Art of the Ascent: A Masterclass in Indoor Climbing
// There's a certain raw beauty in the art of rock climbing,
// and this video captures it perfectly.
// ...
return responseText;
}
}
// [END googlegenaisdk_textgen_with_local_video]
71 changes: 71 additions & 0 deletions genai/api/GenAI.Samples/TextGeneration/TextGenWithMultiImg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2024 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_textgen_with_multi_img]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

public class TextGenWithMultiImg
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-flash",
string localImageFilePath = "path/to/img.jpg")
{
await using var client = new Client(
project: projectId,
location: location,
vertexAI: true,
httpOptions: new HttpOptions { ApiVersion = "v1" });

// Read local image content.
byte[] localImgBytes = File.ReadAllBytes(localImageFilePath);

// Image from GCS
string gcsImageFilePath = "gs://cloud-samples-data/generative-ai/image/scones.jpg";

var contents = new List<Content>
{
new Content
{
Role = "user",
Parts = new List<Part>
{
new Part { FileData = new FileData { FileUri = gcsImageFilePath, MimeType = "image/jpeg" } },
new Part { InlineData = new Blob { Data = localImgBytes, MimeType = "image/jpeg" } },
new Part { Text = "Generate a list of all the objects contained in both images." }
}
}
};

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: contents);

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example response:
// The objects contained in both images are:
// *Coffee
// * Cups(or mugs)
return responseText;
}
}
// [END googlegenaisdk_textgen_with_multi_img]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2024 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_textgen_with_multi_local_img]

using Google.GenAI;
using Google.GenAI.Types;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

public class TextGenWithMultiLocalImg
{
public async Task<string> GenerateContent(
string projectId = "your-project-id",
string location = "global",
string model = "gemini-2.5-flash",
string localImgFilePath1 = "path/to/img1.jpg",
string localImgFilePath2 = "path/to/img2.jpg")
{
await using var client = new Client(
project: projectId,
location: location,
vertexAI: true,
httpOptions: new HttpOptions { ApiVersion = "v1" });

// Read local images content.
byte[] localImg1Bytes = File.ReadAllBytes(localImgFilePath1);
byte[] localImg2Bytes = File.ReadAllBytes(localImgFilePath2);

var contents = new List<Content>
{
new Content
{
Role = "user",
Parts = new List<Part>
{
new Part { InlineData = new Blob { Data = localImg1Bytes, MimeType = "image/jpeg" } },
new Part { InlineData = new Blob { Data = localImg2Bytes, MimeType = "image/jpeg" } },
new Part { Text = "Generate a list of all the objects contained in both images." }
}
}
};

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: contents);

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example response:
// Here are the objects contained in both images:
// 1. **Coffee cup **: Both images feature coffee cups.
// 2. **Baked goods **: Image 1 contains a slice of cake,
// and Image 2 contains scones. Both fall under the category of baked goods.
// ...
return responseText;
}
}
// [END googlegenaisdk_textgen_with_multi_local_img]