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

Update to use MGC #305

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .dotnet/Configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"output-folder": ".",
"namespace": "OpenAI",
"library-name": "OpenAI",
"unreferenced-types-handling": "keepAll",
"use-model-reader-writer": true,
"disable-xml-docs": true
}
20 changes: 10 additions & 10 deletions .dotnet/src/Custom/Assistants/AssistantClient.Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public virtual async Task<ClientResult> CreateAssistantAsync(BinaryContent conte
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateAssistantRequest(content, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -39,7 +39,7 @@ public virtual ClientResult CreateAssistant(BinaryContent content, RequestOption
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateAssistantRequest(content, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand Down Expand Up @@ -69,7 +69,7 @@ public virtual ClientResult CreateAssistant(BinaryContent content, RequestOption
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual AsyncCollectionResult GetAssistantsAsync(int? limit, string order, string after, string before, RequestOptions options)
{
return new AsyncAssistantCollectionResult(this, _pipeline, options, limit, order, after, before);
return new AsyncAssistantCollectionResult(this, Pipeline, options, limit, order, after, before);
}

/// <summary>
Expand Down Expand Up @@ -99,7 +99,7 @@ public virtual AsyncCollectionResult GetAssistantsAsync(int? limit, string order
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual CollectionResult GetAssistants(int? limit, string order, string after, string before, RequestOptions options)
{
return new AssistantCollectionResult(this, _pipeline, options, limit, order, after, before);
return new AssistantCollectionResult(this, Pipeline, options, limit, order, after, before);
}

/// <summary>
Expand All @@ -117,7 +117,7 @@ public virtual async Task<ClientResult> GetAssistantAsync(string assistantId, Re
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

using PipelineMessage message = CreateGetAssistantRequest(assistantId, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -135,7 +135,7 @@ public virtual ClientResult GetAssistant(string assistantId, RequestOptions opti
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

using PipelineMessage message = CreateGetAssistantRequest(assistantId, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand All @@ -155,7 +155,7 @@ public virtual async Task<ClientResult> ModifyAssistantAsync(string assistantId,
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateModifyAssistantRequest(assistantId, content, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -175,7 +175,7 @@ public virtual ClientResult ModifyAssistant(string assistantId, BinaryContent co
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateModifyAssistantRequest(assistantId, content, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand All @@ -193,7 +193,7 @@ public virtual async Task<ClientResult> DeleteAssistantAsync(string assistantId,
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

using PipelineMessage message = CreateDeleteAssistantRequest(assistantId, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -211,7 +211,7 @@ public virtual ClientResult DeleteAssistant(string assistantId, RequestOptions o
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

using PipelineMessage message = CreateDeleteAssistantRequest(assistantId, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <inheritdoc cref="InternalAssistantMessageClient.CreateMessageAsync"/>
Expand Down
53 changes: 28 additions & 25 deletions .dotnet/src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,41 @@ namespace OpenAI.Assistants;
[CodeGenSuppress("AssistantClient", typeof(ClientPipeline), typeof(ApiKeyCredential), typeof(Uri))]
[CodeGenSuppress("CreateAssistantAsync", typeof(AssistantCreationOptions))]
[CodeGenSuppress("CreateAssistant", typeof(AssistantCreationOptions))]
[CodeGenSuppress("GetAssistantAsync", typeof(string))]
[CodeGenSuppress("GetAssistant", typeof(string))]
[CodeGenSuppress("ListAssistantAsync", typeof(string))]
[CodeGenSuppress("ListAssistant", typeof(string))]
[CodeGenSuppress("ModifyAssistantAsync", typeof(string), typeof(AssistantModificationOptions))]
[CodeGenSuppress("ModifyAssistant", typeof(string), typeof(AssistantModificationOptions))]
[CodeGenSuppress("DeleteAssistantAsync", typeof(string))]
[CodeGenSuppress("DeleteAssistant", typeof(string))]
[CodeGenSuppress("GetAssistantsAsync", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string))]
[CodeGenSuppress("GetAssistants", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string))]
[CodeGenSuppress("ListAssistantsAsync", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string))]
[CodeGenSuppress("ListAssistants", typeof(int?), typeof(AssistantCollectionOrder?), typeof(string), typeof(string))]
public partial class AssistantClient
{
private readonly InternalAssistantMessageClient _messageSubClient;
private readonly InternalAssistantRunClient _runSubClient;
private readonly InternalAssistantThreadClient _threadSubClient;

// CUSTOM: Remove virtual keyword.
/// <summary>
/// The HTTP pipeline for sending and receiving REST requests and responses.
/// </summary>
public ClientPipeline Pipeline => _pipeline;

// CUSTOM: Added as a convenience.
/// <summary> Initializes a new instance of <see cref="AssistantClient">. </summary>
/// <summary> Initializes a new instance of <see cref="AssistantClient"/>. </summary>
/// <param name="apiKey"> The API key to authenticate with the service. </param>
/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
public AssistantClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
{
}

// CUSTOM: Added as a convenience.
/// <summary> Initializes a new instance of <see cref="AssistantClient"/>. </summary>
/// <param name="apiKey"> The API key to authenticate with the service. </param>
/// <param name="options"> The options to configure the client. </param>
/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
public AssistantClient(string apiKey, OpenAIClientOptions options) : this(new ApiKeyCredential(apiKey), options)
{
}

// CUSTOM:
// - Used a custom pipeline.
// - Demoted the endpoint parameter to be a property in the options class.
/// <summary> Initializes a new instance of <see cref="AssistantClient">. </summary>
/// <summary> Initializes a new instance of <see cref="AssistantClient"/>. </summary>
/// <param name="credential"> The API key to authenticate with the service. </param>
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
public AssistantClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
Expand All @@ -57,7 +60,7 @@ public partial class AssistantClient
// CUSTOM:
// - Used a custom pipeline.
// - Demoted the endpoint parameter to be a property in the options class.
/// <summary> Initializes a new instance of <see cref="AssistantClient">. </summary>
/// <summary> Initializes a new instance of <see cref="AssistantClient"/>. </summary>
/// <param name="credential"> The API key to authenticate with the service. </param>
/// <param name="options"> The options to configure the client. </param>
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
Expand All @@ -66,18 +69,18 @@ public AssistantClient(ApiKeyCredential credential, OpenAIClientOptions options)
Argument.AssertNotNull(credential, nameof(credential));
options ??= new OpenAIClientOptions();

_pipeline = OpenAIClient.CreatePipeline(credential, options);
Pipeline = OpenAIClient.CreatePipeline(credential, options);
_endpoint = OpenAIClient.GetEndpoint(options);
_messageSubClient = new(_pipeline, options);
_runSubClient = new(_pipeline, options);
_threadSubClient = new(_pipeline, options);
_messageSubClient = new(Pipeline, options);
_runSubClient = new(Pipeline, options);
_threadSubClient = new(Pipeline, options);
}

// CUSTOM:
// - Used a custom pipeline.
// - Demoted the endpoint parameter to be a property in the options class.
// - Made protected.
/// <summary> Initializes a new instance of <see cref="AssistantClient">. </summary>
/// <summary> Initializes a new instance of <see cref="AssistantClient"/>. </summary>
/// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
/// <param name="options"> The options to configure the client. </param>
/// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
Expand All @@ -86,11 +89,11 @@ protected internal AssistantClient(ClientPipeline pipeline, OpenAIClientOptions
Argument.AssertNotNull(pipeline, nameof(pipeline));
options ??= new OpenAIClientOptions();

_pipeline = pipeline;
Pipeline = pipeline;
_endpoint = OpenAIClient.GetEndpoint(options);
_messageSubClient = new(_pipeline, options);
_runSubClient = new(_pipeline, options);
_threadSubClient = new(_pipeline, options);
_messageSubClient = new(Pipeline, options);
_runSubClient = new(Pipeline, options);
_threadSubClient = new(Pipeline, options);
}

/// <summary> Creates a new assistant. </summary>
Expand All @@ -104,7 +107,7 @@ public virtual async Task<ClientResult<Assistant>> CreateAssistantAsync(string m
options ??= new();
options.Model = model;

ClientResult protocolResult = await CreateAssistantAsync(options?.ToBinaryContent(), cancellationToken.ToRequestOptions()).ConfigureAwait(false);
ClientResult protocolResult = await CreateAssistantAsync(options, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

Expand All @@ -119,7 +122,7 @@ public virtual ClientResult<Assistant> CreateAssistant(string model, AssistantCr
options ??= new();
options.Model = model;

ClientResult protocolResult = CreateAssistant(options?.ToBinaryContent(), cancellationToken.ToRequestOptions());
ClientResult protocolResult = CreateAssistant(options, cancellationToken.ToRequestOptions());
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

Expand Down Expand Up @@ -249,7 +252,7 @@ public virtual async Task<ClientResult<Assistant>> ModifyAssistantAsync(string a
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
Argument.AssertNotNull(options, nameof(options));

using BinaryContent content = options.ToBinaryContent();
using BinaryContent content = options;
ClientResult protocolResult
= await ModifyAssistantAsync(assistantId, content, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
Expand Down
4 changes: 2 additions & 2 deletions .dotnet/src/Custom/Assistants/AssistantCollectionOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public readonly partial struct AssistantCollectionOrder
{
// CUSTOM: Renamed.
[CodeGenMember("Asc")]
public static AssistantCollectionOrder Ascending { get; } = new AssistantCollectionOrder(AscendingValue);
public static AssistantCollectionOrder Ascending { get; } = new AssistantCollectionOrder(AscValue);

// CUSTOM: Renamed.
[CodeGenMember("Desc")]
public static AssistantCollectionOrder Descending { get; } = new AssistantCollectionOrder(DescendingValue);
public static AssistantCollectionOrder Descending { get; } = new AssistantCollectionOrder(DescValue);
}
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Assistants/AssistantResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static AssistantResponseFormat CreateJsonSchemaFormat(
InternalResponseFormatJsonSchemaJsonSchema internalSchema = new(
description,
name,
jsonSchema,
strictSchemaEnabled,
jsonSchema,
null);
return new InternalAssistantResponseFormatJsonSchema(internalSchema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
writer.WriteStringValue(Type);
writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options);
writer.WriteSerializedAdditionalRawData(_additionalBinaryDataProperties, options);
writer.WriteEndObject();
}
}
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Assistants/FileSearchRankingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ internal FileSearchRankingOptions(FileSearchRanker? ranker, float scoreThreshold
{
Ranker = ranker;
ScoreThreshold = scoreThreshold;
SerializedAdditionalRawData = serializedAdditionalRawData;
_additionalBinaryDataProperties = serializedAdditionalRawData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions
writer.WritePropertyName("file_search"u8);
writer.WriteObjectValue(_fileSearch, options);
}
writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options);
writer.WriteSerializedAdditionalRawData(_additionalBinaryDataProperties, options);
writer.WriteEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions
writer.WriteObjectValue<InternalFunctionDefinition>(_internalFunction, options);
writer.WritePropertyName("type"u8);
writer.WriteStringValue(Type);
writer.WriteSerializedAdditionalRawData(SerializedAdditionalRawData, options);
writer.WriteSerializedAdditionalRawData(_additionalBinaryDataProperties, options);
writer.WriteEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public virtual async Task<ClientResult> CreateMessageAsync(string threadId, Bina
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateMessageRequest(threadId, content, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -42,7 +42,7 @@ public virtual ClientResult CreateMessage(string threadId, BinaryContent content
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateCreateMessageRequest(threadId, content, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand All @@ -61,7 +61,7 @@ public virtual async Task<ClientResult> GetMessageAsync(string threadId, string
Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));

using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -80,7 +80,7 @@ public virtual ClientResult GetMessage(string threadId, string messageId, Reques
Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));

using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand All @@ -101,7 +101,7 @@ public virtual async Task<ClientResult> ModifyMessageAsync(string threadId, stri
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -122,7 +122,7 @@ public virtual ClientResult ModifyMessage(string threadId, string messageId, Bin
Argument.AssertNotNull(content, nameof(content));

using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

/// <summary>
Expand All @@ -141,7 +141,7 @@ public virtual async Task<ClientResult> DeleteMessageAsync(string threadId, stri
Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));

using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options);
return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
}

/// <summary>
Expand All @@ -160,6 +160,6 @@ public virtual ClientResult DeleteMessage(string threadId, string messageId, Req
Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));

using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options);
return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options));
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}
}
Loading