Skip to content

Commit

Permalink
.Net: Allow access KernelFunction.ExecutionSettings from IAIServiceSe…
Browse files Browse the repository at this point in the history
…lector (#4860)

### Motivation and Context

Closes #4487 

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

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

- [ ] The code builds clean without any errors or warnings
- [ ] 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
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
markwallace-microsoft authored Feb 14, 2024
1 parent 1490eb6 commit 4671853
Show file tree
Hide file tree
Showing 13 changed files with 540 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.SemanticKernel.Text;
Expand All @@ -17,25 +18,61 @@ public sealed class OpenAIAudioToTextExecutionSettings : PromptExecutionSettings
/// Should be in format {filename}.{extension}
/// </summary>
[JsonPropertyName("filename")]
public string Filename { get; set; }
public string Filename
{
get => this._filename;

set
{
this.ThrowIfFrozen();
this._filename = value;
}
}

/// <summary>
/// An optional language of the audio data as two-letter ISO-639-1 language code (e.g. 'en' or 'es').
/// </summary>
[JsonPropertyName("language")]
public string? Language { get; set; }
public string? Language
{
get => this._language;

set
{
this.ThrowIfFrozen();
this._language = value;
}
}

/// <summary>
/// An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
/// </summary>
[JsonPropertyName("prompt")]
public string? Prompt { get; set; }
public string? Prompt
{
get => this._prompt;

set
{
this.ThrowIfFrozen();
this._prompt = value;
}
}

/// <summary>
/// The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt. Default is 'json'.
/// </summary>
[JsonPropertyName("response_format")]
public string ResponseFormat { get; set; } = "json";
public string ResponseFormat
{
get => this._responseFormat;

set
{
this.ThrowIfFrozen();
this._responseFormat = value;
}
}

/// <summary>
/// The sampling temperature, between 0 and 1.
Expand All @@ -44,15 +81,38 @@ public sealed class OpenAIAudioToTextExecutionSettings : PromptExecutionSettings
/// Default is 0.
/// </summary>
[JsonPropertyName("temperature")]
public float Temperature { get; set; } = 0;
public float Temperature
{
get => this._temperature;

set
{
this.ThrowIfFrozen();
this._temperature = value;
}
}

/// <summary>
/// Creates an instance of <see cref="OpenAIAudioToTextExecutionSettings"/> class.
/// </summary>
/// <param name="filename">Filename or identifier associated with audio data. Should be in format {filename}.{extension}</param>
public OpenAIAudioToTextExecutionSettings(string filename)
{
this.Filename = filename;
this._filename = filename;
}

/// <inheritdoc/>
public override PromptExecutionSettings Clone()
{
return new OpenAIAudioToTextExecutionSettings(this.Filename)
{
ModelId = this.ModelId,
ExtensionData = this.ExtensionData is not null ? new Dictionary<string, object>(this.ExtensionData) : null,
Temperature = this.Temperature,
ResponseFormat = this.ResponseFormat,
Language = this.Language,
Prompt = this.Prompt
};
}

/// <summary>
Expand Down Expand Up @@ -83,4 +143,14 @@ public OpenAIAudioToTextExecutionSettings(string filename)

throw new ArgumentException($"Invalid execution settings, cannot convert to {nameof(OpenAIAudioToTextExecutionSettings)}", nameof(executionSettings));
}

#region private ================================================================================

private float _temperature = 0;
private string _responseFormat = "json";
private string _filename;
private string? _language;
private string? _prompt;

#endregion
}
Loading

0 comments on commit 4671853

Please sign in to comment.