Skip to content

Commit a3b7616

Browse files
authored
fix(OpenAI): Apply OpenAI-Beta to all Assistant type resources (#701)
1 parent f999a5d commit a3b7616

File tree

4 files changed

+63
-21
lines changed

4 files changed

+63
-21
lines changed

src/Resources/Threads.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public function create(array $parameters = []): ThreadResponse
3232
$payload = Payload::create('threads', $parameters);
3333

3434
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
35-
$response = $this->transporter->requestObject($payload);
35+
$response = $this->transporter
36+
->addHeader('OpenAI-Beta', 'assistants=v2')
37+
->requestObject($payload);
3638

3739
return ThreadResponse::from($response->data(), $response->meta());
3840
}
@@ -49,7 +51,9 @@ public function createAndRun(array $parameters): ThreadRunResponse
4951
$payload = Payload::create('threads/runs', $parameters);
5052

5153
/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, assistant_id: string, status: string, required_action?: array{type: string, submit_tool_outputs: array{tool_calls: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}}, last_error: ?array{code: string, message: string}, expires_at: ?int, started_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, metadata: array<string, string>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}, incomplete_details: ?array{reason: string}, temperature: float|int|null, top_p: null|float|int, max_prompt_tokens: ?int, max_completion_tokens: ?int, truncation_strategy: array{type: string, last_messages: ?int}, tool_choice: string|array{type: string, function?: array{name: string}}, response_format: string|array{type: 'text'|'json_object'}}> $response */
52-
$response = $this->transporter->requestObject($payload);
54+
$response = $this->transporter
55+
->addHeader('OpenAI-Beta', 'assistants=v2')
56+
->requestObject($payload);
5357

5458
return ThreadRunResponse::from($response->data(), $response->meta());
5559
}
@@ -68,7 +72,9 @@ public function createAndRunStreamed(array $parameters): StreamResponse
6872

6973
$payload = Payload::create('threads/runs', $parameters);
7074

71-
$response = $this->transporter->requestStream($payload);
75+
$response = $this->transporter
76+
->addHeader('OpenAI-Beta', 'assistants=v2')
77+
->requestStream($payload);
7278

7379
return new StreamResponse(ThreadRunStreamResponse::class, $response);
7480
}
@@ -83,7 +89,9 @@ public function retrieve(string $id): ThreadResponse
8389
$payload = Payload::retrieve('threads', $id);
8490

8591
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
86-
$response = $this->transporter->requestObject($payload);
92+
$response = $this->transporter
93+
->addHeader('OpenAI-Beta', 'assistants=v2')
94+
->requestObject($payload);
8795

8896
return ThreadResponse::from($response->data(), $response->meta());
8997
}
@@ -100,7 +108,9 @@ public function modify(string $id, array $parameters): ThreadResponse
100108
$payload = Payload::modify('threads', $id, $parameters);
101109

102110
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
103-
$response = $this->transporter->requestObject($payload);
111+
$response = $this->transporter
112+
->addHeader('OpenAI-Beta', 'assistants=v2')
113+
->requestObject($payload);
104114

105115
return ThreadResponse::from($response->data(), $response->meta());
106116
}
@@ -115,7 +125,9 @@ public function delete(string $id): ThreadDeleteResponse
115125
$payload = Payload::delete('threads', $id);
116126

117127
/** @var Response<array{id: string, object: string, deleted: bool}> $response */
118-
$response = $this->transporter->requestObject($payload);
128+
$response = $this->transporter
129+
->addHeader('OpenAI-Beta', 'assistants=v2')
130+
->requestObject($payload);
119131

120132
return ThreadDeleteResponse::from($response->data(), $response->meta());
121133
}

src/Resources/ThreadsMessages.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public function create(string $threadId, array $parameters): ThreadMessageRespon
2727
$payload = Payload::create("threads/$threadId/messages", $parameters);
2828

2929
/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array<int, array{type: 'image_url', image_url: array{url: string, detail?: string}}|array{type: 'image_file', image_file: array{file_id: string, detail?: string}}|array{type: 'text', text: array{value: string, annotations: array<int, array{type: 'file_citation', text: string, file_citation: array{file_id: string, quote?: string}, start_index: int, end_index: int}|array{type: 'file_path', text: string, file_path: array{file_id: string}, start_index: int, end_index: int}>}}>, assistant_id: ?string, run_id: ?string, attachments?: array<int, array{file_id: string, tools: array<int, array{type: 'file_search'}|array{type: 'code_interpreter'}>}>, metadata: array<string, string>}> $response */
30-
$response = $this->transporter->requestObject($payload);
30+
$response = $this->transporter
31+
->addHeader('OpenAI-Beta', 'assistants=v2')
32+
->requestObject($payload);
3133

3234
return ThreadMessageResponse::from($response->data(), $response->meta());
3335
}
@@ -42,7 +44,9 @@ public function retrieve(string $threadId, string $messageId): ThreadMessageResp
4244
$payload = Payload::retrieve("threads/$threadId/messages", $messageId);
4345

4446
/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array<int, array{type: 'image_url', image_url: array{url: string, detail?: string}}|array{type: 'image_file', image_file: array{file_id: string, detail?: string}}|array{type: 'text', text: array{value: string, annotations: array<int, array{type: 'file_citation', text: string, file_citation: array{file_id: string, quote?: string}, start_index: int, end_index: int}|array{type: 'file_path', text: string, file_path: array{file_id: string}, start_index: int, end_index: int}>}}>, assistant_id: ?string, run_id: ?string, attachments?: array<int, array{file_id: string, tools: array<int, array{type: 'file_search'}|array{type: 'code_interpreter'}>}>, metadata: array<string, string>}> $response */
45-
$response = $this->transporter->requestObject($payload);
47+
$response = $this->transporter
48+
->addHeader('OpenAI-Beta', 'assistants=v2')
49+
->requestObject($payload);
4650

4751
return ThreadMessageResponse::from($response->data(), $response->meta());
4852
}
@@ -59,7 +63,9 @@ public function modify(string $threadId, string $messageId, array $parameters):
5963
$payload = Payload::modify("threads/$threadId/messages", $messageId, $parameters);
6064

6165
/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array<int, array{type: 'image_url', image_url: array{url: string, detail?: string}}|array{type: 'image_file', image_file: array{file_id: string, detail?: string}}|array{type: 'text', text: array{value: string, annotations: array<int, array{type: 'file_citation', text: string, file_citation: array{file_id: string, quote?: string}, start_index: int, end_index: int}|array{type: 'file_path', text: string, file_path: array{file_id: string}, start_index: int, end_index: int}>}}>, assistant_id: ?string, run_id: ?string, attachments?: array<int, array{file_id: string, tools: array<int, array{type: 'file_search'}|array{type: 'code_interpreter'}>}>, metadata: array<string, string>}> $response */
62-
$response = $this->transporter->requestObject($payload);
66+
$response = $this->transporter
67+
->addHeader('OpenAI-Beta', 'assistants=v2')
68+
->requestObject($payload);
6369

6470
return ThreadMessageResponse::from($response->data(), $response->meta());
6571
}
@@ -74,7 +80,9 @@ public function delete(string $threadId, string $messageId): ThreadMessageDelete
7480
$payload = Payload::delete("threads/$threadId/messages", $messageId);
7581

7682
/** @var Response<array{id: string, object: string, deleted: bool}> $response */
77-
$response = $this->transporter->requestObject($payload);
83+
$response = $this->transporter
84+
->addHeader('OpenAI-Beta', 'assistants=v2')
85+
->requestObject($payload);
7886

7987
return ThreadMessageDeleteResponse::from($response->data(), $response->meta());
8088
}
@@ -91,7 +99,9 @@ public function list(string $threadId, array $parameters = []): ThreadMessageLis
9199
$payload = Payload::list("threads/$threadId/messages", $parameters);
92100

93101
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, thread_id: string, role: string, content: array<int, array{type: 'image_url', image_url: array{url: string, detail?: string}}|array{type: 'image_file', image_file: array{file_id: string, detail?: string}}|array{type: 'text', text: array{value: string, annotations: array<int, array{type: 'file_citation', text: string, file_citation: array{file_id: string, quote?: string}, start_index: int, end_index: int}|array{type: 'file_path', text: string, file_path: array{file_id: string}, start_index: int, end_index: int}>}}>, assistant_id: ?string, run_id: ?string, attachments?: array<int, array{file_id: string, tools: array<int, array{type: 'file_search'}|array{type: 'code_interpreter'}>}>, metadata: array<string, string>}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
94-
$response = $this->transporter->requestObject($payload);
102+
$response = $this->transporter
103+
->addHeader('OpenAI-Beta', 'assistants=v2')
104+
->requestObject($payload);
95105

96106
return ThreadMessageListResponse::from($response->data(), $response->meta());
97107
}

0 commit comments

Comments
 (0)