Skip to content

Commit

Permalink
refresh (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
trrwilson authored Jul 23, 2024
1 parent 7bdecfd commit d77539c
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 207 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

- ([#49](https://github.com/openai/openai-dotnet/issues/49)) Fixed a bug with extensible enums implementing case-insensitive equality but case-sensitive hash codes. (commit_hash)
- ([#57](https://github.com/openai/openai-dotnet/issues/57)) Fixed a bug with requests URIs with query string parameter potentially containing a malformed double question mark (`??`) on .NET Framework (net481). (commit_hash)

### Other Changes
- Added optional `CancellationToken` parameters to methods for `AssistantClient` and `VectorStore` client, consistent with past changes in [19a65a0](https://github.com/openai/openai-dotnet/commit/19a65a0a943fa3bef1ec8504708aaa526a1ee03a) (commit_link_)
- Fixed Assistants `FileSearchToolDefinition`'s `MaxResults` parameter to appropriately serialize and deserialize the value (commit_link)
- Added missing `[EditorBrowsable(EditorBrowsableState.Never)]` attributes to `AssistantClient` protocol methods, which should improve discoverability of the strongly typed methods (commit_link)

## 2.0.0-beta.7 (2024-06-24)

Expand Down
277 changes: 145 additions & 132 deletions api/api.md

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/Custom/Assistants/AssistantClient.Protocol.cs

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions src/Custom/Assistants/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ 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("ModifyAssistantAsync", typeof(string), typeof(AssistantModificationOptions))]
[CodeGenSuppress("ModifyAssistant", typeof(string), typeof(AssistantModificationOptions))]
[CodeGenSuppress("DeleteAssistantAsync", typeof(string))]
[CodeGenSuppress("DeleteAssistant", typeof(string))]
[CodeGenSuppress("GetAssistantsAsync", typeof(int?), typeof(ListOrder?), typeof(string), typeof(string))]
Expand Down Expand Up @@ -199,6 +203,69 @@ public virtual PageCollection<Assistant> GetAssistants(
return PageCollectionHelpers.Create(enumerator);
}

/// <summary>
/// Gets an instance representing an existing <see cref="Assistant"/> based on its ID.
/// </summary>
/// <param name="assistantId"> The ID of the Assistant to retrieve. </param>
/// <param name="cancellationToken">A token that can be used to cancel this method call.</param>
/// <returns>An <see cref="Assistant"/> instance representing the state of the Assistant with the provided ID.</returns>
public virtual async Task<ClientResult<Assistant>> GetAssistantAsync(string assistantId, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

ClientResult protocolResult = await GetAssistantAsync(assistantId, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

/// <summary>
/// Gets an instance representing an existing <see cref="Assistant"/> based on its ID.
/// </summary>
/// <param name="assistantId"> The ID of the Assistant to retrieve. </param>
/// <param name="cancellationToken">A token that can be used to cancel this method call.</param>
/// <returns>An <see cref="Assistant"/> instance representing the state of the Assistant with the provided ID.</returns>
public virtual ClientResult<Assistant> GetAssistant(string assistantId, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

ClientResult protocolResult = GetAssistant(assistantId, cancellationToken.ToRequestOptions());
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

/// <summary>
/// Modifies an existing <see cref="Assistant"/>.
/// </summary>
/// <param name="assistantId"> The ID of the Assistant to retrieve. </param>
/// <param name="options"> The new options to apply to the existing Assistant. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> An updated <see cref="Assistant"/> instance representing the state of the Assistant with the provided ID. </returns>
public virtual async Task<ClientResult<Assistant>> ModifyAssistantAsync(string assistantId, AssistantModificationOptions options, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
Argument.AssertNotNull(options, nameof(options));

using BinaryContent content = options.ToBinaryContent();
ClientResult protocolResult
= await ModifyAssistantAsync(assistantId, content, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

/// <summary>
/// Modifies an existing <see cref="Assistant"/>.
/// </summary>
/// <param name="assistantId"> The ID of the Assistant to retrieve. </param>
/// <param name="options"> The new options to apply to the existing Assistant. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> An updated <see cref="Assistant"/> instance representing the state of the Assistant with the provided ID. </returns>
public virtual ClientResult<Assistant> ModifyAssistant(string assistantId, AssistantModificationOptions options, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
Argument.AssertNotNull(options, nameof(options));

using BinaryContent content = options.ToBinaryContent();
ClientResult protocolResult = ModifyAssistant(assistantId, content, null);
return CreateResultFromProtocol(protocolResult, Assistant.FromResponse);
}

/// <summary>
/// Deletes an existing <see cref="Assistant"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOption
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
writer.WriteStringValue(Type);
if (Optional.IsDefined(MaxResults))
{
writer.WritePropertyName("file_search"u8);
writer.WriteStartObject();
writer.WritePropertyName("max_num_results"u8);
writer.WriteNumberValue(MaxResults.Value);
writer.WriteEndObject();
}
writer.WriteSerializedAdditionalRawData(_serializedAdditionalRawData, options);
writer.WriteEndObject();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Assistants/FileSearchToolDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public partial class FileSearchToolDefinition : ToolDefinition
{
public int? MaxResults
{
get => _fileSearch.InternalMaxNumResults;
get => _fileSearch?.InternalMaxNumResults;
init => _fileSearch.InternalMaxNumResults = value;
}

Expand Down
68 changes: 68 additions & 0 deletions src/Custom/VectorStores/VectorStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace OpenAI.VectorStores;
[CodeGenClient("VectorStores")]
[CodeGenSuppress("CreateVectorStoreAsync", typeof(VectorStoreCreationOptions))]
[CodeGenSuppress("CreateVectorStore", typeof(VectorStoreCreationOptions))]
[CodeGenSuppress("GetVectorStoreAsync", typeof(string))]
[CodeGenSuppress("GetVectorStore", typeof(string))]
[CodeGenSuppress("ModifyVectorStoreAsync", typeof(string), typeof(VectorStoreModificationOptions))]
[CodeGenSuppress("ModifyVectorStore", typeof(string), typeof(VectorStoreModificationOptions))]
[CodeGenSuppress("DeleteVectorStoreAsync", typeof(string))]
[CodeGenSuppress("DeleteVectorStore", typeof(string))]
[CodeGenSuppress("GetVectorStoresAsync", typeof(int?), typeof(ListOrder?), typeof(string), typeof(string))]
Expand Down Expand Up @@ -101,6 +105,70 @@ public virtual ClientResult<VectorStore> CreateVectorStore(VectorStoreCreationOp
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

/// <summary>
/// Gets an instance representing an existing <see cref="VectorStore"/> based on its ID.
/// </summary>
/// <param name="vectorStoreId"> The ID of the vector store to retrieve. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> A representation of an existing <see cref="VectorStore"/>. </returns>
public virtual async Task<ClientResult<VectorStore>> GetVectorStoreAsync(string vectorStoreId, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));

ClientResult result
= await GetVectorStoreAsync(vectorStoreId, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return ClientResult.FromValue(
VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

/// <summary>
/// Gets an instance representing an existing <see cref="VectorStore"/> based on its ID.
/// </summary>
/// <param name="vectorStoreId"> The ID of the vector store to retrieve. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> A representation of an existing <see cref="VectorStore"/>. </returns>
public virtual ClientResult<VectorStore> GetVectorStore(string vectorStoreId, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));

ClientResult result = GetVectorStore(vectorStoreId, cancellationToken.ToRequestOptions());
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

/// <summary>
/// Modifies an existing <see cref="VectorStore"/>.
/// </summary>
/// <param name="vectorStoreId"> The ID of the <see cref="VectorStore"/> to modify. </param>
/// <param name="vectorStore"> The new options to apply to the <see cref="VectorStore"/>. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> An updated representation of the modified <see cref="VectorStore"/>. </returns>
public virtual async Task<ClientResult<VectorStore>> ModifyVectorStoreAsync(string vectorStoreId, VectorStoreModificationOptions vectorStore, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));
Argument.AssertNotNull(vectorStore, nameof(vectorStore));

using BinaryContent content = vectorStore.ToBinaryContent();
ClientResult result = await ModifyVectorStoreAsync(vectorStoreId, content, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

/// <summary>
/// Modifies an existing <see cref="VectorStore"/>.
/// </summary>
/// <param name="vectorStoreId"> The ID of the <see cref="VectorStore"/> to modify. </param>
/// <param name="vectorStore"> The new options to apply to the <see cref="VectorStore"/>. </param>
/// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
/// <returns> An updated representation of the modified <see cref="VectorStore"/>. </returns>
public virtual ClientResult<VectorStore> ModifyVectorStore(string vectorStoreId, VectorStoreModificationOptions vectorStore, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));
Argument.AssertNotNull(vectorStore, nameof(vectorStore));

using BinaryContent content = vectorStore.ToBinaryContent();
ClientResult result = ModifyVectorStore(vectorStoreId, content, cancellationToken.ToRequestOptions());
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

/// <summary>
/// Deletes a vector store.
/// </summary>
Expand Down
36 changes: 0 additions & 36 deletions src/Generated/AssistantClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,6 @@ protected AssistantClient()
{
}

public virtual async Task<ClientResult<Assistant>> GetAssistantAsync(string assistantId)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

ClientResult result = await GetAssistantAsync(assistantId, null).ConfigureAwait(false);
return ClientResult.FromValue(Assistant.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual ClientResult<Assistant> GetAssistant(string assistantId)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));

ClientResult result = GetAssistant(assistantId, null);
return ClientResult.FromValue(Assistant.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual async Task<ClientResult<Assistant>> ModifyAssistantAsync(string assistantId, AssistantModificationOptions assistant)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
Argument.AssertNotNull(assistant, nameof(assistant));

using BinaryContent content = assistant.ToBinaryContent();
ClientResult result = await ModifyAssistantAsync(assistantId, content, null).ConfigureAwait(false);
return ClientResult.FromValue(Assistant.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual ClientResult<Assistant> ModifyAssistant(string assistantId, AssistantModificationOptions assistant)
{
Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
Argument.AssertNotNull(assistant, nameof(assistant));

using BinaryContent content = assistant.ToBinaryContent();
ClientResult result = ModifyAssistant(assistantId, content, null);
return ClientResult.FromValue(Assistant.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

internal PipelineMessage CreateCreateAssistantRequest(BinaryContent content, RequestOptions options)
{
var message = _pipeline.CreateMessage();
Expand Down
36 changes: 0 additions & 36 deletions src/Generated/VectorStoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,6 @@ internal VectorStoreClient(ClientPipeline pipeline, ApiKeyCredential keyCredenti
_endpoint = endpoint;
}

public virtual async Task<ClientResult<VectorStore>> GetVectorStoreAsync(string vectorStoreId)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));

ClientResult result = await GetVectorStoreAsync(vectorStoreId, null).ConfigureAwait(false);
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual ClientResult<VectorStore> GetVectorStore(string vectorStoreId)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));

ClientResult result = GetVectorStore(vectorStoreId, null);
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual async Task<ClientResult<VectorStore>> ModifyVectorStoreAsync(string vectorStoreId, VectorStoreModificationOptions vectorStore)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));
Argument.AssertNotNull(vectorStore, nameof(vectorStore));

using BinaryContent content = vectorStore.ToBinaryContent();
ClientResult result = await ModifyVectorStoreAsync(vectorStoreId, content, null).ConfigureAwait(false);
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

public virtual ClientResult<VectorStore> ModifyVectorStore(string vectorStoreId, VectorStoreModificationOptions vectorStore)
{
Argument.AssertNotNullOrEmpty(vectorStoreId, nameof(vectorStoreId));
Argument.AssertNotNull(vectorStore, nameof(vectorStore));

using BinaryContent content = vectorStore.ToBinaryContent();
ClientResult result = ModifyVectorStore(vectorStoreId, content, null);
return ClientResult.FromValue(VectorStore.FromResponse(result.GetRawResponse()), result.GetRawResponse());
}

internal PipelineMessage CreateGetVectorStoresRequest(int? limit, string order, string after, string before, RequestOptions options)
{
var message = _pipeline.CreateMessage();
Expand Down
1 change: 1 addition & 0 deletions src/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

<ItemGroup>
<None Include="OpenAI.png" Pack="true" PackagePath="\" />
<None Include="..\CHANGELOG.md" Pack="true" PackagePath="\" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

Expand Down

0 comments on commit d77539c

Please sign in to comment.