Skip to content

Commit

Permalink
feat: Updated client to latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 20, 2024
1 parent e691bb1 commit 55bed2e
Show file tree
Hide file tree
Showing 126 changed files with 580 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<PropertyGroup Label="Nuget">
<Version>2.0.0-alpha.5</Version>
<Version>2.0.0-alpha.6</Version>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>tryAGI and contributors</Authors>
Expand Down
17 changes: 10 additions & 7 deletions src/libs/OpenAI/Client/Assistants/AssistantExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Files;
using OpenAI.Threads;
using System.Threading;
Expand Down Expand Up @@ -25,7 +27,7 @@ public static async Task<AssistantResponse> ModifyAsync(this AssistantResponse a
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>True, if the <see cref="assistant"/> was successfully deleted.</returns>
/// <returns>True, if the assistant was successfully deleted.</returns>
public static async Task<bool> DeleteAsync(this AssistantResponse assistant, CancellationToken cancellationToken = default)
=> await assistant.Client.AssistantsEndpoint.DeleteAssistantAsync(assistant.Id, cancellationToken).ConfigureAwait(false);

Expand All @@ -52,7 +54,7 @@ public static async Task<ListResponse<AssistantFileResponse>> ListFilesAsync(thi
=> await assistant.Client.AssistantsEndpoint.ListFilesAsync(assistant.Id, query, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Attach a file to the <see cref="assistant"/>.
/// Attach a file to the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="file">
Expand All @@ -65,7 +67,7 @@ public static async Task<AssistantFileResponse> AttachFileAsync(this AssistantRe
=> await assistant.Client.AssistantsEndpoint.AttachFileAsync(assistant.Id, file, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Uploads a new file at the specified <see cref="filePath"/> and attaches it to the <see cref="assistant"/>.
/// Uploads a new file at the specified path and attaches it to the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="filePath">The local file path to upload.</param>
Expand Down Expand Up @@ -100,7 +102,7 @@ public static async Task<AssistantFileResponse> RetrieveFileAsync(this Assistant
// => await assistantFile.Client.FilesEndpoint.DownloadFileAsync(assistantFile.Id, directory, deleteCachedFile, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Remove AssistantFile.
/// Remove the file from the assistant it is attached to.
/// </summary>
/// <remarks>
/// Note that removing an AssistantFile does not delete the original File object,
Expand All @@ -114,7 +116,7 @@ public static async Task<bool> RemoveFileAsync(this AssistantFileResponse file,
=> await file.Client.AssistantsEndpoint.RemoveFileAsync(file.AssistantId, file.Id, cancellationToken).ConfigureAwait(false);

/// <summary>
/// Remove AssistantFile.
/// Remove the file from the assistant it is attached to.
/// </summary>
/// <remarks>
/// Note that removing an AssistantFile does not delete the original File object,
Expand All @@ -141,7 +143,7 @@ public static async Task<bool> DeleteFileAsync(this AssistantFileResponse file,
}

/// <summary>
/// Removes and Deletes a file from the <see cref="assistant"/>.
/// Removes and Deletes a file from the assistant.
/// </summary>
/// <param name="assistant"><see cref="AssistantResponse"/>.</param>
/// <param name="fileId">The ID of the file to delete.</param>
Expand All @@ -150,7 +152,8 @@ public static async Task<bool> DeleteFileAsync(this AssistantFileResponse file,
public static async Task<bool> DeleteFileAsync(this AssistantResponse assistant, string fileId, CancellationToken cancellationToken = default)
{
var isRemoved = await assistant.Client.AssistantsEndpoint.RemoveFileAsync(assistant.Id, fileId, cancellationToken).ConfigureAwait(false);
return isRemoved && await assistant.Client.FilesEndpoint.DeleteFileAsync(fileId, cancellationToken).ConfigureAwait(false);
if (!isRemoved) { return false; }
return await assistant.Client.FilesEndpoint.DeleteFileAsync(fileId, cancellationToken).ConfigureAwait(false);
}

#endregion Files
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Assistants/AssistantFileResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Text.Json.Serialization;

Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Assistants/AssistantResponse.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenAI.Assistants
{
/// <summary>
/// Purpose-built AI that uses OpenAIs models and calls tools.
/// Purpose-built AI that uses OpenAI's models and calls tools.
/// </summary>
public sealed class AssistantResponse : BaseResponse
{
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Assistants/AssistantsEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Extensions;
using OpenAI.Files;
using System;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Assistants/CreateAssistantRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Audio/AudioEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using OpenAI.Extensions;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Extensions;
using System;
using System.IO;
using System.Net.Http;
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Audio/AudioResponseFormat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace OpenAI.Audio
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace OpenAI.Audio
{
public enum AudioResponseFormat
{
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Audio/AudioTranscriptionRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.IO;

namespace OpenAI.Audio
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Audio/AudioTranslationRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.IO;

namespace OpenAI.Audio
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Audio/SpeechRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Text.Json.Serialization;
using OpenAI.Extensions;
using OpenAI.Models;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Audio/SpeechResponseFormat.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Runtime.Serialization;

namespace OpenAI.Audio
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Audio/SpeechVoice.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace OpenAI.Audio
{
public enum SpeechVoice
Expand Down
4 changes: 3 additions & 1 deletion src/libs/OpenAI/Client/Authentication/AuthInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Security.Authentication;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Security.Authentication;
using System.Text.Json.Serialization;

namespace OpenAI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.IO;
using System.Text.Json;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;

namespace OpenAI
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Chat/ChatEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using OpenAI.Extensions;
using System;
using System.Collections.Generic;
Expand Down
77 changes: 33 additions & 44 deletions src/libs/OpenAI/Client/Chat/ChatRequest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -9,49 +11,6 @@ namespace OpenAI.Chat
{
public sealed class ChatRequest
{
/// <inheritdoc />
[Obsolete("Use new constructor arguments")]
public ChatRequest(
IEnumerable<Message> messages,
IEnumerable<Function> functions,
string functionCall = null,
string model = null,
double? temperature = null,
double? topP = null,
int? number = null,
string[] stops = null,
int? maxTokens = null,
double? presencePenalty = null,
double? frequencyPenalty = null,
IReadOnlyDictionary<string, double> logitBias = null,
string user = null)
: this(messages, model, frequencyPenalty, logitBias, maxTokens, number, presencePenalty, ChatResponseFormat.Text, maxTokens, stops, temperature, topP, user)
{
var functionList = functions?.ToList();

if (functionList != null && functionList.Any())
{
if (string.IsNullOrWhiteSpace(functionCall))
{
FunctionCall = "auto";
}
else
{
if (!functionCall.Equals("none") &&
!functionCall.Equals("auto"))
{
FunctionCall = new JsonObject { ["name"] = functionCall };
}
else
{
FunctionCall = functionCall;
}
}
}

Functions = functionList?.ToList();
}

/// <inheritdoc />
public ChatRequest(
IEnumerable<Message> messages,
Expand All @@ -67,8 +26,9 @@ public ChatRequest(
string[] stops = null,
double? temperature = null,
double? topP = null,
int? topLogProbs = null,
string user = null)
: this(messages, model, frequencyPenalty, logitBias, maxTokens, number, presencePenalty, responseFormat, number, stops, temperature, topP, user)
: this(messages, model, frequencyPenalty, logitBias, maxTokens, number, presencePenalty, responseFormat, number, stops, temperature, topP, topLogProbs, user)
{
var tooList = tools?.ToList();

Expand Down Expand Up @@ -164,6 +124,10 @@ public ChatRequest(
/// in a ban or exclusive selection of the relevant token.<br/>
/// Defaults to null
/// </param>
/// <param name="topLogProbs">
/// An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,
/// each with an associated log probability.
/// </param>
/// <param name="user">
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
/// </param>
Expand All @@ -180,6 +144,7 @@ public ChatRequest(
string[] stops = null,
double? temperature = null,
double? topP = null,
int? topLogProbs = null,
string user = null)
{
Messages = messages?.ToList();
Expand All @@ -200,6 +165,8 @@ public ChatRequest(
Stops = stops;
Temperature = temperature;
TopP = topP;
LogProbs = topLogProbs.HasValue ? topLogProbs.Value > 0 : null;
TopLogProbs = topLogProbs;
User = user;
}

Expand Down Expand Up @@ -236,6 +203,28 @@ public ChatRequest(
[JsonPropertyName("logit_bias")]
public IReadOnlyDictionary<string, double> LogitBias { get; }

/// <summary>
/// Whether to return log probabilities of the output tokens or not.
/// If true, returns the log probabilities of each output token returned in the content of message.
/// </summary>
/// <remarks>
/// This option is currently not available on the gpt-4-vision-preview model.
/// </remarks>
[JsonPropertyName("logprobs")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public bool? LogProbs { get; }

/// <summary>
/// An integer between 0 and 5 specifying the number of most likely tokens to return at each token position,
/// each with an associated log probability.
/// </summary>
/// <remarks>
/// <see cref="LogProbs"/> must be set to true if this parameter is used.
/// </remarks>
[JsonPropertyName("top_logprobs")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int? TopLogProbs { get; }

/// <summary>
/// The maximum number of tokens allowed for the generated answer.
/// By default, the number of tokens the model can return will be (4096 - prompt tokens).
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Chat/ChatResponse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/OpenAI/Client/Chat/ChatResponseFormat.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Runtime.Serialization;

namespace OpenAI.Chat
Expand Down
Loading

0 comments on commit 55bed2e

Please sign in to comment.