openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Assistants/Internal/InternalAssistantMessageClient.Protocol.cs
235lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel; |
| 3 | using System.ClientModel.Primitives; |
| 4 | using System.Threading.Tasks; |
| 5 | |
| 6 | namespace OpenAI.Assistants; |
| 7 | |
| 8 | internal partial class InternalAssistantMessageClient |
| 9 | { |
| 10 | /// <summary> |
| 11 | /// [Protocol Method] Create a message. |
| 12 | /// </summary> |
| 13 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to create a message for. </param> |
| 14 | /// <param name="content"> The content to send as the body of the request. </param> |
| 15 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 16 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception> |
| 17 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 18 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 19 | /// <returns> The response returned from the service. </returns> |
| 20 | public virtual async Task<ClientResult> CreateMessageAsync(string threadId, BinaryContent content, RequestOptions options = null) |
| 21 | { |
| 22 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 23 | Argument.AssertNotNull(content, nameof(content)); |
| 24 | |
| 25 | using PipelineMessage message = CreateCreateMessageRequest(threadId, content, options); |
| 26 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 27 | } |
| 28 | |
| 29 | /// <summary> |
| 30 | /// [Protocol Method] Create a message. |
| 31 | /// </summary> |
| 32 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to create a message for. </param> |
| 33 | /// <param name="content"> The content to send as the body of the request. </param> |
| 34 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 35 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="content"/> is null. </exception> |
| 36 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 37 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 38 | /// <returns> The response returned from the service. </returns> |
| 39 | public virtual ClientResult CreateMessage(string threadId, BinaryContent content, RequestOptions options = null) |
| 40 | { |
| 41 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 42 | Argument.AssertNotNull(content, nameof(content)); |
| 43 | |
| 44 | using PipelineMessage message = CreateCreateMessageRequest(threadId, content, options); |
| 45 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 46 | } |
| 47 | |
| 48 | /// <summary> |
| 49 | /// [Protocol Method] Returns a list of messages for a given thread. |
| 50 | /// </summary> |
| 51 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) the messages belong to. </param> |
| 52 | /// <param name="limit"> |
| 53 | /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the |
| 54 | /// default is 20. |
| 55 | /// </param> |
| 56 | /// <param name="order"> |
| 57 | /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` |
| 58 | /// for descending order. Allowed values: "asc" | "desc" |
| 59 | /// </param> |
| 60 | /// <param name="after"> |
| 61 | /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. |
| 62 | /// For instance, if you make a list request and receive 100 objects, ending with obj_foo, your |
| 63 | /// subsequent call can include after=obj_foo in order to fetch the next page of the list. |
| 64 | /// </param> |
| 65 | /// <param name="before"> |
| 66 | /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. |
| 67 | /// For instance, if you make a list request and receive 100 objects, ending with obj_foo, your |
| 68 | /// subsequent call can include before=obj_foo in order to fetch the previous page of the list. |
| 69 | /// </param> |
| 70 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 71 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception> |
| 72 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 73 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 74 | /// <returns> The response returned from the service. </returns> |
| 75 | public virtual async Task<ClientResult> GetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options) |
| 76 | { |
| 77 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 78 | |
| 79 | using PipelineMessage message = CreateGetMessagesRequest(threadId, limit, order, after, before, options); |
| 80 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 81 | } |
| 82 | |
| 83 | /// <summary> |
| 84 | /// [Protocol Method] Returns a list of messages for a given thread. |
| 85 | /// </summary> |
| 86 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) the messages belong to. </param> |
| 87 | /// <param name="limit"> |
| 88 | /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the |
| 89 | /// default is 20. |
| 90 | /// </param> |
| 91 | /// <param name="order"> |
| 92 | /// Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc` |
| 93 | /// for descending order. Allowed values: "asc" | "desc" |
| 94 | /// </param> |
| 95 | /// <param name="after"> |
| 96 | /// A cursor for use in pagination. `after` is an object ID that defines your place in the list. |
| 97 | /// For instance, if you make a list request and receive 100 objects, ending with obj_foo, your |
| 98 | /// subsequent call can include after=obj_foo in order to fetch the next page of the list. |
| 99 | /// </param> |
| 100 | /// <param name="before"> |
| 101 | /// A cursor for use in pagination. `before` is an object ID that defines your place in the list. |
| 102 | /// For instance, if you make a list request and receive 100 objects, ending with obj_foo, your |
| 103 | /// subsequent call can include before=obj_foo in order to fetch the previous page of the list. |
| 104 | /// </param> |
| 105 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 106 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> is null. </exception> |
| 107 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> is an empty string, and was expected to be non-empty. </exception> |
| 108 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 109 | /// <returns> The response returned from the service. </returns> |
| 110 | public virtual ClientResult GetMessages(string threadId, int? limit, string order, string after, string before, RequestOptions options) |
| 111 | { |
| 112 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 113 | |
| 114 | using PipelineMessage message = CreateGetMessagesRequest(threadId, limit, order, after, before, options); |
| 115 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 116 | } |
| 117 | |
| 118 | /// <summary> |
| 119 | /// [Protocol Method] Retrieve a message. |
| 120 | /// </summary> |
| 121 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this message belongs. </param> |
| 122 | /// <param name="messageId"> The ID of the message to retrieve. </param> |
| 123 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 124 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception> |
| 125 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 126 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 127 | /// <returns> The response returned from the service. </returns> |
| 128 | public virtual async Task<ClientResult> GetMessageAsync(string threadId, string messageId, RequestOptions options) |
| 129 | { |
| 130 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 131 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 132 | |
| 133 | using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options); |
| 134 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 135 | } |
| 136 | |
| 137 | /// <summary> |
| 138 | /// [Protocol Method] Retrieve a message. |
| 139 | /// </summary> |
| 140 | /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this message belongs. </param> |
| 141 | /// <param name="messageId"> The ID of the message to retrieve. </param> |
| 142 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 143 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception> |
| 144 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 145 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 146 | /// <returns> The response returned from the service. </returns> |
| 147 | public virtual ClientResult GetMessage(string threadId, string messageId, RequestOptions options) |
| 148 | { |
| 149 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 150 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 151 | |
| 152 | using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options); |
| 153 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 154 | } |
| 155 | |
| 156 | /// <summary> |
| 157 | /// [Protocol Method] Modifies a message. |
| 158 | /// </summary> |
| 159 | /// <param name="threadId"> The ID of the thread to which this message belongs. </param> |
| 160 | /// <param name="messageId"> The ID of the message to modify. </param> |
| 161 | /// <param name="content"> The content to send as the body of the request. </param> |
| 162 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 163 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="messageId"/> or <paramref name="content"/> is null. </exception> |
| 164 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 165 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 166 | /// <returns> The response returned from the service. </returns> |
| 167 | public virtual async Task<ClientResult> ModifyMessageAsync(string threadId, string messageId, BinaryContent content, RequestOptions options = null) |
| 168 | { |
| 169 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 170 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 171 | Argument.AssertNotNull(content, nameof(content)); |
| 172 | |
| 173 | using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options); |
| 174 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 175 | } |
| 176 | |
| 177 | /// <summary> |
| 178 | /// [Protocol Method] Modifies a message. |
| 179 | /// </summary> |
| 180 | /// <param name="threadId"> The ID of the thread to which this message belongs. </param> |
| 181 | /// <param name="messageId"> The ID of the message to modify. </param> |
| 182 | /// <param name="content"> The content to send as the body of the request. </param> |
| 183 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 184 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="messageId"/> or <paramref name="content"/> is null. </exception> |
| 185 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 186 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 187 | /// <returns> The response returned from the service. </returns> |
| 188 | public virtual ClientResult ModifyMessage(string threadId, string messageId, BinaryContent content, RequestOptions options = null) |
| 189 | { |
| 190 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 191 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 192 | Argument.AssertNotNull(content, nameof(content)); |
| 193 | |
| 194 | using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options); |
| 195 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 196 | } |
| 197 | |
| 198 | /// <summary> |
| 199 | /// [Protocol Method] Deletes a message. |
| 200 | /// </summary> |
| 201 | /// <param name="threadId"> The ID of the thread to which this message belongs. </param> |
| 202 | /// <param name="messageId"> The ID of the message to delete. </param> |
| 203 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 204 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception> |
| 205 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 206 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 207 | /// <returns> The response returned from the service. </returns> |
| 208 | public virtual async Task<ClientResult> DeleteMessageAsync(string threadId, string messageId, RequestOptions options) |
| 209 | { |
| 210 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 211 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 212 | |
| 213 | using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options); |
| 214 | return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); |
| 215 | } |
| 216 | |
| 217 | /// <summary> |
| 218 | /// [Protocol Method] Deletes a message. |
| 219 | /// </summary> |
| 220 | /// <param name="threadId"> The ID of the thread to which this message belongs. </param> |
| 221 | /// <param name="messageId"> The ID of the message to delete. </param> |
| 222 | /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param> |
| 223 | /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception> |
| 224 | /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception> |
| 225 | /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception> |
| 226 | /// <returns> The response returned from the service. </returns> |
| 227 | public virtual ClientResult DeleteMessage(string threadId, string messageId, RequestOptions options) |
| 228 | { |
| 229 | Argument.AssertNotNullOrEmpty(threadId, nameof(threadId)); |
| 230 | Argument.AssertNotNullOrEmpty(messageId, nameof(messageId)); |
| 231 | |
| 232 | using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options); |
| 233 | return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); |
| 234 | } |
| 235 | } |
| 236 | |