Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson committed Nov 17, 2023
1 parent e771c55 commit 0d9716b
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 125 deletions.
5 changes: 2 additions & 3 deletions OpenAI-DotNet-Tests/TestFixture_11_Assistants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task Test_01_CreateAssistant()
},
tools: new List<Tool>
{
// Tool.Retrieval
Tool.Retrieval
},
fileIds: new List<string> { assistantFileId });
var result = await OpenAIClient.AssistantsEndpoint.CreateAssistantAsync(request);
Expand Down Expand Up @@ -117,8 +117,7 @@ public async Task Test_04_DeleteAssistantFile()
{
Assert.IsNotNull(file);

var isDeleted =
await OpenAIClient.AssistantsEndpoint.DeleteAssistantFileAsync(file.AssistantId, file.Id);
var isDeleted = await OpenAIClient.AssistantsEndpoint.DeleteAssistantFileAsync(file.AssistantId, file.Id);

Assert.IsTrue(isDeleted);
}
Expand Down
21 changes: 10 additions & 11 deletions OpenAI-DotNet-Tests/TestFixture_15_TheadRuns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Message = OpenAI.Threads.Message;

namespace OpenAI.Tests
{
Expand Down Expand Up @@ -76,10 +75,8 @@ public async Task Test_03_ListThreadRuns()
var thread = await OpenAIClient.ThreadsEndpoint.CreateThreadAsync(TestThreadRequest);
var request = new CreateThreadRunRequest(assistant);
var run = await OpenAIClient.ThreadsEndpoint.CreateThreadRunAsync(thread.Id, request);

Assert.IsNotNull(run);
var list = await OpenAIClient.ThreadsEndpoint.ListThreadRunsAsync(run.ThreadId);

Assert.IsNotNull(list);
Assert.IsNotEmpty(list.Items);

Expand All @@ -96,10 +93,12 @@ public async Task Test_03_ListThreadRuns()
public async Task Test_04_ModifyThreadRun()
{
var assistant = await OpenAIClient.AssistantsEndpoint.CreateAssistantAsync(TestAssistantRequest);
Assert.IsNotNull(assistant);
var thread = await OpenAIClient.ThreadsEndpoint.CreateThreadAsync(TestThreadRequest);

Assert.IsNotNull(thread);
var request = new CreateThreadRunRequest(assistant);
var run = await OpenAIClient.ThreadsEndpoint.CreateThreadRunAsync(thread.Id, request);
Assert.IsNotNull(run);

// run in Queued and InProgress can't be modified
run = await WaitRunPassThroughStatusAsync(thread.Id, run.Id, RunStatus.Queued, RunStatus.InProgress);
Expand All @@ -126,9 +125,9 @@ public async Task Test_05_CancelRun()
var thread = await OpenAIClient.ThreadsEndpoint.CreateThreadAsync(TestThreadRequest);
var request = new CreateThreadRunRequest(assistant);
var run = await OpenAIClient.ThreadsEndpoint.CreateThreadRunAsync(thread.Id, request);

Assert.IsNotNull(run);
run = await OpenAIClient.ThreadsEndpoint.CancelThreadRunAsync(thread.Id, run.Id);

Assert.IsNotNull(run);
// waiting while run in Queued and InProgress
run = await WaitRunPassThroughStatusAsync(thread.Id, run.Id, RunStatus.Cancelling);

Expand Down Expand Up @@ -182,13 +181,13 @@ public async Task Test_06_SubmitToolOutput()
Assert.AreEqual(1, run.RequiredAction.SubmitToolOutputs.ToolCalls.Count);
var toolCall = run.RequiredAction.SubmitToolOutputs.ToolCalls[0];
Assert.AreEqual("function", toolCall.Type);
Assert.IsNotNull(toolCall.Function);
Assert.AreEqual(nameof(WeatherService.GetCurrentWeather), toolCall.Function.Name);
Assert.IsNotNull(toolCall.Function.Arguments);
Assert.IsNotNull(toolCall.FunctionCall);
Assert.AreEqual(nameof(WeatherService.GetCurrentWeather), toolCall.FunctionCall.Name);
Assert.IsNotNull(toolCall.FunctionCall.Arguments);

var functionArgs = JsonSerializer.Deserialize<WeatherArgs>(toolCall.Function.Arguments);
var functionArgs = JsonSerializer.Deserialize<WeatherArgs>(toolCall.FunctionCall.Arguments);
var functionResult = WeatherService.GetCurrentWeather(functionArgs);
var submitRequest = new SubmitThreadRunToolOutputsRequest(new List<ToolOutput>
var submitRequest = new SubmitToolOutputsRequest(new List<ToolOutput>
{
new ToolOutput(toolCall.Id, functionResult)
});
Expand Down
12 changes: 6 additions & 6 deletions OpenAI-DotNet/Assistants/AssistantsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public async Task<bool> DeleteAssistantAsync(string assistantId, CancellationTok
/// <summary>
/// Get list of assistants.
/// </summary>
/// <param name="request"><see cref="ListRequest"/>.</param>
/// <param name="query"><see cref="ListQuery"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns><see cref="ListResponse{Assistant}"/></returns>
public async Task<ListResponse<Assistant>> ListAssistantsAsync(ListRequest request = null, CancellationToken cancellationToken = default)
public async Task<ListResponse<Assistant>> ListAssistantsAsync(ListQuery query = null, CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl(queryParameters: request), cancellationToken).ConfigureAwait(false);
var response = await Api.Client.GetAsync(GetUrl(queryParameters: query), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return response.Deserialize<ListResponse<Assistant>>(responseAsString, OpenAIClient.JsonSerializationOptions);
}
Expand Down Expand Up @@ -135,12 +135,12 @@ public async Task<bool> DeleteAssistantFileAsync(string assistantId, string file
/// Returns a list of assistant files.
/// </summary>
/// <param name="assistantId">The ID of the assistant the file belongs to.</param>
/// <param name="request"><see cref="ListRequest"/>.</param>
/// <param name="query"><see cref="ListQuery"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns><see cref="ListResponse{AssistantFile}"/>.</returns>
public async Task<ListResponse<AssistantFile>> ListAssistantFilesAsync(string assistantId, ListRequest request = null, CancellationToken cancellationToken = default)
public async Task<ListResponse<AssistantFile>> ListAssistantFilesAsync(string assistantId, ListQuery query = null, CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files", request), cancellationToken).ConfigureAwait(false);
var response = await Api.Client.GetAsync(GetUrl($"/{assistantId}/files", query), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return response.Deserialize<ListResponse<AssistantFile>>(responseAsString, OpenAIClient.JsonSerializationOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Edits/EditsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OpenAI.Edits
/// Given a prompt and an instruction, the model will return an edited version of the prompt.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/edits"/>
/// </summary>
[Obsolete]
[Obsolete("Deprecated")]
public sealed class EditsEndpoint : BaseEndPoint
{
/// <inheritdoc />
Expand Down
15 changes: 8 additions & 7 deletions OpenAI-DotNet/FineTuning/FineTuningEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace OpenAI.FineTuning
{
/// <summary>
/// Manage fine-tuning jobs to tailor a model to your specific training data.<br/>
/// <see href="https://platform.openai.com/docs/guides/fine-tuning"/>
/// <see href="https://platform.openai.com/docs/guides/fine-tuning"/><br/>
/// <see href="https://platform.openai.com/docs/api-reference/fine-tuning"/>
/// </summary>
public sealed class FineTuningEndpoint : BaseEndPoint
{
Expand Down Expand Up @@ -58,12 +59,12 @@ public async Task<FineTuneJobList> ListJobsAsync(int? limit, string after, Cance
/// <summary>
/// List your organization's fine-tuning jobs.
/// </summary>
/// <param name="request"><see cref="ListRequest"/>.</param>
/// <param name="query"><see cref="ListQuery"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>List of <see cref="FineTuneJob"/>s.</returns>
public async Task<ListResponse<FineTuneJob>> ListJobsAsync(ListRequest request = null, CancellationToken cancellationToken = default)
public async Task<ListResponse<FineTuneJob>> ListJobsAsync(ListQuery query = null, CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl("/jobs", request), cancellationToken).ConfigureAwait(false);
var response = await Api.Client.GetAsync(GetUrl("/jobs", query), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return response.Deserialize<ListResponse<FineTuneJob>>(responseAsString, OpenAIClient.JsonSerializationOptions);
}
Expand Down Expand Up @@ -121,12 +122,12 @@ public async Task<EventList> ListJobEventsAsync(string jobId, int? limit, string
/// Get fine-grained status updates for a fine-tune job.
/// </summary>
/// <param name="jobId"><see cref="FineTuneJob.Id"/>.</param>
/// <param name="request"><see cref="ListRequest"/>.</param>
/// <param name="query"><see cref="ListQuery"/>.</param>
/// <param name="cancellationToken">Optional, <see cref="CancellationToken"/>.</param>
/// <returns>List of events for <see cref="FineTuneJob"/>.</returns>
public async Task<ListResponse<Event>> ListJobEventsAsync(string jobId, ListRequest request = null, CancellationToken cancellationToken = default)
public async Task<ListResponse<Event>> ListJobEventsAsync(string jobId, ListQuery query = null, CancellationToken cancellationToken = default)
{
var response = await Api.Client.GetAsync(GetUrl($"/jobs/{jobId}/events", request), cancellationToken).ConfigureAwait(false);
var response = await Api.Client.GetAsync(GetUrl($"/jobs/{jobId}/events", query), cancellationToken).ConfigureAwait(false);
var responseAsString = await response.ReadAsStringAsync(EnableDebug, cancellationToken).ConfigureAwait(false);
return response.Deserialize<ListResponse<Event>>(responseAsString, OpenAIClient.JsonSerializationOptions);
}
Expand Down
2 changes: 2 additions & 0 deletions OpenAI-DotNet/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace OpenAI
/// </summary>
public class Function
{
public Function() { }

internal Function(Function other) => CopyFrom(other);

/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions OpenAI-DotNet/ListRequest.cs → OpenAI-DotNet/ListQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace OpenAI
{
public sealed class ListRequest
public sealed class ListQuery
{
/// <summary>
/// List Request.
/// List Query.
/// </summary>
/// <param name="limit">
/// A limit on the number of objects to be returned.
Expand All @@ -25,7 +25,7 @@ public sealed class ListRequest
/// For instance, if you make a list request and receive 100 objects, ending with obj_foo,
/// your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
/// </param>
public ListRequest(int? limit = null, SortOrder order = SortOrder.Descending, string after = null, string before = null)
public ListQuery(int? limit = null, SortOrder order = SortOrder.Descending, string after = null, string before = null)
{
Limit = limit;
Order = order;
Expand All @@ -41,17 +41,17 @@ public ListRequest(int? limit = null, SortOrder order = SortOrder.Descending, st

public string Before { get; set; }

public static implicit operator Dictionary<string, string>(ListRequest request)
public static implicit operator Dictionary<string, string>(ListQuery query)
{
if (request == null) { return null; }
if (query == null) { return null; }
var parameters = new Dictionary<string, string>();

if (request.Limit.HasValue)
if (query.Limit.HasValue)
{
parameters.Add("limit", request.Limit.ToString());
parameters.Add("limit", query.Limit.ToString());
}

switch (request.Order)
switch (query.Order)
{
case SortOrder.Descending:
parameters.Add("order", "desc");
Expand All @@ -61,14 +61,14 @@ public static implicit operator Dictionary<string, string>(ListRequest request)
break;
}

if (!string.IsNullOrEmpty(request.After))
if (!string.IsNullOrEmpty(query.After))
{
parameters.Add("after", request.After);
parameters.Add("after", query.After);
}

if (!string.IsNullOrEmpty(request.Before))
if (!string.IsNullOrEmpty(query.Before))
{
parameters.Add("before", request.Before);
parameters.Add("before", query.Before);
}

return parameters;
Expand Down
21 changes: 11 additions & 10 deletions OpenAI-DotNet/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public OpenAIClient(OpenAIAuthentication openAIAuthentication = null, OpenAIClie
ModelsEndpoint = new ModelsEndpoint(this);
CompletionsEndpoint = new CompletionsEndpoint(this);
ChatEndpoint = new ChatEndpoint(this);
#pragma warning disable CS0612 // Type or member is obsolete
#pragma warning disable CS0618 // Type or member is obsolete
EditsEndpoint = new EditsEndpoint(this);
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
ImagesEndPoint = new ImagesEndpoint(this);
EmbeddingsEndpoint = new EmbeddingsEndpoint(this);
AudioEndpoint = new AudioEndpoint(this);
Expand Down Expand Up @@ -158,7 +158,7 @@ private HttpClient SetupClient(HttpClient client = null)
/// Given a prompt and an instruction, the model will return an edited version of the prompt.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/edits"/>
/// </summary>
[Obsolete]
[Obsolete("Deprecated")]
public EditsEndpoint EditsEndpoint { get; }

/// <summary>
Expand Down Expand Up @@ -187,7 +187,8 @@ private HttpClient SetupClient(HttpClient client = null)

/// <summary>
/// Manage fine-tuning jobs to tailor a model to your specific training data.<br/>
/// <see href="https://platform.openai.com/docs/guides/fine-tuning"/>
/// <see href="https://platform.openai.com/docs/guides/fine-tuning"/><br/>
/// <see href="https://platform.openai.com/docs/api-reference/fine-tuning"/>
/// </summary>
public FineTuningEndpoint FineTuningEndpoint { get; }

Expand All @@ -198,16 +199,16 @@ private HttpClient SetupClient(HttpClient client = null)
/// </summary>
public ModerationsEndpoint ModerationsEndpoint { get; }

/// <summary>
/// Create threads that assistants can interact with.
/// <see href="https://platform.openai.com/docs/api-reference/threads"/>
/// </summary>
public ThreadsEndpoint ThreadsEndpoint { get; }

/// <summary>
/// Build assistants that can call models and use tools to perform tasks.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/assistants"/>
/// </summary>
public AssistantsEndpoint AssistantsEndpoint { get; }

/// <summary>
/// Create threads that assistants can interact with.<br/>
/// <see href="https://platform.openai.com/docs/api-reference/threads"/>
/// </summary>
public ThreadsEndpoint ThreadsEndpoint { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OpenAI.Threads
{
public sealed class ToolCallFunction
public sealed class FunctionCall
{
/// <summary>
/// The name of the function.
Expand Down
7 changes: 2 additions & 5 deletions OpenAI-DotNet/Threads/RunStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public sealed class RunStep : BaseResponse
[JsonPropertyName("id")]
public string Id { get; private set; }

/// <summary>
/// The object type, which is always `thread.run.step`.
/// </summary>
[JsonInclude]
[JsonPropertyName("object")]
public string Object { get; private set; }
Expand Down Expand Up @@ -60,15 +57,15 @@ public sealed class RunStep : BaseResponse
public string RunId { get; private set; }

/// <summary>
/// The type of run step, which can be either message_creation or tool_calls.
/// The type of run step.
/// </summary>
[JsonInclude]
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter<RunStepType>))]
public RunStepType Type { get; private set; }

/// <summary>
/// The status of the run step, which can be either in_progress, cancelled, failed, completed, or expired.
/// The status of the run step.
/// </summary>
[JsonInclude]
[JsonPropertyName("status")]
Expand Down
28 changes: 0 additions & 28 deletions OpenAI-DotNet/Threads/RunStepToolCall.cs

This file was deleted.

2 changes: 1 addition & 1 deletion OpenAI-DotNet/Threads/RunStepToolCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public sealed class RunStepToolCalls
/// </summary>
[JsonInclude]
[JsonPropertyName("tool_calls")]
public IReadOnlyList<Tool> ToolCalls { get; private set; }
public IReadOnlyList<ToolCall> ToolCalls { get; private set; }
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;

namespace OpenAI.Threads
{
/// <summary>
/// Request to submit tool outputs to run
/// </summary>
public sealed class SubmitThreadRunToolOutputsRequest
public sealed class SubmitToolOutputsRequest
{
public SubmitThreadRunToolOutputsRequest(IReadOnlyList<ToolOutput> toolOutputs)
public SubmitToolOutputsRequest(IEnumerable<ToolOutput> toolOutputs)
{
ToolOutputs = toolOutputs;
ToolOutputs = toolOutputs?.ToList();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet/Threads/ThreadMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public sealed class ThreadMessage : BaseResponse

/// <summary>
/// A list of file IDs that the assistant should use.
/// Useful for tools like retrieval and code_interpreter that can access files.
/// Useful for tools like 'retrieval' and 'code_interpreter' that can access files.
/// A maximum of 10 files can be attached to a message.
/// </summary>
[JsonInclude]
Expand Down
Loading

0 comments on commit 0d9716b

Please sign in to comment.