Skip to content

Commit 36a759d

Browse files
committed
fb
1 parent 21f0416 commit 36a759d

File tree

4 files changed

+221
-46
lines changed

4 files changed

+221
-46
lines changed

tests/Responses/ResponsesTests.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,50 @@ public async Task ResponseUsingConversations()
535535
{
536536
"type": "message",
537537
"role": "user",
538-
"content": "Say 'this is a test.'"
538+
"content": "tell me a joke"
539539
}
540540
]
541541
}
542542
"""u8.ToArray());
543543

544544
using BinaryContent requestContent = BinaryContent.Create(createConversationParameters);
545-
ClientResult conversationResult = await conversationClient.CreateConversationAsync(requestContent);
545+
var conversationResult = await conversationClient.CreateConversationAsync(requestContent);
546546
using JsonDocument conversationResultAsJson = JsonDocument.Parse(conversationResult.GetRawResponse().Content.ToString());
547547
string conversationId = conversationResultAsJson.RootElement.GetProperty("id"u8).GetString();
548548

549549
OpenAIResponseClient client = GetTestClient("gpt-4.1");
550550
OpenAIResponse response = await client.CreateResponseAsync(
551-
[ResponseItem.CreateUserMessageItem("Hello, model!")],
551+
[ResponseItem.CreateUserMessageItem("tell me another")],
552552
new ResponseCreationOptions()
553553
{
554554
ConversationId = conversationId,
555555
});
556556

557557
Assert.That(response, Is.Not.Null);
558558
Assert.That(response.ConversationId, Is.EqualTo(conversationId));
559+
560+
var conversationResults = conversationClient.GetConversationItemsAsync(conversationId);
561+
var conversationItems = new List<JsonElement>();
562+
await foreach (ClientResult result in conversationResults.GetRawPagesAsync())
563+
{
564+
using JsonDocument getConversationItemsResultAsJson = JsonDocument.Parse(result.GetRawResponse().Content.ToString());
565+
foreach (JsonElement element in getConversationItemsResultAsJson.RootElement.GetProperty("data").EnumerateArray())
566+
{
567+
conversationItems.Add(element.Clone());
568+
}
569+
}
570+
571+
Assert.That(conversationItems, Is.Not.Empty, "Expected the conversation to contain items.");
572+
Assert.That(conversationItems.Count, Is.GreaterThanOrEqualTo(2));
573+
574+
var lastItem = conversationItems[conversationItems.Count - 1];
575+
var secondLastItem = conversationItems[conversationItems.Count - 2];
576+
577+
string GetContentText(JsonElement item) =>
578+
item.GetProperty("content")[0].GetProperty("text").GetString();
579+
580+
Assert.That(GetContentText(lastItem), Is.EqualTo("tell me a joke"));
581+
Assert.That(GetContentText(secondLastItem), Is.EqualTo("tell me another"));
559582
}
560583

561584
[RecordedTest]

tests/SessionRecords/ResponsesTests/ResponseUsingConversations.json

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"RequestHeaders": {
77
"Accept": "application/json",
88
"Authorization": "Sanitized",
9-
"Content-Length": "179",
9+
"Content-Length": "172",
1010
"Content-Type": "application/json",
1111
"User-Agent": "OpenAI/2.7.0 (.NET 9.0.11; Microsoft Windows 10.0.26200)"
1212
},
@@ -18,15 +18,15 @@
1818
{
1919
"type": "message",
2020
"role": "user",
21-
"content": "Say 'this is a test.'"
21+
"content": "tell me a joke"
2222
}
2323
]
2424
},
2525
"StatusCode": 200,
2626
"ResponseHeaders": {
2727
"Alt-Svc": "h3=\":443\"",
2828
"cf-cache-status": "DYNAMIC",
29-
"CF-RAY": "9a3bfbbe89668a1a-BOM",
29+
"CF-RAY": "9a436f20dcee4808-BOM",
3030
"Connection": "keep-alive",
3131
"Content-Length": "164",
3232
"Content-Type": "application/json",
@@ -42,14 +42,14 @@
4242
],
4343
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
4444
"X-Content-Type-Options": "nosniff",
45-
"x-envoy-upstream-service-time": "432",
45+
"x-envoy-upstream-service-time": "117",
4646
"x-openai-proxy-wasm": "v0.1",
4747
"X-Request-ID": "Sanitized"
4848
},
4949
"ResponseBody": {
50-
"id": "conv_6924cd7745508196a24913721af0bb5e08b043bebee1496b",
50+
"id": "conv_6925fea431bc8194a4c88c67ea2867fc03291ba5d682a10e",
5151
"object": "conversation",
52-
"created_at": 1764019575,
52+
"created_at": 1764097700,
5353
"metadata": {
5454
"topic": "test"
5555
}
@@ -61,7 +61,7 @@
6161
"RequestHeaders": {
6262
"Accept": "application/json, text/event-stream",
6363
"Authorization": "Sanitized",
64-
"Content-Length": "190",
64+
"Content-Length": "192",
6565
"Content-Type": "application/json",
6666
"User-Agent": "OpenAI/2.7.0 (.NET 9.0.11; Microsoft Windows 10.0.26200)"
6767
},
@@ -74,20 +74,20 @@
7474
"content": [
7575
{
7676
"type": "input_text",
77-
"text": "Hello, model!"
77+
"text": "tell me another"
7878
}
7979
]
8080
}
8181
],
82-
"conversation": "conv_6924cd7745508196a24913721af0bb5e08b043bebee1496b"
82+
"conversation": "conv_6925fea431bc8194a4c88c67ea2867fc03291ba5d682a10e"
8383
},
8484
"StatusCode": 200,
8585
"ResponseHeaders": {
8686
"Alt-Svc": "h3=\":443\"",
8787
"cf-cache-status": "DYNAMIC",
88-
"CF-RAY": "9a3bfbcbc9c98a1a-BOM",
88+
"CF-RAY": "9a436f248eae4808-BOM",
8989
"Connection": "keep-alive",
90-
"Content-Length": "1578",
90+
"Content-Length": "1631",
9191
"Content-Type": "application/json",
9292
"Date": "Sanitized",
9393
"openai-organization": "Sanitized",
@@ -97,26 +97,26 @@
9797
"Server": "cloudflare",
9898
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
9999
"X-Content-Type-Options": "nosniff",
100-
"x-envoy-upstream-service-time": "2399",
100+
"x-envoy-upstream-service-time": "2431",
101101
"x-ratelimit-limit-requests": "10000",
102102
"x-ratelimit-limit-tokens": "30000000",
103103
"x-ratelimit-remaining-requests": "9999",
104-
"x-ratelimit-remaining-tokens": "29999959",
104+
"x-ratelimit-remaining-tokens": "29999963",
105105
"x-ratelimit-reset-requests": "6ms",
106106
"x-ratelimit-reset-tokens": "0s",
107107
"X-Request-ID": "Sanitized"
108108
},
109109
"ResponseBody": {
110-
"id": "resp_08b043bebee1496b006924cd7a195881969c78b7eaa7678cbe",
110+
"id": "resp_03291ba5d682a10e006925fea4c15c8194bdc6fd8a8091dbee",
111111
"object": "response",
112-
"created_at": 1764019578,
112+
"created_at": 1764097700,
113113
"status": "completed",
114114
"background": false,
115115
"billing": {
116116
"payer": "developer"
117117
},
118118
"conversation": {
119-
"id": "conv_6924cd7745508196a24913721af0bb5e08b043bebee1496b"
119+
"id": "conv_6925fea431bc8194a4c88c67ea2867fc03291ba5d682a10e"
120120
},
121121
"error": null,
122122
"incomplete_details": null,
@@ -126,15 +126,15 @@
126126
"model": "gpt-4.1-2025-04-14",
127127
"output": [
128128
{
129-
"id": "msg_08b043bebee1496b006924cd7afd648196b3654061f11bcc6a",
129+
"id": "msg_03291ba5d682a10e006925fea53e288194a866cc71cfc25f07",
130130
"type": "message",
131131
"status": "completed",
132132
"content": [
133133
{
134134
"type": "output_text",
135135
"annotations": [],
136136
"logprobs": [],
137-
"text": "Hello! This is a test. How can I help you today?"
137+
"text": "Sure! Here you go:\n\nWhy did the scarecrow win an award?\n\nBecause he was outstanding in his field!"
138138
}
139139
],
140140
"role": "assistant"
@@ -164,19 +164,95 @@
164164
"top_p": 1.0,
165165
"truncation": "disabled",
166166
"usage": {
167-
"input_tokens": 22,
167+
"input_tokens": 18,
168168
"input_tokens_details": {
169169
"cached_tokens": 0
170170
},
171-
"output_tokens": 15,
171+
"output_tokens": 24,
172172
"output_tokens_details": {
173173
"reasoning_tokens": 0
174174
},
175-
"total_tokens": 37
175+
"total_tokens": 42
176176
},
177177
"user": null,
178178
"metadata": {}
179179
}
180+
},
181+
{
182+
"RequestUri": "https://api.openai.com/v1/conversations/conv_6925fea431bc8194a4c88c67ea2867fc03291ba5d682a10e/items",
183+
"RequestMethod": "GET",
184+
"RequestHeaders": {
185+
"Accept": "application/json",
186+
"Authorization": "Sanitized",
187+
"User-Agent": "OpenAI/2.7.0 (.NET 9.0.11; Microsoft Windows 10.0.26200)"
188+
},
189+
"RequestBody": null,
190+
"StatusCode": 200,
191+
"ResponseHeaders": {
192+
"Alt-Svc": "h3=\":443\"",
193+
"cf-cache-status": "DYNAMIC",
194+
"CF-RAY": "9a436f38bf734808-BOM",
195+
"Connection": "keep-alive",
196+
"Content-Length": "1166",
197+
"Content-Type": "application/json",
198+
"Date": "Sanitized",
199+
"openai-organization": "Sanitized",
200+
"openai-processing-ms": "Sanitized",
201+
"openai-project": "Sanitized",
202+
"openai-version": "2020-10-01",
203+
"Server": "cloudflare",
204+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains; preload",
205+
"X-Content-Type-Options": "nosniff",
206+
"x-envoy-upstream-service-time": "105",
207+
"x-openai-proxy-wasm": "v0.1",
208+
"X-Request-ID": "Sanitized"
209+
},
210+
"ResponseBody": {
211+
"object": "list",
212+
"data": [
213+
{
214+
"id": "msg_03291ba5d682a10e006925fea53e288194a866cc71cfc25f07",
215+
"type": "message",
216+
"status": "completed",
217+
"content": [
218+
{
219+
"type": "output_text",
220+
"annotations": [],
221+
"logprobs": [],
222+
"text": "Sure! Here you go:\n\nWhy did the scarecrow win an award?\n\nBecause he was outstanding in his field!"
223+
}
224+
],
225+
"role": "assistant"
226+
},
227+
{
228+
"id": "msg_03291ba5d682a10e006925fea4ee788194a1f1ebb8a90e72ac",
229+
"type": "message",
230+
"status": "completed",
231+
"content": [
232+
{
233+
"type": "input_text",
234+
"text": "tell me another"
235+
}
236+
],
237+
"role": "user"
238+
},
239+
{
240+
"id": "msg_6925fea432288194bfac5ae77facf13a03291ba5d682a10e",
241+
"type": "message",
242+
"status": "completed",
243+
"content": [
244+
{
245+
"type": "input_text",
246+
"text": "tell me a joke"
247+
}
248+
],
249+
"role": "user"
250+
}
251+
],
252+
"first_id": "msg_03291ba5d682a10e006925fea53e288194a866cc71cfc25f07",
253+
"has_more": false,
254+
"last_id": "msg_6925fea432288194bfac5ae77facf13a03291ba5d682a10e"
255+
}
180256
}
181257
],
182258
"Variables": {

0 commit comments

Comments
 (0)