Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/ai/Azure.AI.VoiceLive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var model = "gpt-4o-mini-realtime-preview"; // Specify the model to use
VoiceLiveSession session = await client.StartSessionAsync(model).ConfigureAwait(false);

// Configure session for voice conversation
SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a helpful AI assistant. Respond naturally and conversationally.",
Expand Down Expand Up @@ -188,7 +188,7 @@ await foreach (SessionUpdate serverEvent in session.GetUpdatesAsync().ConfigureA
### Configuring custom voice and advanced features

```C# Snippet:AdvancedVoiceConfiguration
SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a customer service representative. Be helpful and professional.",
Expand Down Expand Up @@ -235,7 +235,7 @@ var getCurrentWeatherFunction = new VoiceLiveFunctionDefinition("get_current_wea
""")
};

SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a weather assistant. Use the get_current_weather function to help users with weather information.",
Expand Down
415 changes: 180 additions & 235 deletions sdk/ai/Azure.AI.VoiceLive/api/Azure.AI.VoiceLive.net8.0.cs

Large diffs are not rendered by default.

415 changes: 180 additions & 235 deletions sdk/ai/Azure.AI.VoiceLive/api/Azure.AI.VoiceLive.netstandard2.0.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private async Task SetupSessionAsync(CancellationToken cancellationToken)
};

// Create conversation session options
var sessionOptions = new SessionOptions
var sessionOptions = new VoiceLiveSessionOptions
{
EchoCancellation = new AudioEchoCancellation(),
InputAudioEchoCancellation = new AudioEchoCancellation(),
Model = _model,
Instructions = _instructions,
Voice = azureVoice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private async Task SetupSessionAsync(CancellationToken cancellationToken)
};

// Create conversation session options with function tools
var sessionOptions = new SessionOptions
var sessionOptions = new VoiceLiveSessionOptions
{
Model = _model,
Instructions = _instructions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task BasicVoiceAssistantExample()
VoiceLiveSession session = await client.StartSessionAsync(model).ConfigureAwait(false);

// Configure session for voice conversation
SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a helpful AI assistant. Respond naturally and conversationally.",
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task AdvancedVoiceConfiguration()
VoiceLiveSession session = await client.StartSessionAsync(model).ConfigureAwait(false);

#region Snippet:AdvancedVoiceConfiguration
SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a customer service representative. Be helpful and professional.",
Expand Down Expand Up @@ -143,7 +143,7 @@ public async Task FunctionCallingExample()
""")
};

SessionOptions sessionOptions = new SessionOptions()
VoiceLiveSessionOptions sessionOptions = new()
{
Model = model,
Instructions = "You are a weather assistant. Use the get_current_weather function to help users with weather information.",
Expand Down
2 changes: 1 addition & 1 deletion sdk/ai/Azure.AI.VoiceLive/src/Azure.AI.VoiceLive.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>
This is the Azure.AI.VoiceLive client library for working with the Azure VoiceLive service.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;

namespace Azure.AI.VoiceLive
{
/// <summary> A single log probability entry for a token. </summary>
public partial class LogProbProperties
{
/// <summary> The bytes that were used to generate the log probability. </summary>
[CodeGenMember("Bytes")]
public BinaryData Bytes { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace Azure.AI.VoiceLive
{
/// <summary>
///
/// </summary>
public partial class ResponseMaxOutputTokensOption : IJsonModel<ResponseMaxOutputTokensOption>
{
void IJsonModel<ResponseMaxOutputTokensOption>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> SerializeConversationMaxTokensChoice(this, writer, options);

ResponseMaxOutputTokensOption IJsonModel<ResponseMaxOutputTokensOption>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
using JsonDocument document = JsonDocument.ParseValue(ref reader);
return DeserializeConversationMaxTokensChoice(document.RootElement, options);
}

BinaryData IPersistableModel<ResponseMaxOutputTokensOption>.Write(ModelReaderWriterOptions options)
{
return ModelReaderWriter.Write(this, options, null);
}

ResponseMaxOutputTokensOption IPersistableModel<ResponseMaxOutputTokensOption>.Create(BinaryData data, ModelReaderWriterOptions options)
=> FromBinaryData(data);

string IPersistableModel<ResponseMaxOutputTokensOption>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";

internal static void SerializeConversationMaxTokensChoice(ResponseMaxOutputTokensOption instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
if (instance._isDefaultNullValue == true)
{
writer.WriteNullValue();
}
else if (instance._stringValue is not null)
{
writer.WriteStringValue(instance._stringValue);
}
else if (instance.NumericValue.HasValue)
{
writer.WriteNumberValue(instance.NumericValue.Value);
}
}

internal static ResponseMaxOutputTokensOption DeserializeConversationMaxTokensChoice(JsonElement element, ModelReaderWriterOptions options = null)
{
if (element.ValueKind == JsonValueKind.Null)
{
return new ResponseMaxOutputTokensOption(isDefaultNullValue: true);
}
if (element.ValueKind == JsonValueKind.String)
{
return new ResponseMaxOutputTokensOption(stringValue: element.GetString());
}
if (element.ValueKind == JsonValueKind.Number)
{
return new ResponseMaxOutputTokensOption(numberValue: element.GetInt32());
}
return null;
}

internal static ResponseMaxOutputTokensOption FromBinaryData(BinaryData bytes)
{
if (bytes is null)
{
return new ResponseMaxOutputTokensOption(isDefaultNullValue: true);
}
using JsonDocument document = JsonDocument.Parse(bytes);
return DeserializeConversationMaxTokensChoice(document.RootElement);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.AI.VoiceLive
{
/// <summary>
/// Represents the maximum number of tokens that may be generated in a response.
/// </summary>
public partial class ResponseMaxOutputTokensOption
{
/// <summary>
/// The numeric equivlant for the number of tokens.
/// </summary>
public int? NumericValue { get; }
private readonly bool? _isDefaultNullValue;
private readonly string _stringValue;

/// <summary>
/// Creates an options class with infinite tokens possible.
/// </summary>
/// <returns></returns>
public static ResponseMaxOutputTokensOption CreateInfiniteMaxTokensOption()
=> new("inf");
/// <summary>
/// Creates an options class with the default number of possible tokens.
/// </summary>
/// <returns></returns>
public static ResponseMaxOutputTokensOption CreateDefaultMaxTokensOption()
=> new(isDefaultNullValue: true);
/// <summary>
/// Creates an options class with a fixed number of tokens.
/// </summary>
/// <param name="maxTokens"></param>
/// <returns></returns>
public static ResponseMaxOutputTokensOption CreateNumericMaxTokensOption(int maxTokens)
=> new(numberValue: maxTokens);
/// <summary>
/// Creates an options class with a fixed number of tokens.
/// </summary>
/// <param name="numberValue"></param>
public ResponseMaxOutputTokensOption(int numberValue)
{
NumericValue = numberValue;
}

internal ResponseMaxOutputTokensOption(string stringValue)
{
_stringValue = stringValue;
}

internal ResponseMaxOutputTokensOption(bool isDefaultNullValue)
{
_isDefaultNullValue = true;
}

internal ResponseMaxOutputTokensOption() { }

/// <summary>
/// Creates a ResponseMaxOutputTokensOptions class from an integer value.
/// </summary>
/// <param name="maxTokens"></param>
public static implicit operator ResponseMaxOutputTokensOption(int maxTokens)
=> CreateNumericMaxTokensOption(maxTokens);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable

using System;
using System.Collections.Generic;

namespace Azure.AI.VoiceLive
{
/// <summary> The SessionUpdateInputAudioBufferSpeechStopped. </summary>
public partial class SessionUpdateInputAudioBufferSpeechStopped
{
/// <summary>
/// Time from the start of all audio written to the buffer during the
/// session when speech was first detected. This will correspond to the
/// beginning of audio sent to the model, and thus includes the
/// `prefix_padding_ms` configured in the Session.
/// </summary>
public TimeSpan AudioEnd { get => TimeSpan.FromMilliseconds(AudioEndMs); }

internal int AudioEndMsAs { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#nullable disable

using System;
using System.Collections.Generic;

namespace Azure.AI.VoiceLive
{
/// <summary> The SessionUpdateInputAudioBufferSpeechStarted. </summary>
public partial class SessionUpdateInputAudioBufferSpeechStarted
{
/// <summary>
/// Time from the start of all audio written to the buffer during the
/// session when speech was first detected. This will correspond to the
/// beginning of audio sent to the model, and thus includes the
/// `prefix_padding_ms` configured in the Session.
/// </summary>
public TimeSpan AudioStart { get => TimeSpan.FromMilliseconds(AudioStartMs); }

internal int AudioStartMs { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace Azure.AI.VoiceLive
{
/// <summary>
///
/// </summary>
public partial class ToolChoiceOption : IJsonModel<ToolChoiceOption>
{
void IJsonModel<ToolChoiceOption>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> SerializeConversationToolChoiceOption(this, writer, options);

ToolChoiceOption IJsonModel<ToolChoiceOption>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
using JsonDocument document = JsonDocument.ParseValue(ref reader);
return DeserializeConversationToolChoiceOption(document.RootElement, options);
}

BinaryData IPersistableModel<ToolChoiceOption>.Write(ModelReaderWriterOptions options)
{
return ModelReaderWriter.Write(this, options, null);
}

ToolChoiceOption IPersistableModel<ToolChoiceOption>.Create(BinaryData data, ModelReaderWriterOptions options)
=> FromBinaryData(data);

string IPersistableModel<ToolChoiceOption>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";

internal static void SerializeConversationToolChoiceOption(ToolChoiceOption instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
if (instance.ToolCallConstraint.HasValue)
{
writer.WriteStringValue(instance.ToolCallConstraint.Value.ToString());
}
else if (instance.FunctionName is not null)
{
var functionObject = new ToolChoiceFunctionObjectFunction(name: instance.FunctionName);
writer.WriteObjectValue(functionObject, options);
}
}

internal static ToolChoiceOption DeserializeConversationToolChoiceOption(JsonElement element, ModelReaderWriterOptions options = null)
{
if (element.ValueKind == JsonValueKind.Object)
{
var functionObject = ToolChoiceFunctionObjectFunction.DeserializeToolChoiceFunctionObjectFunction(element, options);
return new ToolChoiceOption(functionObject.Name);
}
if (element.ValueKind == JsonValueKind.String)
{
return new ToolChoiceOption(new ToolChoiceLiteral(element.GetString()));
}
return null;
}

internal static ToolChoiceOption FromBinaryData(BinaryData bytes)
{
if (bytes is null)
{
return new ToolChoiceOption();
}
using JsonDocument document = JsonDocument.Parse(bytes);
return DeserializeConversationToolChoiceOption(document.RootElement);
}
}
}
Loading