openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Chat/ChatClient.Protocol.cs
95lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Collections.Generic; |
| 5 | using System.ComponentModel; |
| 6 | using System.Diagnostics.CodeAnalysis; |
| 7 | using System.Threading.Tasks; |
| 8 | |
| 9 | namespace OpenAI.Chat; |
| 10 | |
| 11 | /// <summary> The service client for the OpenAI Chat Completions endpoint. </summary> |
| 12 | [CodeGenSuppress("CreateChatCompletionAsync", typeof(BinaryContent), typeof(RequestOptions))] |
| 13 | [CodeGenSuppress("CreateChatCompletion", typeof(BinaryContent), typeof(RequestOptions))] |
| 14 | [CodeGenSuppress("GetChatCompletionMessagesAsync", typeof(string), typeof(string), typeof(int?), typeof(string), typeof(RequestOptions))] |
| 15 | [CodeGenSuppress("GetChatCompletionMessages", typeof(string), typeof(string), typeof(int?), typeof(string), typeof(RequestOptions))] |
| 16 | [CodeGenSuppress("GetChatCompletionsAsync", typeof(string), typeof(int?), typeof(string), typeof(IDictionary<string, string>), typeof(string), typeof(RequestOptions))] |
| 17 | [CodeGenSuppress("GetChatCompletions", typeof(string), typeof(int?), typeof(string), typeof(IDictionary<string, string>), typeof(string), typeof(RequestOptions))] |
| 18 | [CodeGenSuppress("UpdateChatCompletionAsync", typeof(string), typeof(BinaryContent), typeof(RequestOptions))] |
| 19 | [CodeGenSuppress("UpdateChatCompletion", typeof(string), typeof(BinaryContent), typeof(RequestOptions))] |
| 20 | public partial class ChatClient |
| 21 | { |
| 22 | /// <summary> |
| 23 | /// [Protocol Method] Creates a model response for the given chat conversation. |
| 24 | /// </summary> |
| 25 | /// <param name="content"> The content to send as the body of the request. </param> |
| 26 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 27 | /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception> |
| 28 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 29 | /// <returns> The response returned from the service. </returns> |
| 30 | [EditorBrowsable(EditorBrowsableState.Never)] |
| 31 | public virtual async Task<ClientResult> CompleteChatAsync(BinaryContent content, RequestOptions options = null) |
| 32 | { |
| 33 | Argument.AssertNotNull(content, nameof(content)); |
| 34 | |
| 35 | using PipelineMessage message = CreateCreateChatCompletionRequest(content, options); |
| 36 | return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 37 | } |
| 38 | |
| 39 | /// <summary> |
| 40 | /// [Protocol Method] Creates a model response for the given chat conversation. |
| 41 | /// </summary> |
| 42 | /// <param name="content"> The content to send as the body of the request. </param> |
| 43 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 44 | /// <exception cref="ArgumentNullException"> <paramref name="content"/> is null. </exception> |
| 45 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 46 | /// <returns> The response returned from the service. </returns> |
| 47 | [EditorBrowsable(EditorBrowsableState.Never)] |
| 48 | public virtual ClientResult CompleteChat(BinaryContent content, RequestOptions options = null) |
| 49 | { |
| 50 | Argument.AssertNotNull(content, nameof(content)); |
| 51 | |
| 52 | using PipelineMessage message = CreateCreateChatCompletionRequest(content, options); |
| 53 | return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); |
| 54 | } |
| 55 | |
| 56 | // CUSTOM: Added Experimental attribute. |
| 57 | [Experimental("OPENAI001")] |
| 58 | public virtual ClientResult GetChatCompletion(string completionId, RequestOptions options) |
| 59 | { |
| 60 | Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); |
| 61 | |
| 62 | using PipelineMessage message = CreateGetChatCompletionRequest(completionId, options); |
| 63 | return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); |
| 64 | } |
| 65 | |
| 66 | // CUSTOM: Added Experimental attribute. |
| 67 | [Experimental("OPENAI001")] |
| 68 | public virtual async Task<ClientResult> GetChatCompletionAsync(string completionId, RequestOptions options) |
| 69 | { |
| 70 | Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); |
| 71 | |
| 72 | using PipelineMessage message = CreateGetChatCompletionRequest(completionId, options); |
| 73 | return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 74 | } |
| 75 | |
| 76 | // CUSTOM: Added Experimental attribute. |
| 77 | [Experimental("OPENAI001")] |
| 78 | public virtual ClientResult DeleteChatCompletion(string completionId, RequestOptions options) |
| 79 | { |
| 80 | Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); |
| 81 | |
| 82 | using PipelineMessage message = CreateDeleteChatCompletionRequest(completionId, options); |
| 83 | return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options)); |
| 84 | } |
| 85 | |
| 86 | // CUSTOM: Added Experimental attribute. |
| 87 | [Experimental("OPENAI001")] |
| 88 | public virtual async Task<ClientResult> DeleteChatCompletionAsync(string completionId, RequestOptions options) |
| 89 | { |
| 90 | Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); |
| 91 | |
| 92 | using PipelineMessage message = CreateDeleteChatCompletionRequest(completionId, options); |
| 93 | return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 94 | } |
| 95 | } |
| 96 | |