8000 fix(OpenAI): add testing for response cancel (#592) · openai-php/client@0e66f10 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e66f10

Browse files
authored
fix(OpenAI): add testing for response cancel (#592)
1 parent 59e27ca commit 0e66f10

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

src/Contracts/Resources/ResponsesContract.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public function createStreamed(array $parameters): StreamResponse;
4242
*/
4343
public function retrieve(string $id): RetrieveResponse;
4444

45+
/**
46+
* Cancels a model response with the given ID. Must be marked as 'background' to be cancellable.
47+
*
48+
* @see https://platform.openai.com/docs/api-reference/responses/cancel
49+
*/
50+
public function cancel(string $id): RetrieveResponse;
51+
4552
/**
4653
* Deletes a model response with the given ID.
4754
*

src/Testing/Resources/ResponsesTestResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function list(string $id, array $parameters = []): ListInputItems
4040
return $this->record(__FUNCTION__, func_get_args());
4141
}
4242

43+
public function cancel(string $id): RetrieveResponse
44+
{
45+
return $this->record(__FUNCTION__, func_get_args());
46+
}
47+
4348
public function delete(string $id): DeleteResponse
4449
{
4550
return $this->record(__FUNCTION__, func_get_args());
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace OpenAI\Testing\Responses\Fixtures\Responses;
4+
5+
final class CancelResponseFixture
6+
{
7+
public const ATTRIBUTES = [
8+
'id' => 'resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c',
9+
'object' => 'response',
10+
'created_at' => 1741484430,
11+
'status' => 'completed',
12+
'error' => null,
13+
'incomplete_details' => null,
14+
'instructions' => null,
15+
'max_output_tokens' => null,
16+
'model' => 'gpt-4o-2024-08-06',
17+
'output' => [
18+
[
19+
'type' => 'web_search_call',
20+
'id' => 'ws_67ccf18f64008190a39b619f4c8455ef087bb177ab789d5c',
21+
'status' => 'completed',
22+
],
23+
[
24+
'type' => 'message',
25+
'id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c',
26+
'status' => 'completed',
27+
'role' => 'assistant',
28+
'content' => [
29+
[
30+
'type' => 'output_text',
31+
'text' => 'As of today, March 9, 2025, one notable positive news story...',
32+
'annotations' => [
33+
[
34+
'type' => 'url_citation',
35+
'start_index' => 442,
36+
'end_index' => 557,
37+
'url' => 'https://.../?utm_source=chatgpt.com',
38+
'title' => '...',
39+
],
40+
[
41+
'type' => 'url_citation',
42+
'start_index' => 962,
43+
'end_index' => 1077,
44+
'url' => 'https://.../?utm_source=chatgpt.com',
45+
'title' => '...',
46+
],
47+
[
48+
'type' => 'url_citation',
49+
'start_index' => 1336,
50+
'end_index' => 1451,
51+
'url' => 'https://.../?utm_source=chatgpt.com',
52+
'title' => '...',
53+
],
54+
],
55+
],
56+
],
57+
],
58+
],
59+
'parallel_tool_calls' => true,
60+
'previous_response_id' => null,
61+
'reasoning' => [
62+
'effort' => null,
63+
'generate_summary' => null,
64+
],
65+
'store' => true,
66+
'temperature' => 1.0,
67+
'text' => [
68+
'format' => [
69+
'type' => 'text',
70+
],
71+
],
72+
'tool_choice' => 'auto',
73+
'tools' => [
74+
[
75+
'type' => 'web_search_preview',
76+
'domains' => [],
77+
'search_context_size' => 'medium',
78+
'user_location' => [
79+
'type' => 'approximate',
80+
'city' => 'San Francisco',
81+
'country' => 'US',
82+
'region' => 'California',
83+
'timezone' => 'America/Los_Angeles',
84+
],
85+
],
86+
],
87+
'top_p' => 1.0,
88+
'truncation' => 'disabled',
89+
'usage' => [
90+
'input_tokens' => 328,
91+
'input_tokens_details' => [
92+
'cached_tokens' => 0,
93+
],
94+
'output_tokens' => 356,
95+
'output_tokens_details' => [
96+
'reasoning_tokens' => 0,
97+
],
98+
'total_tokens' => 684,
99+
],
100+
'user' => null,
101+
'metadata' => [],
102+
];
103+
}

tests/Testing/Resources/ResponsesTestResource.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@
4747
});
4848
});
4949

50+
it('records a response cancel request', function () {
51+
$fake = new ClientFake([
52+
RetrieveResponse::fake(),
53+
]);
54+
55+
$fake->responses()->cancel('asst_SMzoVX8XmCZEg1EbMHoAm8tc');
56+
57+
$fake->assertSent(Responses::class, function ($method, $responseId) {
58+
return $method === 'cancel' &&
59+
$responseId === 'asst_SMzoVX8XmCZEg1EbMHoAm8tc';
60+
});
61+
});
62+
5063
it('records a response delete request', function () {
5164
$fake = new ClientFake([
5265
DeleteResponse::fake(),

0 commit comments

Comments
 (0)
0