Skip to content

Commit

Permalink
.Net: OpenAI V2 - Migrated FileService - Phase 05 (#7076)
Browse files Browse the repository at this point in the history
### Motivation and Context

- Added FileService OpenAI V2 Implementation
- Updated Extensions and UT accordingly
- Updated ClientCore to be used with FileService and allow non-required
`modelId`.
  • Loading branch information
RogerBarreto committed Jul 4, 2024
1 parent 48eb9c3 commit caed23a
Show file tree
Hide file tree
Showing 22 changed files with 860 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,6 @@ public void ItAddOrNotOrganizationIdAttributeWhenProvided()
Assert.False(clientCoreWithoutOrgId.Attributes.ContainsKey(ClientCore.OrganizationKey));
}

[Fact]
public void ItThrowsIfModelIdIsNotProvided()
{
// Act & Assert
Assert.Throws<ArgumentException>(() => new ClientCore(" ", "apikey"));
Assert.Throws<ArgumentException>(() => new ClientCore("", "apikey"));
Assert.Throws<ArgumentNullException>(() => new ClientCore(null!));
}

[Fact]
public void ItThrowsWhenNotUsingCustomEndpointAndApiKeyIsNotProvided()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AudioToText;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Embeddings;
using Microsoft.SemanticKernel.Services;
using Microsoft.SemanticKernel.TextToAudio;
Expand Down Expand Up @@ -132,4 +133,15 @@ public void ItCanAddAudioToTextServiceWithOpenAIClient()
// Assert
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Fact]
public void ItCanAddFileService()
{
// Arrange
var sut = Kernel.CreateBuilder();

// Act
var service = sut.AddOpenAIFiles("key").Build()
.GetRequiredService<OpenAIFileService>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel.Connectors.OpenAI;
using Xunit;

namespace SemanticKernel.Connectors.OpenAI.UnitTests.Extensions;

public class OpenAIFileUploadExecutionSettingsTests
{
[Fact]
public void ItCanCreateOpenAIFileUploadExecutionSettings()
{
// Arrange
var fileName = "file.txt";
var purpose = OpenAIFilePurpose.FineTune;

// Act
var settings = new OpenAIFileUploadExecutionSettings(fileName, purpose);

// Assert
Assert.Equal(fileName, settings.FileName);
Assert.Equal(purpose, settings.Purpose);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AudioToText;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Embeddings;
using Microsoft.SemanticKernel.Services;
using Microsoft.SemanticKernel.TextToAudio;
Expand Down Expand Up @@ -133,4 +134,16 @@ public void ItCanAddAudioToTextServiceWithOpenAIClient()
// Assert
Assert.Equal("model", service.Attributes[AIServiceExtensions.ModelIdKey]);
}

[Fact]
public void ItCanAddFileService()
{
// Arrange
var sut = new ServiceCollection();

// Act
var service = sut.AddOpenAIFiles("key")
.BuildServiceProvider()
.GetRequiredService<OpenAIFileService>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public void ConstructorWithApiKeyWorksCorrectly(bool includeLoggerFactory)
Assert.Equal("model-id", service.Attributes["ModelId"]);
}

[Fact]
public void ItThrowsIfModelIdIsNotProvided()
{
// Act & Assert
Assert.Throws<ArgumentException>(() => new OpenAIAudioToTextService(" ", "apikey"));
Assert.Throws<ArgumentException>(() => new OpenAIAudioToTextService(" ", openAIClient: new("apikey")));
Assert.Throws<ArgumentException>(() => new OpenAIAudioToTextService("", "apikey"));
Assert.Throws<ArgumentException>(() => new OpenAIAudioToTextService("", openAIClient: new("apikey")));
Assert.Throws<ArgumentNullException>(() => new OpenAIAudioToTextService(null!, "apikey"));
Assert.Throws<ArgumentNullException>(() => new OpenAIAudioToTextService(null!, openAIClient: new("apikey")));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
Loading

0 comments on commit caed23a

Please sign in to comment.