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

Feature/assistant api part 2 #546

Merged
merged 4 commits into from
May 1, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenAI.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
// Tools
//await ChatCompletionTestHelper.RunChatFunctionCallTest(sdk);
//await ChatCompletionTestHelper.RunChatFunctionCallTestAsStream(sdk);
await BatchTestHelper.RunBatchOperationsTest(sdk);
//await BatchTestHelper.RunBatchOperationsTest(sdk);

// Whisper
//await AudioTestHelper.RunSimpleAudioCreateTranscriptionTest(sdk);
Expand Down
109 changes: 92 additions & 17 deletions OpenAI.SDK/EndpointProviders/AzureOpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,6 @@ public string MessageList(string threadId, MessageListRequest? messageListReques
return url;
}

public string MessageFileRetrieve(string threadId, string messageId, string fileId)
{
return $"{Prefix}/threads/{threadId}/messages/{messageId}/files/{fileId}{AzureVersionQueryString}";
}

public string MessageFileList(string threadId, string messageId, MessageFileListRequest? messageFileListRequest)
{
var url = $"{Prefix}/threads/{threadId}/messages/{messageId}/files{AzureVersionQueryString}";

var query = messageFileListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}{query}";
}

return url;
}

public string RunCreate(string threadId)
{
Expand Down Expand Up @@ -371,6 +354,96 @@ public string RunStepList(string threadId, string runId, RunStepListRequest? run
return url;
}


public string VectorStoreCreate()
{
return $"{Prefix}/vector_stores{AzureVersionQueryString}";
}

public string VectorStoreList(BaseListRequest baseListRequest)
{
var url = $"{Prefix}/vector_stores{AzureVersionQueryString}";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string VectorStoreRetrieve(string vectorStoreId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}{AzureVersionQueryString}";
}

public string VectorStoreModify(string vectorStoreId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}{AzureVersionQueryString}";
}

public string VectorStoreDelete(string vectorStoreId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}{AzureVersionQueryString}";
}

public string VectorStoreFileCreate(string vectorStoreId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files{AzureVersionQueryString}";
}

public string VectorStoreFileRetrieve(string vectorStoreId, string fileId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files/{fileId}{AzureVersionQueryString}";
}

public string VectorStoreFileDelete(string vectorStoreId, string fileId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files/{fileId}{AzureVersionQueryString}";
}

public string VectorStoreFileList(string vectorStoreId, BaseListRequest? baseListRequest)
{
var url = $"{Prefix}/vector_stores/{vectorStoreId}/files{AzureVersionQueryString}";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string VectorStoreFileBatchCreate(string vectorStoreId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files/batches{AzureVersionQueryString}";
}

public string VectorStoreFileBatchRetrieve(string vectorStoreId, string batchId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files/batches/{batchId}{AzureVersionQueryString}";
}

public string VectorStoreFileBatchCancel(string vectorStoreId, string batchId)
{
return $"{Prefix}/vector_stores/{vectorStoreId}/files/batches/{batchId}/cancel{AzureVersionQueryString}";
}

public string VectorStoreFileBatchList(string vectorStoreId, string batchId, BaseListRequest? baseListRequest)
{
var url = $"{Prefix}/vector_stores/{vectorStoreId}/files/batches{AzureVersionQueryString}";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string FineTuningJobList()
{
return $"{Prefix}/fine_tuning/jobs{AzureVersionQueryString}";
Expand All @@ -395,4 +468,6 @@ private string Files()
{
return $"{Prefix}/files{AzureVersionQueryString}";
}


}
16 changes: 14 additions & 2 deletions OpenAI.SDK/EndpointProviders/IOpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ internal interface IOpenAiEndpointProvider
string MessageRetrieve(string threadId,string messageId);
string MessageModify(string threadId, string messageId);
string MessageList(string threadId, MessageListRequest? messageListRequest);
string MessageFileRetrieve(string threadId, string messageId, string fileId);
string MessageFileList(string threadId, string messageId, MessageFileListRequest? messageFileListRequest);
string RunCreate(string threadId);
string RunRetrieve(string threadId, string runId);
string RunModify(string threadId, string runId);
Expand All @@ -66,4 +64,18 @@ internal interface IOpenAiEndpointProvider
string ThreadAndRunCreate();
string RunStepRetrieve(string threadId, string runId,string stepId);
string RunStepList(string threadId, string runId, RunStepListRequest? runStepListRequest);
string VectorStoreCreate();
string VectorStoreList(BaseListRequest baseListRequest);
string VectorStoreRetrieve(string vectorStoreId);
string VectorStoreModify(string vectorStoreId);
string VectorStoreDelete(string vectorStoreId);
string VectorStoreFileCreate(string vectorStoreId);
string VectorStoreFileRetrieve(string vectorStoreId, string fileId);
string VectorStoreFileDelete(string vectorStoreId, string fileId);
string VectorStoreFileList(string vectorStoreId, BaseListRequest? baseListRequest);
string VectorStoreFileBatchCreate(string vectorStoreId);
string VectorStoreFileBatchRetrieve(string vectorStoreId, string batchId);
string VectorStoreFileBatchCancel(string vectorStoreId, string batchId);
string VectorStoreFileBatchList(string vectorStoreId, string batchId, BaseListRequest? baseListRequest);

}
109 changes: 90 additions & 19 deletions OpenAI.SDK/EndpointProviders/OpenAiEndpointProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Threading;
using OpenAI.ObjectModels.RequestModels;

namespace OpenAI.EndpointProviders;
Expand Down Expand Up @@ -298,25 +299,6 @@ public string MessageList(string threadId, MessageListRequest? messageListReques

return url;
}

public string MessageFileRetrieve(string threadId, string messageId, string fileId)
{
return $"{_apiVersion}/threads/{threadId}/messages/{messageId}/files/{fileId}";
}

public string MessageFileList(string threadId, string messageId, MessageFileListRequest? messageFileListRequest)
{
var url = $"{_apiVersion}/threads/{threadId}/messages/{messageId}/files";

var query = messageFileListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string RunCreate(string threadId)
{
return $"{_apiVersion}/threads/{threadId}/runs";
Expand Down Expand Up @@ -377,4 +359,93 @@ public string RunStepList(string threadId, string runId, RunStepListRequest? run

return url;
}

public string VectorStoreCreate()
{
return $"{_apiVersion}/vector_stores";
}

public string VectorStoreList(BaseListRequest baseListRequest)
{
var url = $"{_apiVersion}/vector_stores";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string VectorStoreRetrieve(string vectorStoreId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}";
}

public string VectorStoreModify(string vectorStoreId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}";
}

public string VectorStoreDelete(string vectorStoreId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}";
}

public string VectorStoreFileCreate(string vectorStoreId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files";
}

public string VectorStoreFileRetrieve(string vectorStoreId, string fileId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files/{fileId}";
}

public string VectorStoreFileDelete(string vectorStoreId, string fileId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files/{fileId}";
}

public string VectorStoreFileList(string vectorStoreId, BaseListRequest? baseListRequest)
{
var url = $"{_apiVersion}/vector_stores/{vectorStoreId}/files";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}

public string VectorStoreFileBatchCreate(string vectorStoreId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files/batches";
}

public string VectorStoreFileBatchRetrieve(string vectorStoreId, string batchId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files/batches/{batchId}";
}

public string VectorStoreFileBatchCancel(string vectorStoreId, string batchId)
{
return $"{_apiVersion}/vector_stores/{vectorStoreId}/files/batches/{batchId}/cancel";
}

public string VectorStoreFileBatchList(string vectorStoreId, string batchId,BaseListRequest? baseListRequest)
{
var url = $"{_apiVersion}/vector_stores/{vectorStoreId}/files/batches";

var query = baseListRequest?.GetQueryParameters();
if (!string.IsNullOrWhiteSpace(query))
{
url = $"{url}?{query}";
}

return url;
}
}
9 changes: 9 additions & 0 deletions OpenAI.SDK/Interfaces/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ public interface IMessageService
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<MessageListResponse> MessageList(string threadId, MessageListRequest? request = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve a message.
/// </summary>
Task<MessageResponse> GetMessage(string threadId, string messageId, CancellationToken cancellationToken = default);
/// <summary>
/// Modifies a message.
/// </summary>
Task<MessageResponse> ModifyMessage(string threadId, string messageId, ModifyMessageRequest requestBody, CancellationToken cancellationToken = default);
}
20 changes: 20 additions & 0 deletions OpenAI.SDK/Interfaces/IRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ public interface IRunService
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<RunResponse> RunSubmitToolOutputs(string threadId, string runId, SubmitToolOutputsToRunRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Modifies a run.
/// </summary>
/// <param name="threadId">The ID of the [thread](/docs/api-reference/threads) that was run.</param>
/// <param name="runId">The ID of the run to modify.</param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<RunResponse> RunModify(string threadId, string runId, RunModifyRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Create a thread and run it in one request.
/// </summary>
Task<RunResponse> CreateThreadAndRun(CreateThreadAndRunRequest requestBody, CancellationToken cancellationToken = default);

/// <summary>
/// Returns a list of runs belonging to a thread.
/// </summary>
Task<RunListResponse> ListRuns(string threadId, RunListRequest runListRequest, CancellationToken cancellationToken = default);
}
27 changes: 27 additions & 0 deletions OpenAI.SDK/Interfaces/IRunStepService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using OpenAI.ObjectModels.RequestModels;
using OpenAI.ObjectModels.ResponseModels;

namespace OpenAI.Interfaces;

public interface IRunStepService
{
/// <summary>
/// Returns a list of run steps belonging to a run.
/// </summary>
/// <param name="threadId">The ID of the thread the run and run steps belong to.</param>
/// <param name="runId">The ID of the run steps belong to.</param>
/// <param name="request">Paging</param>
/// <param name="cancellationToken"></param>
/// <returns>A list of [run step](/docs/api-reference/runs/step-object) objects.</returns>
Task<RunStepListResponse> RunStepsList(string threadId, string runId, RunStepListRequest request, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves a run step.
/// </summary>
/// <param name="threadId">The ID of the thread to which the run and run step belongs.</param>
/// <param name="runId">The ID of the run to which the run step belongs.</param>
/// <param name="stepId">The ID of the run step to retrieve.</param>
/// <param name="cancellationToken"></param>
/// <returns>The [run step](/docs/api-reference/runs/step-object) object matching the specified ID.</returns>
Task<RunStepResponse> RunStepRetrieve(string threadId, string runId, string stepId, CancellationToken cancellationToken = default);
}
5 changes: 5 additions & 0 deletions OpenAI.SDK/Interfaces/IThreadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public interface IThreadService
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<DeletionStatusResponse> ThreadDelete(string threadId, CancellationToken cancellationToken = default);

/// <summary>
/// Modifies a thread.
/// </summary>
Task<ThreadResponse> ModifyThread(string threadId, ModifyThreadRequest requestBody, CancellationToken cancellationToken = default);
}
Loading
Loading