Skip to content

Commit

Permalink
.Net: Small improvements in Structured Outputs (#9906)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Resolves: #9897

This PR addresses remaining comments from previous PR related to
Structured Outputs:
#9873.

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
  • Loading branch information
dmytrostruk authored Dec 9, 2024
1 parent 049cbbf commit 68e6dd7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ public async Task StructuredOutputsWithFunctionsFromYamlAsync()
var functionPath = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "Plugins", "MoviePlugins", "MoviePluginYaml", "TopMovies.yaml");

// Load YAML prompt.
using Stream stream = File.OpenRead(functionPath);
using StreamReader reader = new(stream);

var topMoviesYaml = reader.ReadToEnd();
var topMoviesYaml = File.ReadAllText(functionPath);

// Import a function from YAML.
var function = kernel.CreateFunctionFromPromptYaml(topMoviesYaml);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
namespace SemanticKernel.Connectors.OpenAI.UnitTests.Helpers;

/// <summary>
/// Unit tests for <see cref="OpenAIChatResponseFormatHelper"/> class.
/// Unit tests for <see cref="OpenAIChatResponseFormatBuilder"/> class.
/// </summary>
public sealed class OpenAIChatResponseFormatHelperTests
public sealed class OpenAIChatResponseFormatBuilderTests
{
private readonly JsonSerializerOptions _options = new();

public OpenAIChatResponseFormatHelperTests()
public OpenAIChatResponseFormatBuilderTests()
{
this._options.Converters.Add(new BinaryDataJsonConverter());
}
Expand All @@ -33,7 +33,7 @@ public void GetJsonSchemaResponseFormatReturnsChatResponseFormatByDefault(
var jsonElement = jsonDocument.RootElement;

// Act
var chatResponseFormat = OpenAIChatResponseFormatHelper.GetJsonSchemaResponseFormat(jsonElement);
var chatResponseFormat = OpenAIChatResponseFormatBuilder.GetJsonSchemaResponseFormat(jsonElement);
var responseFormat = this.GetResponseFormat(chatResponseFormat);

// Assert
Expand Down Expand Up @@ -79,7 +79,7 @@ public void GetJsonSchemaResponseFormatThrowsExceptionWhenSchemaDoesNotExist()
var jsonElement = jsonDocument.RootElement;

// Act & Assert
Assert.Throws<ArgumentException>(() => OpenAIChatResponseFormatHelper.GetJsonSchemaResponseFormat(jsonElement));
Assert.Throws<ArgumentException>(() => OpenAIChatResponseFormatBuilder.GetJsonSchemaResponseFormat(jsonElement));
}

public static TheoryData<string, string, bool?> ChatResponseFormatJson => new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,10 @@ protected virtual ChatCompletionOptions CreateChatCompletionOptions(
}
}

return OpenAIChatResponseFormatHelper.GetJsonSchemaResponseFormat(formatElement);
return OpenAIChatResponseFormatBuilder.GetJsonSchemaResponseFormat(formatElement);

case Type formatObjectType:
return OpenAIChatResponseFormatHelper.GetJsonSchemaResponseFormat(formatObjectType);
return OpenAIChatResponseFormatBuilder.GetJsonSchemaResponseFormat(formatObjectType);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Microsoft.SemanticKernel.Connectors.OpenAI;

/// <summary>
/// Helper class to process <see cref="ChatResponseFormat"/> object.
/// Helper class to build <see cref="ChatResponseFormat"/> object.
/// </summary>
internal static class OpenAIChatResponseFormatHelper
internal static class OpenAIChatResponseFormatBuilder
{
/// <summary>
/// <see cref="JsonSchemaMapperConfiguration"/> for JSON schema format for structured outputs.
Expand Down

0 comments on commit 68e6dd7

Please sign in to comment.