-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net OpenAI V2 - Text to Image Service - Phase 02 (#6951)
- Updated ImageToText service implementation using OpenAI SDK - Updated ImageToText service API's parameters order (modelId first) and added modelId as required (OpenAI supports both dall-e-2 and dall-e-3) - Added support for OpenAIClient breaking glass for Image to Text Service - Added support for custom/Non-default endpoint for Image to Text Service - Added missing Extensions (Service Collection + Kernel Builder) for Embeddings and Image to Text modalities - Added missing UnitTest for Embeddings - Added UT convering Image to Text. - Added integration tests for ImageTotext - Resolve Partially #6916
- Loading branch information
1 parent
6729af1
commit c967a24
Showing
19 changed files
with
914 additions
and
21 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
73 changes: 73 additions & 0 deletions
73
...t/src/Connectors/Connectors.OpenAIV2.UnitTests/Extensions/KernelBuilderExtensionsTests.cs
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,73 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Embeddings; | ||
using Microsoft.SemanticKernel.Services; | ||
using Microsoft.SemanticKernel.TextToImage; | ||
using OpenAI; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Connectors.OpenAI.UnitTests.Extensions; | ||
|
||
public class KernelBuilderExtensionsTests | ||
{ | ||
[Fact] | ||
public void ItCanAddTextEmbeddingGenerationService() | ||
{ | ||
// Arrange | ||
var sut = Kernel.CreateBuilder(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextEmbeddingGeneration("model", "key") | ||
.Build() | ||
.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddTextEmbeddingGenerationServiceWithOpenAIClient() | ||
{ | ||
// Arrange | ||
var sut = Kernel.CreateBuilder(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextEmbeddingGeneration("model", new OpenAIClient("key")) | ||
.Build() | ||
.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddTextToImageService() | ||
{ | ||
// Arrange | ||
var sut = Kernel.CreateBuilder(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextToImage("model", "key") | ||
.Build() | ||
.GetRequiredService<ITextToImageService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddTextToImageServiceWithOpenAIClient() | ||
{ | ||
// Arrange | ||
var sut = Kernel.CreateBuilder(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextToImage("model", new OpenAIClient("key")) | ||
.Build() | ||
.GetRequiredService<ITextToImageService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...c/Connectors/Connectors.OpenAIV2.UnitTests/Extensions/ServiceCollectionExtensionsTests.cs
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,74 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Embeddings; | ||
using Microsoft.SemanticKernel.Services; | ||
using Microsoft.SemanticKernel.TextToImage; | ||
using OpenAI; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.Connectors.OpenAI.UnitTests.Extensions; | ||
|
||
public class ServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void ItCanAddTextEmbeddingGenerationService() | ||
{ | ||
// Arrange | ||
var sut = new ServiceCollection(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextEmbeddingGeneration("model", "key") | ||
.BuildServiceProvider() | ||
.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddTextEmbeddingGenerationServiceWithOpenAIClient() | ||
{ | ||
// Arrange | ||
var sut = new ServiceCollection(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextEmbeddingGeneration("model", new OpenAIClient("key")) | ||
.BuildServiceProvider() | ||
.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddImageToTextService() | ||
{ | ||
// Arrange | ||
var sut = new ServiceCollection(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextToImage("model", "key") | ||
.BuildServiceProvider() | ||
.GetRequiredService<ITextToImageService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
|
||
[Fact] | ||
public void ItCanAddImageToTextServiceWithOpenAIClient() | ||
{ | ||
// Arrange | ||
var sut = new ServiceCollection(); | ||
|
||
// Act | ||
var service = sut.AddOpenAITextToImage("model", new OpenAIClient("key")) | ||
.BuildServiceProvider() | ||
.GetRequiredService<ITextToImageService>(); | ||
|
||
// Assert | ||
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]); | ||
} | ||
} |
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
Oops, something went wrong.