Skip to content

Commit b89d28a

Browse files
committed
tests
1 parent f71b006 commit b89d28a

File tree

5 files changed

+316
-14
lines changed

5 files changed

+316
-14
lines changed

src/Custom/Chat/ChatClient.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,26 +448,29 @@ public virtual async Task<ClientResult> GetChatCompletionAsync(GetChatCompletion
448448
}
449449

450450
[Experimental("OPENAI001")]
451-
public virtual ClientResult<ChatCompletionList> GetChatCompletionMessages(GetChatCompletionMessageOptions options, CancellationToken cancellationToken = default)
451+
[OverloadResolutionPriority(2)]
452+
public virtual ClientResult<ChatCompletionMessageList> GetChatCompletionMessages(GetChatCompletionMessageOptions options, CancellationToken cancellationToken = default)
452453
{
453454
Argument.AssertNotNullOrEmpty(options.CompletionId, nameof(options.CompletionId));
454455

455456
PipelineMessage message = CreateGetChatCompletionMessagesRequest(options.CompletionId, options.After, options.Limit, options.Order, cancellationToken.ToRequestOptions());
456457
ClientResult result = ClientResult.FromResponse(Pipeline.ProcessMessage(message, cancellationToken.ToRequestOptions()));
457-
return ClientResult.FromValue((ChatCompletionList)result, result.GetRawResponse());
458+
return ClientResult.FromValue((ChatCompletionMessageList)result, result.GetRawResponse());
458459
}
459460

460461
[Experimental("OPENAI001")]
461-
public virtual async Task<ClientResult<ChatCompletionList>> GetChatCompletionMessagesAsync(GetChatCompletionMessageOptions options, CancellationToken cancellationToken = default)
462+
[OverloadResolutionPriority(2)]
463+
public virtual async Task<ClientResult<ChatCompletionMessageList>> GetChatCompletionMessagesAsync(GetChatCompletionMessageOptions options, CancellationToken cancellationToken = default)
462464
{
463465
Argument.AssertNotNullOrEmpty(options.CompletionId, nameof(options.CompletionId));
464466

465467
PipelineMessage message = CreateGetChatCompletionMessagesRequest(options.CompletionId, options.After, options.Limit, options.Order, cancellationToken.ToRequestOptions());
466468
ClientResult result = ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, cancellationToken.ToRequestOptions()).ConfigureAwait(false));
467-
return ClientResult.FromValue((ChatCompletionList)result, result.GetRawResponse());
469+
return ClientResult.FromValue((ChatCompletionMessageList)result, result.GetRawResponse());
468470
}
469471

470472
[Experimental("OPENAI001")]
473+
[OverloadResolutionPriority(1)]
471474
public virtual CollectionResult GetChatCompletionMessages(GetChatCompletionMessageOptions options, RequestOptions requestOptions = null)
472475
{
473476
Argument.AssertNotNullOrEmpty(options.CompletionId, nameof(options.CompletionId));
@@ -482,6 +485,7 @@ public virtual CollectionResult GetChatCompletionMessages(GetChatCompletionMessa
482485
}
483486

484487
[Experimental("OPENAI001")]
488+
[OverloadResolutionPriority(1)]
485489
public virtual AsyncCollectionResult GetChatCompletionMessagesAsync(GetChatCompletionMessageOptions options, RequestOptions requestOptions = null)
486490
{
487491
Argument.AssertNotNullOrEmpty(options.CompletionId, nameof(options.CompletionId));

src/Custom/Chat/ChatCompletionMessageList.Serialization.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// <auto-generated/>
2-
3-
#nullable disable
4-
51
using System;
62
using System.ClientModel;
73
using System.ClientModel.Primitives;
@@ -12,7 +8,7 @@
128

139
namespace OpenAI.Chat
1410
{
15-
internal partial class ChatCompletionMessageList : IJsonModel<ChatCompletionMessageList>
11+
public partial class ChatCompletionMessageList : IJsonModel<ChatCompletionMessageList>
1612
{
1713
internal ChatCompletionMessageList() : this(null, null, null, null, default, default)
1814
{

src/Custom/Chat/ChatCompletionMessageList.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// <auto-generated/>
2-
3-
#nullable disable
4-
51
using System.ClientModel.Primitives;
62
using System.Collections.Generic;
73
using System.ComponentModel;
@@ -11,7 +7,7 @@
117

128
namespace OpenAI.Chat
139
{
14-
internal partial class ChatCompletionMessageList
10+
public partial class ChatCompletionMessageList
1511
{
1612
[Experimental("SCME0001")]
1713
private JsonPatch _patch;

tests/Chat/ChatStoreTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,58 @@ await RetryWithExponentialBackoffAsync(async () =>
867867
catch { /* Ignore cleanup errors */ }
868868
}
869869

870+
[RecordedTest]
871+
public async Task GetChatCompletionMessagesWithBasicUsage_PM()
872+
{
873+
ChatClient client = GetTestClient();
874+
875+
// Create a completion with stored output enabled to have messages
876+
ChatCompletionOptions createOptions = new()
877+
{
878+
StoredOutputEnabled = true,
879+
Metadata = { ["test_scenario"] = "basic_messages" }
880+
};
881+
882+
ChatCompletion completion = await client.CompleteChatAsync(
883+
["Basic messages test: Say 'Hello, this is a test message.'"],
884+
createOptions);
885+
886+
887+
GetChatCompletionMessageOptions messageOptions = new GetChatCompletionMessageOptions
888+
{
889+
CompletionId = completion.Id
890+
};
891+
892+
ChatCompletionMessageList messageList = null;
893+
int messageCount = 0;
894+
895+
do
896+
{
897+
await RetryWithExponentialBackoffAsync(async () =>
898+
{
899+
// Test basic enumeration of messages
900+
messageList = await client.GetChatCompletionMessagesAsync(messageOptions);
901+
});
902+
903+
foreach (var message in messageList.Data)
904+
{
905+
messageCount++;
906+
Assert.That(message.Id, Is.Not.Null.And.Not.Empty);
907+
Assert.That(message.Content, Is.EqualTo("Basic messages test: Say 'Hello, this is a test message.'"));
908+
909+
if (messageCount >= 5) break; // Prevent infinite loop
910+
}
911+
} while (messageList?.HasMore ?? false);
912+
Assert.That(messageCount, Is.GreaterThan(0));
913+
914+
// Clean up
915+
try
916+
{
917+
await client.DeleteChatCompletionAsync(completion.Id);
918+
}
919+
catch { /* Ignore cleanup errors */ }
920+
}
921+
870922
[Test]
871923
public async Task GetChatCompletionMessagesWithPagination()
872924
{
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "https://api.openai.com/v1/chat/completions",
5+
"RequestMethod": "POST",
6+
"RequestHeaders": {
7+
"Accept": "application/json",
8+
"Authorization": "Sanitized",
9+
"Content-Length": "181",
10+
"Content-Type": "application/json",
11+
"User-Agent": "OpenAI/2.5.0 (.NET 9.0.10; Darwin 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132)"
12+
},
13+
"RequestBody": {
14+
"metadata": {
15+
"test_scenario": "basic_messages"
16+
},
17+
"messages": [
18+
{
19+
"role": "user",
20+
"content": "Basic messages test: Say 'Hello, this is a test message.'"
21+
}
22+
],
23+
"model": "gpt-4o-mini",
24+
"store": true
25+
},
26+
"StatusCode": 200,
27+
"ResponseHeaders": {
28+
"Access-Control-Expose-Headers": "X-Request-ID",
29+
"Alt-Svc": "h3=\":443\"",
30+
"cf-cache-status": "DYNAMIC",
31+
"CF-RAY": "9953c7245a626b5e-DFW",
32+
"Connection": "keep-alive",
33+
"Content-Type": "application/json",
34+
"Date": "Mon, 27 Oct 2025 17:05:24 GMT",
35+
"openai-organization": "Sanitized",
36+
"openai-processing-ms": "635",
37+
"openai-project": "Sanitized",
38+
"openai-version": "2020-10-01",
39+
"Server": "cloudflare",
40+
"Set-Cookie": [
41+
"Sanitized",
42+
"Sanitized"
43+
],
44+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
45+
"Transfer-Encoding": "chunked",
46+
"X-Content-Type-Options": "nosniff",
47+
"x-envoy-upstream-service-time": "835",
48+
"x-openai-proxy-wasm": "v0.1",
49+
"x-ratelimit-limit-requests": "30000",
50+
"x-ratelimit-limit-tokens": "150000000",
51+
"x-ratelimit-remaining-requests": "29999",
52+
"x-ratelimit-remaining-tokens": "149999982",
53+
"x-ratelimit-reset-requests": "2ms",
54+
"x-ratelimit-reset-tokens": "0s",
55+
"X-Request-ID": "Sanitized"
56+
},
57+
"ResponseBody": {
58+
"id": "chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw",
59+
"object": "chat.completion",
60+
"created": 1761584723,
61+
"model": "gpt-4o-mini-2024-07-18",
62+
"choices": [
63+
{
64+
"index": 0,
65+
"message": {
66+
"role": "assistant",
67+
"content": "Hello, this is a test message.",
68+
"refusal": null,
69+
"annotations": []
70+
},
71+
"logprobs": null,
72+
"finish_reason": "stop"
73+
}
74+
],
75+
"usage": {
76+
"prompt_tokens": 21,
77+
"completion_tokens": 8,
78+
"total_tokens": 29,
79+
"prompt_tokens_details": {
80+
"cached_tokens": 0,
81+
"audio_tokens": 0
82+
},
83+
"completion_tokens_details": {
84+
"reasoning_tokens": 0,
85+
"audio_tokens": 0,
86+
"accepted_prediction_tokens": 0,
87+
"rejected_prediction_tokens": 0
88+
}
89+
},
90+
"service_tier": "default",
91+
"system_fingerprint": "Sanitized"
92+
}
93+
},
94+
{
95+
"RequestUri": "https://api.openai.com/v1/chat/completions/chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw/messages",
96+
"RequestMethod": "GET",
97+
"RequestHeaders": {
98+
"Accept": "application/json",
99+
"Authorization": "Sanitized",
100+
"User-Agent": "OpenAI/2.5.0 (.NET 9.0.10; Darwin 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132)"
101+
},
102+
"RequestBody": null,
103+
"StatusCode": 404,
104+
"ResponseHeaders": {
105+
"Alt-Svc": "h3=\":443\"",
106+
"cf-cache-status": "DYNAMIC",
107+
"CF-RAY": "9953c72e9db66b5e-DFW",
108+
"Connection": "keep-alive",
109+
"Content-Length": "189",
110+
"Content-Type": "application/json",
111+
"Date": "Mon, 27 Oct 2025 17:05:24 GMT",
112+
"openai-organization": "Sanitized",
113+
"openai-processing-ms": "369",
114+
"openai-project": "Sanitized",
115+
"openai-version": "2020-10-01",
116+
"Server": "cloudflare",
117+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
118+
"X-Content-Type-Options": "nosniff",
119+
"x-envoy-upstream-service-time": "371",
120+
"x-openai-proxy-wasm": "v0.1",
121+
"X-Request-ID": "Sanitized"
122+
},
123+
"ResponseBody": {
124+
"error": {
125+
"message": "Completion chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw not found",
126+
"type": "invalid_request_error",
127+
"param": "completion_id",
128+
"code": "not_found"
129+
}
130+
}
131+
},
132+
{
133+
"RequestUri": "https://api.openai.com/v1/chat/completions/chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw/messages",
134+
"RequestMethod": "GET",
135+
"RequestHeaders": {
136+
"Accept": "application/json",
137+
"Authorization": "Sanitized",
138+
"User-Agent": "OpenAI/2.5.0 (.NET 9.0.10; Darwin 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132)"
139+
},
140+
"RequestBody": null,
141+
"StatusCode": 404,
142+
"ResponseHeaders": {
143+
"Alt-Svc": "h3=\":443\"",
144+
"cf-cache-status": "DYNAMIC",
145+
"CF-RAY": "9953c7363d426b5e-DFW",
146+
"Connection": "keep-alive",
147+
"Content-Length": "189",
148+
"Content-Type": "application/json",
149+
"Date": "Mon, 27 Oct 2025 17:05:25 GMT",
150+
"openai-organization": "Sanitized",
151+
"openai-processing-ms": "87",
152+
"openai-project": "Sanitized",
153+
"openai-version": "2020-10-01",
154+
"Server": "cloudflare",
155+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
156+
"X-Content-Type-Options": "nosniff",
157+
"x-envoy-upstream-service-time": "89",
158+
"x-openai-proxy-wasm": "v0.1",
159+
"X-Request-ID": "Sanitized"
160+
},
161+
"ResponseBody": {
162+
"error": {
163+
"message": "Completion chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw not found",
164+
"type": "invalid_request_error",
165+
"param": "completion_id",
166+
"code": "not_found"
167+
}
168+
}
169+
},
170+
{
171+
"RequestUri": "https://api.openai.com/v1/chat/completions/chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw/messages",
172+
"RequestMethod": "GET",
173+
"RequestHeaders": {
174+
"Accept": "application/json",
175+
"Authorization": "Sanitized",
176+
"User-Agent": "OpenAI/2.5.0 (.NET 9.0.10; Darwin 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132)"
177+
},
178+
"RequestBody": null,
179+
"StatusCode": 200,
180+
"ResponseHeaders": {
181+
"Alt-Svc": "h3=\":443\"",
182+
"cf-cache-status": "DYNAMIC",
183+
"CF-RAY": "9953c7408fbf6b5e-DFW",
184+
"Connection": "keep-alive",
185+
"Content-Length": "317",
186+
"Content-Type": "application/json",
187+
"Date": "Mon, 27 Oct 2025 17:05:27 GMT",
188+
"openai-organization": "Sanitized",
189+
"openai-processing-ms": "181",
190+
"openai-project": "Sanitized",
191+
"openai-version": "2020-10-01",
192+
"Server": "cloudflare",
193+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
194+
"X-Content-Type-Options": "nosniff",
195+
"x-envoy-upstream-service-time": "183",
196+
"x-openai-proxy-wasm": "v0.1",
197+
"X-Request-ID": "Sanitized"
198+
},
199+
"ResponseBody": {
200+
"object": "list",
201+
"data": [
202+
{
203+
"id": "chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw-0",
204+
"role": "user",
205+
"content": "Basic messages test: Say 'Hello, this is a test message.'",
206+
"content_parts": null,
207+
"name": null
208+
}
209+
],
210+
"first_id": "chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw-0",
211+
"last_id": "chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw-0",
212+
"has_more": false
213+
}
214+
},
215+
{
216+
"RequestUri": "https://api.openai.com/v1/chat/completions/chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw",
217+
"RequestMethod": "DELETE",
218+
"RequestHeaders": {
219+
"Accept": "application/json",
220+
"Authorization": "Sanitized",
221+
"User-Agent": "OpenAI/2.5.0 (.NET 9.0.10; Darwin 25.0.0 Darwin Kernel Version 25.0.0: Wed Sep 17 21:42:08 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T8132)"
222+
},
223+
"RequestBody": null,
224+
"StatusCode": 200,
225+
"ResponseHeaders": {
226+
"Alt-Svc": "h3=\":443\"",
227+
"cf-cache-status": "DYNAMIC",
228+
"CF-RAY": "9953c74279906b5e-DFW",
229+
"Connection": "keep-alive",
230+
"Content-Length": "97",
231+
"Content-Type": "application/json",
232+
"Date": "Mon, 27 Oct 2025 17:05:27 GMT",
233+
"openai-organization": "Sanitized",
234+
"openai-processing-ms": "398",
235+
"openai-project": "Sanitized",
236+
"openai-version": "2020-10-01",
237+
"Server": "cloudflare",
238+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
239+
"X-Content-Type-Options": "nosniff",
240+
"x-envoy-upstream-service-time": "400",
241+
"x-openai-proxy-wasm": "v0.1",
242+
"X-Request-ID": "Sanitized"
243+
},
244+
"ResponseBody": {
245+
"object": "chat.completion.deleted",
246+
"id": "chatcmpl-CVKwljY7I29TrcoYAzC1rLM9cFQZw",
247+
"deleted": true
248+
}
249+
}
250+
],
251+
"Variables": {
252+
"OPEN-API-KEY": "api-key"
253+
}
254+
}

0 commit comments

Comments
 (0)