openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.2.0-beta.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Custom/Assistants/Internal/InternalAssistantMessageClient.Protocol.cs

165lines · modecode

1using System;
2using System.ClientModel;
3using System.ClientModel.Primitives;
4using System.Threading.Tasks;
5
6namespace OpenAI.Assistants;
7
8internal 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] Retrieve a message.
50 /// </summary>
51 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this message belongs. </param>
52 /// <param name="messageId"> The ID of the message to retrieve. </param>
53 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
54 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception>
55 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
56 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
57 /// <returns> The response returned from the service. </returns>
58 public virtual async Task<ClientResult> GetMessageAsync(string threadId, string messageId, RequestOptions options)
59 {
60 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
61 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
62
63 using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options);
64 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
65 }
66
67 /// <summary>
68 /// [Protocol Method] Retrieve a message.
69 /// </summary>
70 /// <param name="threadId"> The ID of the [thread](/docs/api-reference/threads) to which this message belongs. </param>
71 /// <param name="messageId"> The ID of the message to retrieve. </param>
72 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
73 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception>
74 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
75 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
76 /// <returns> The response returned from the service. </returns>
77 public virtual ClientResult GetMessage(string threadId, string messageId, RequestOptions options)
78 {
79 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
80 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
81
82 using PipelineMessage message = CreateGetMessageRequest(threadId, messageId, options);
83 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
84 }
85
86 /// <summary>
87 /// [Protocol Method] Modifies a message.
88 /// </summary>
89 /// <param name="threadId"> The ID of the thread to which this message belongs. </param>
90 /// <param name="messageId"> The ID of the message to modify. </param>
91 /// <param name="content"> The content to send as the body of the request. </param>
92 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
93 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="messageId"/> or <paramref name="content"/> is null. </exception>
94 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
95 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
96 /// <returns> The response returned from the service. </returns>
97 public virtual async Task<ClientResult> ModifyMessageAsync(string threadId, string messageId, BinaryContent content, RequestOptions options = null)
98 {
99 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
100 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
101 Argument.AssertNotNull(content, nameof(content));
102
103 using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options);
104 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
105 }
106
107 /// <summary>
108 /// [Protocol Method] Modifies a message.
109 /// </summary>
110 /// <param name="threadId"> The ID of the thread to which this message belongs. </param>
111 /// <param name="messageId"> The ID of the message to modify. </param>
112 /// <param name="content"> The content to send as the body of the request. </param>
113 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
114 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/>, <paramref name="messageId"/> or <paramref name="content"/> is null. </exception>
115 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
116 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
117 /// <returns> The response returned from the service. </returns>
118 public virtual ClientResult ModifyMessage(string threadId, string messageId, BinaryContent content, RequestOptions options = null)
119 {
120 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
121 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
122 Argument.AssertNotNull(content, nameof(content));
123
124 using PipelineMessage message = CreateModifyMessageRequest(threadId, messageId, content, options);
125 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
126 }
127
128 /// <summary>
129 /// [Protocol Method] Deletes a message.
130 /// </summary>
131 /// <param name="threadId"> The ID of the thread to which this message belongs. </param>
132 /// <param name="messageId"> The ID of the message to delete. </param>
133 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
134 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception>
135 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
136 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
137 /// <returns> The response returned from the service. </returns>
138 public virtual async Task<ClientResult> DeleteMessageAsync(string threadId, string messageId, RequestOptions options)
139 {
140 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
141 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
142
143 using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options);
144 return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
145 }
146
147 /// <summary>
148 /// [Protocol Method] Deletes a message.
149 /// </summary>
150 /// <param name="threadId"> The ID of the thread to which this message belongs. </param>
151 /// <param name="messageId"> The ID of the message to delete. </param>
152 /// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
153 /// <exception cref="ArgumentNullException"> <paramref name="threadId"/> or <paramref name="messageId"/> is null. </exception>
154 /// <exception cref="ArgumentException"> <paramref name="threadId"/> or <paramref name="messageId"/> is an empty string, and was expected to be non-empty. </exception>
155 /// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
156 /// <returns> The response returned from the service. </returns>
157 public virtual ClientResult DeleteMessage(string threadId, string messageId, RequestOptions options)
158 {
159 Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
160 Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
161
162 using PipelineMessage message = CreateDeleteMessageRequest(threadId, messageId, options);
163 return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
164 }
165}
166