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 TextGenSysInstrWithTxtTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenSysInstrWithTxt _sample;

public TextGenSysInstrWithTxtTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenSysInstrWithTxt();
}

[Fact]
public async Task TestTextGenSysInstrWithTxt()
{
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 TextGenWithMuteVideoTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithMuteVideo _sample;

public TextGenWithMuteVideoTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithMuteVideo();
}

[Fact]
public async Task TestTextGenWithMuteVideo()
{
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 TextGenWithTxtImgTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithTxtImg _sample;

public TextGenWithTxtImgTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithTxtImg();
}

[Fact]
public async Task TestTextGenWithTxtImg()
{
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 TextGenWithTxtStreamTest
{
private readonly GenAIFixture _fixture;
private readonly TextGenWithTxtStream _sample;

public TextGenWithTxtStreamTest(GenAIFixture fixture)
{
_fixture = fixture;
_sample = new TextGenWithTxtStream();
}

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

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

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

var systemInstruction = new Content
{
Parts = new List<Part>
{
new Part
{
Text = "You're a language translator. Your mission is to translate text in English to French."
}
}
};

GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: model,
contents: "Why is the sky blue?",
config: new GenerateContentConfig { SystemInstruction = systemInstruction });

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example response:
// Pourquoi le ciel est-il bleu ?
return responseText;
}
}
// [END googlegenaisdk_textgen_sys_instr_with_txt]
70 changes: 70 additions & 0 deletions genai/api/GenAI.Samples/TextGeneration/TextGenWithMuteVideo.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_mute_video]

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

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

var contents = new List<Content>
{
new Content
{
Role = "user",
Parts = new List<Part>
{
new Part
{
FileData = new FileData
{
FileUri = "gs://cloud-samples-data/generative-ai/video/ad_copy_from_video.mp4",
MimeType = "video/mp4"
}
},
new Part { Text = "What is in 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:
// This video shows an aerial view of people surfing in the ocean on a misty
// or hazy day, with a distant coastline and mountains in the background...
return responseText;
}
}
// [END googlegenaisdk_textgen_with_mute_video]
70 changes: 70 additions & 0 deletions genai/api/GenAI.Samples/TextGeneration/TextGenWithTxtImg.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_txt_img]

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

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

var contents = new List<Content>
{
new Content
{
Role = "user",
Parts = new List<Part>
{
new Part
{
FileData = new FileData
{
FileUri = "gs://cloud-samples-data/generative-ai/image/scones.jpg",
MimeType = "image/jpeg"
}
},
new Part { Text = "What is shown in this image?"}
}
}
};

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

string responseText = response.Candidates[0].Content.Parts[0].Text;
Console.WriteLine(responseText);
// Example response:
// This image displays a beautifully arranged, top-down still life featuring
// blueberry scones, fresh fruit, drinks, and flowers, set against...
return responseText;
}
}
// [END googlegenaisdk_textgen_with_txt_img]
Loading