-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add models of Gemini 1.5 and Gemini 1.0 Ultra
- Loading branch information
1 parent
167e726
commit 13e7692
Showing
7 changed files
with
1,518 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
#if NET472_OR_GREATER || NETSTANDARD2_0 | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
#endif | ||
using FluentAssertions; | ||
using Mscc.GenerativeAI; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Test.Mscc.GenerativeAI | ||
{ | ||
[Collection(nameof(ConfigurationFixture))] | ||
public class GoogleAi_Gemini15Pro_Should | ||
{ | ||
private readonly ITestOutputHelper output; | ||
private readonly ConfigurationFixture fixture; | ||
private readonly string model = Model.Gemini15Pro; | ||
|
||
public GoogleAi_Gemini15Pro_Should(ITestOutputHelper output, ConfigurationFixture fixture) | ||
{ | ||
this.output = output; | ||
this.fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public void Initialize_Gemini15Pro() | ||
{ | ||
// Arrange | ||
|
||
// Act | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
|
||
// Assert | ||
model.Should().NotBeNull(); | ||
model.Name.Should().Be(Model.Gemini15Pro.SanitizeModelName()); | ||
} | ||
|
||
[Fact] | ||
public async void Generate_Text_From_Image() | ||
{ | ||
// Arrange | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var request = new GenerateContentRequest { Contents = new List<Content>() }; | ||
var base64image = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="; | ||
var parts = new List<IPart> | ||
{ | ||
new TextData { Text = "What is this picture about?" }, | ||
new InlineData { MimeType = "image/jpeg", Data = base64image } | ||
}; | ||
request.Contents.Add(new Content { Role = Role.User, Parts = parts }); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
response.Text.Should().Contain("red"); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Fact] | ||
public async void Describe_Image_From_InlineData() | ||
{ | ||
// Arrange | ||
var prompt = "Parse the time and city from the airport board shown in this image into a list, in Markdown"; | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
// Images | ||
var board = await TestExtensions.ReadImageFileBase64Async("https://ai.google.dev/static/docs/images/timetable.png"); | ||
var request = new GenerateContentRequest(prompt); | ||
request.Contents[0].Parts.Add( | ||
new InlineData { MimeType = "image/png", Data = board } | ||
); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Theory] | ||
[InlineData("scones.jpg", "image/jpeg", "What is this picture?", "blueberries")] | ||
[InlineData("cat.jpg", "image/jpeg", "Describe this image", "snow")] | ||
[InlineData("cat.jpg", "image/jpeg", "Is it a cat?", "Yes")] | ||
//[InlineData("animals.mp4", "video/mp4", "What's in the video?", "Zootopia")] | ||
public async void Generate_Text_From_ImageFile(string filename, string mimetype, string prompt, string expected) | ||
{ | ||
// Arrange | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var base64image = Convert.ToBase64String(File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "payload", filename))); | ||
var parts = new List<IPart> | ||
{ | ||
new TextData { Text = prompt }, | ||
new InlineData { MimeType = mimetype, Data = base64image } | ||
}; | ||
var generationConfig = new GenerationConfig() | ||
{ | ||
Temperature = 0.4f, TopP = 1, TopK = 32, MaxOutputTokens = 1024 | ||
}; | ||
|
||
// Act | ||
var response = await model.GenerateContent(parts, generationConfig); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
response.Text.Should().Contain(expected); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Theory] | ||
[InlineData("scones.jpg", "What is this picture?", "blueberries")] | ||
[InlineData("cat.jpg", "Describe this image", "snow")] | ||
[InlineData("cat.jpg", "Is it a feline?", "Yes")] | ||
//[InlineData("animals.mp4", "video/mp4", "What's in the video?", "Zootopia")] | ||
public async void Describe_AddMedia_From_ImageFile(string filename, string prompt, string expected) | ||
{ | ||
// Arrange | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var request = new GenerateContentRequest(prompt) | ||
{ | ||
GenerationConfig = new GenerationConfig() | ||
{ | ||
Temperature = 0.4f, TopP = 1, TopK = 32, MaxOutputTokens = 1024 | ||
} | ||
}; | ||
request.AddMedia(Path.Combine(Environment.CurrentDirectory, "payload", filename)); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
response.Text.Should().Contain(expected); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Fact] | ||
public async void Describe_AddMedia_From_Url() | ||
{ | ||
// Arrange | ||
var prompt = "Parse the time and city from the airport board shown in this image into a list, in Markdown"; | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var request = new GenerateContentRequest(prompt); | ||
await request.AddMedia("https://ai.google.dev/static/docs/images/timetable.png"); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Fact] | ||
public async void Describe_AddMedia_From_UrlRemote() | ||
{ | ||
// Arrange | ||
var prompt = "Parse the time and city from the airport board shown in this image into a list, in Markdown"; | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var request = new GenerateContentRequest(prompt); | ||
await request.AddMedia("https://ai.google.dev/static/docs/images/timetable.png", true); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Fact(Skip = "Bad Request due to FileData part")] | ||
public async void Describe_Image_From_FileData() | ||
{ | ||
// Arrange | ||
var prompt = "Parse the time and city from the airport board shown in this image into a list, in Markdown"; | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var request = new GenerateContentRequest(prompt); | ||
request.Contents[0].Parts.Add(new FileData | ||
{ | ||
FileUri = "https://ai.google.dev/static/docs/images/timetable.png", | ||
MimeType = "image/png" | ||
}); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
output.WriteLine(response?.Text); | ||
} | ||
|
||
[Fact(Skip = "URL scheme not supported")] | ||
public async void Multimodal_Video_Input() | ||
{ | ||
// Arrange | ||
var model = new GenerativeModel(apiKey: fixture.ApiKey, model: this.model); | ||
var video = await TestExtensions.ReadImageFileBase64Async("gs://cloud-samples-data/video/animals.mp4"); | ||
var request = new GenerateContentRequest("What's in the video?"); | ||
request.Contents[0].Role = Role.User; | ||
request.Contents[0].Parts.Add(new InlineData { MimeType = "video/mp4", Data = video }); | ||
|
||
// Act | ||
var response = await model.GenerateContent(request); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.Candidates.Should().NotBeNull().And.HaveCount(1); | ||
response.Candidates.FirstOrDefault().Content.Should().NotBeNull(); | ||
response.Candidates.FirstOrDefault().Content.Parts.Should().NotBeNull().And.HaveCountGreaterThanOrEqualTo(1); | ||
response.Text.Should().Contain("Zootopia"); | ||
output.WriteLine(response?.Text); | ||
} | ||
} | ||
} |
Oops, something went wrong.