Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming Client Result investigation - assistants #46

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1d447d9
When building a release, upload nuget package as a release asset (#27)
hallipr Mar 18, 2024
3957379
Add release url to nuget package (#28)
hallipr Mar 18, 2024
bc4d02f
Use major version 0 (#29)
hallipr Mar 18, 2024
ddbba58
Use better package urls (#30)
hallipr Mar 18, 2024
fed67d6
Add ModifyMessage methods to AssistantClient (#31)
joseharriaga Mar 18, 2024
6374f6d
Move OpenAI to use latest multipart/form-data proposal (#32)
annelo-msft Mar 20, 2024
7b8ea02
Update System.ClientModel to version 1.1.0-alpha.20240319.1 (#35)
joseharriaga Mar 20, 2024
b5032d5
Add Directory.Build.targets to test project to copy assets to output …
joseharriaga Mar 20, 2024
bab92c7
Apply EditorBrowsableState.Never to multipart/form-data protocol meth…
joseharriaga Mar 20, 2024
2f84947
client constructor feedback (#34)
trrwilson Mar 20, 2024
cf3b7c0
Polyfill the C#12 "ExperimentalAttribute" and use it for AssistantCli…
trrwilson Mar 20, 2024
61157b6
incorporate some of the lower-hanging ApiView feedback (#40)
trrwilson Mar 21, 2024
95bd1aa
Move ImageSize to a non-enum type (#33)
trrwilson Mar 21, 2024
228a46f
Update TypeSpec to OpenAPIv3 commit 28a300c5784415af66f81b2acc0db182f…
joseharriaga Mar 26, 2024
109c91d
investigatino
annelo-msft Mar 27, 2024
49f903f
initial enumerator implementation
annelo-msft Mar 27, 2024
920edfe
reworked enumerator and convenience methods
annelo-msft Mar 27, 2024
0e4cbed
nits
annelo-msft Mar 27, 2024
02c627c
nits
annelo-msft Mar 27, 2024
b9f1ad0
Merge branch 'openai-sseclientresult1' into openai-sseclientresult2
annelo-msft Mar 28, 2024
f23bf88
OpenAI: Update convenience layer for multipart/form-data endpoints pe…
annelo-msft Mar 28, 2024
9d6e5da
Merge remote-tracking branch 'joseharriaga/main' into openai-sseclien…
annelo-msft Mar 28, 2024
535c0ab
updates
annelo-msft Mar 28, 2024
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
4 changes: 4 additions & 0 deletions .dotnet/scripts/Add-Customizations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ function Set-LangVersionToLatest {
$root = Split-Path $PSScriptRoot -Parent
$filePath = Join-Path -Path $root -ChildPath "tests\OpenAI.Tests.csproj"
$xml = [xml](Get-Content -Path $filePath)

$xml.Project.PropertyGroup.TargetFramework = "net8.0"

$element = $xml.CreateElement("LangVersion")
$element.InnerText = "latest"
$xml.Project.PropertyGroup.AppendChild($element) | Out-Null

$xml.Save($filePath)
}

Expand Down
4 changes: 2 additions & 2 deletions .dotnet/scripts/Update-ClientModel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function Update-SystemClientModelPackage {
$directory = Join-Path -Path $root -ChildPath "src"
Set-Location -Path $directory
dotnet remove "OpenAI.csproj" package "System.ClientModel"
dotnet add "OpenAI.csproj" package "System.ClientModel" --version "1.1.0-alpha.20240305.1" --source "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"
dotnet add "OpenAI.csproj" package "System.ClientModel" --version "1.1.0-alpha.20240319.1" --source "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"

# Update System.ClientModel package in OpenAI.Tests.csproj
$directory = Join-Path -Path $root -ChildPath "tests"
Set-Location -Path $directory
dotnet remove "OpenAI.Tests.csproj" package "System.ClientModel"
dotnet add "OpenAI.Tests.csproj" package "System.ClientModel" --version "1.1.0-alpha.20240305.1" --source "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"
dotnet add "OpenAI.Tests.csproj" package "System.ClientModel" --version "1.1.0-alpha.20240319.1" --source "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"

Set-Location -Path $current
}
Expand Down
22 changes: 20 additions & 2 deletions .dotnet/src/Custom/Assistants/AssistantClient.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public virtual async Task<ClientResult> GetAssistantFileAssociationAsync(

/// <inheritdoc cref="Internal.Assistants.GetAssistantFiles(string, int?, string, string, string, RequestOptions)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult GetAssistantFileAssociation(
public virtual ClientResult GetAssistantFileAssociations(
string assistantId,
int? maxResults,
string createdSortOrder,
Expand All @@ -133,7 +133,7 @@ public virtual ClientResult GetAssistantFileAssociation(

/// <inheritdoc cref="Internal.Assistants.GetAssistantFilesAsync(string, int?, string, string, string, RequestOptions)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> GetAssistantFileAssociationAsync(
public virtual async Task<ClientResult> GetAssistantFileAssociationsAsync(
string assistantId,
int? maxResults,
string createdSortOrder,
Expand Down Expand Up @@ -248,6 +248,24 @@ public virtual async Task<ClientResult> GetMessageAsync(
RequestOptions options)
=> await MessageShim.GetMessageAsync(threadId, messageId, options).ConfigureAwait(false);

/// <inheritdoc cref="Internal.Messages.ModifyMessage(string, string, BinaryContent, RequestOptions)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult ModifyMessage(
string threadId,
string messageId,
BinaryContent content,
RequestOptions options)
=> MessageShim.ModifyMessage(threadId, messageId, content, options);

/// <inheritdoc cref="Internal.Messages.ModifyMessageAsync(string, string, BinaryContent, RequestOptions)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> ModifyMessageAsync(
string threadId,
string messageId,
BinaryContent content,
RequestOptions options)
=> await MessageShim.ModifyMessageAsync(threadId, messageId, content, options).ConfigureAwait(false);

/// <inheritdoc cref="Internal.Messages.GetMessages(string, int?, string, string, string, RequestOptions)"/>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult GetMessages(
Expand Down
160 changes: 56 additions & 104 deletions .dotnet/src/Custom/Assistants/AssistantClient.cs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions .dotnet/src/Custom/Assistants/MessageModificationOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace OpenAI.Assistants;

/// <summary>
/// Represents additional options available when modifying an existing <see cref="ThreadMessage"/>.
/// </summary>
public partial class MessageModificationOptions
{
/// <summary>
/// A replacement for the optional key/value mapping of additional, supplemental data items to attach to the
/// <see cref="ThreadMessage"/>. This information may be useful for storing custom details in a structured format.
/// </summary>
/// <remarks>
/// <list type="bullet">
/// <item><b>Keys</b> can be a maximum of 64 characters in length.</item>
/// <item><b>Values</b> can be a maximum of 512 characters in length.</item>
/// </list>
/// </remarks>
public IDictionary<string, string> Metadata { get; } = new ChangeTrackingDictionary<string, string>();
}
3 changes: 0 additions & 3 deletions .dotnet/src/Custom/Assistants/ThreadModificationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenAI.ClientShared.Internal;
using System.ClientModel.Internal;

using System.Collections.Generic;

namespace OpenAI.Assistants;
Expand Down
5 changes: 0 additions & 5 deletions .dotnet/src/Custom/Assistants/ToolOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@ public ToolOutput(string toolCallId, string output = null)
Id = toolCallId;
Output = output;
}

[SetsRequiredMembers]
public ToolOutput(RequiredToolCall toolCall, string output = null)
: this(toolCall.Id, output)
{ }
}
180 changes: 179 additions & 1 deletion .dotnet/src/Custom/Audio/AudioClient.Protocol.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.ClientModel;
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;

namespace OpenAI.Audio;
Expand All @@ -16,4 +18,180 @@ public virtual ClientResult GenerateSpeechFromText(BinaryContent content, Reques
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> GenerateSpeechFromTextAsync(BinaryContent content, RequestOptions options = null)
=> await Shim.CreateSpeechAsync(content, options).ConfigureAwait(false);

/// <summary>
/// [Protocol Method] Transcribes audio into the input language.
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// <item>
/// <description>
/// Please try the simpler <see cref="TranscribeAudio(BinaryData, string, AudioTranscriptionOptions)"/> or <see cref="TranscribeAudio(Stream, string, AudioTranscriptionOptions)"/> convenience overload with strongly typed models first.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> The content to send as the body of the request. </param>
/// <param name="contentType"> The content type of the request. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult TranscribeAudio(BinaryContent content, string contentType, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));

options ??= new RequestOptions();

using PipelineMessage message = CreateCreateTranscriptionRequest(content, contentType, options);

Shim.Pipeline.Send(message);

PipelineResponse response = message.Response!;

if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)
{
throw new ClientResultException(response);
}

return ClientResult.FromResponse(response);
}

/// <summary>
/// [Protocol Method] Transcribes audio into the input language.
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// <item>
/// <description>
/// Please try the simpler <see cref="TranscribeAudioAsync(BinaryData, string, AudioTranscriptionOptions)"/> or <see cref="TranscribeAudioAsync(Stream, string, AudioTranscriptionOptions)"/> convenience overload with strongly typed models first.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> The content to send as the body of the request. </param>
/// <param name="contentType"> The content type of the request. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> or <paramref name="contentType"/> is null. </exception>
/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> TranscribeAudioAsync(BinaryContent content, string contentType, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));

options ??= new RequestOptions();

using PipelineMessage message = CreateCreateTranscriptionRequest(content, contentType, options);

Shim.Pipeline.Send(message);

PipelineResponse response = message.Response!;

if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)
{
throw await ClientResultException.CreateAsync(response).ConfigureAwait(false);
}

return ClientResult.FromResponse(response);
}

/// <summary>
/// [Protocol Method] Translates audio into English.
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// <item>
/// <description>
/// Please try the simpler <see cref="TranslateAudio(BinaryData, string, AudioTranslationOptions)"/> or <see cref="TranslateAudio(Stream, string, AudioTranslationOptions)"/> convenience overload with strongly typed models first.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> The content to send as the body of the request. </param>
/// <param name="contentType"> The content type of the request. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual ClientResult TranslateAudio(BinaryContent content, string contentType, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));

options ??= new RequestOptions();

using PipelineMessage message = CreateCreateTranslationRequest(content, contentType, options);

Shim.Pipeline.Send(message);

PipelineResponse response = message.Response!;

if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)
{
throw new ClientResultException(response);
}

return ClientResult.FromResponse(response);
}

/// <summary>
/// [Protocol Method] Translates audio into English.
/// <list type="bullet">
/// <item>
/// <description>
/// This <see href="https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/ProtocolMethods.md">protocol method</see> allows explicit creation of the request and processing of the response for advanced scenarios.
/// </description>
/// </item>
/// <item>
/// <description>
/// Please try the simpler <see cref="TranslateAudioAsync(BinaryData, string, AudioTranslationOptions)"/> or <see cref="TranslateAudioAsync(Stream, string, AudioTranslationOptions)"/> convenience overload with strongly typed models first.
/// </description>
/// </item>
/// </list>
/// </summary>
/// <param name="content"> The content to send as the body of the request. </param>
/// <param name="contentType"> The content type of the request. </param>
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
/// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception>
/// <exception cref="ArgumentException"> <paramref name="contentType"/> is an empty string, and was expected to be non-empty. </exception>
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
/// <returns> The response returned from the service. </returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<ClientResult> TranslateAudioAsync(BinaryContent content, string contentType, RequestOptions options = null)
{
Argument.AssertNotNull(content, nameof(content));
Argument.AssertNotNullOrEmpty(contentType, nameof(contentType));

options ??= new RequestOptions();

using PipelineMessage message = CreateCreateTranslationRequest(content, contentType, options);

Shim.Pipeline.Send(message);

PipelineResponse response = message.Response!;

if (response.IsError && options.ErrorOptions == ClientErrorBehaviors.Default)
{
throw await ClientResultException.CreateAsync(response).ConfigureAwait(false);
}

return ClientResult.FromResponse(response);
}
}
Loading
Loading