Skip to content

Commit ed841e5

Browse files
Add @throws annotation
1 parent 7b5652b commit ed841e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+355
-11
lines changed

phpstan.neon.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@ parameters:
55
excludePaths:
66
analyse:
77
- src/Testing
8+
exceptions:
9+
check:
10+
missingCheckedExceptionInThrows: true
11+
tooWideThrowType: true
12+
implicitThrows: false
13+
uncheckedExceptionClasses:
14+
- Http\Discovery\Exception\NotFoundException
15+
- LogicException
16+
- JsonException
817

918
reportUnmatchedIgnoredErrors: true

src/Contracts/Resources/AssistantsContract.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Assistants\AssistantDeleteResponse;
67
use OpenAI\Responses\Assistants\AssistantListResponse;
78
use OpenAI\Responses\Assistants\AssistantResponse;
@@ -14,13 +15,17 @@ interface AssistantsContract
1415
* @see https://platform.openai.com/docs/api-reference/assistants/object
1516
*
1617
* @param array<string, mixed> $parameters
18+
*
19+
* @throws OpenAIThrowable
1720
*/
1821
public function create(array $parameters): AssistantResponse;
1922

2023
/**
2124
* Retrieves an assistant.
2225
*
2326
* @see https://platform.openai.com/docs/api-reference/assistants/getAssistant
27+
*
28+
* @throws OpenAIThrowable
2429
*/
2530
public function retrieve(string $id): AssistantResponse;
2631

@@ -30,13 +35,17 @@ public function retrieve(string $id): AssistantResponse;
3035
* @see https://platform.openai.com/docs/api-reference/assistants/modifyAssistant
3136
*
3237
* @param array<string, mixed> $parameters
38+
*
39+
* @throws OpenAIThrowable
3340
*/
3441
public function modify(string $id, array $parameters): AssistantResponse;
3542

3643
/**
3744
* Delete an assistant.
3845
*
3946
* @see https://platform.openai.com/docs/api-reference/assistants/deleteAssistant
47+
*
48+
* @throws OpenAIThrowable
4049
*/
4150
public function delete(string $id): AssistantDeleteResponse;
4251

@@ -46,13 +55,17 @@ public function delete(string $id): AssistantDeleteResponse;
4655
* @see https://platform.openai.com/docs/api-reference/assistants/listAssistants
4756
*
4857
* @param array<string, mixed> $parameters
58+
*
59+
* @throws OpenAIThrowable
4960
*/
5061
public function list(array $parameters = []): AssistantListResponse;
5162

5263
/**
5364
* Manage files attached to an assistant.
5465
*
5566
* @see https://platform.openai.com/docs/api-reference/assistants
67+
*
68+
* @throws OpenAIThrowable
5669
*/
5770
public function files(): AssistantsFilesContract;
5871
}

src/Contracts/Resources/AssistantsFilesContract.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Assistants\Files\AssistantFileDeleteResponse;
67
use OpenAI\Responses\Assistants\Files\AssistantFileListResponse;
78
use OpenAI\Responses\Assistants\Files\AssistantFileResponse;
@@ -14,20 +15,26 @@ interface AssistantsFilesContract
1415
* @see https://platform.openai.com/docs/api-reference/assistants/createAssistantFile
1516
*
1617
* @param array<string, mixed> $parameters
18+
*
19+
* @throws OpenAIThrowable
1720
*/
1821
public function create(string $assistantId, array $parameters): AssistantFileResponse;
1922

2023
/**
2124
* Retrieves an AssistantFile.
2225
*
2326
* @see https://platform.openai.com/docs/api-reference/assistants/getAssistantFile
27+
*
28+
* @throws OpenAIThrowable
2429
*/
2530
public function retrieve(string $assistantId, string $fileId): AssistantFileResponse;
2631

2732
/**
2833
* Delete an assistant file.
2934
*
3035
* @see https://platform.openai.com/docs/api-reference/assistants/deleteAssistantFile
36+
*
37+
* @throws OpenAIThrowable
3138
*/
3239
public function delete(string $assistantId, string $fileId): AssistantFileDeleteResponse;
3340

@@ -37,6 +44,8 @@ public function delete(string $assistantId, string $fileId): AssistantFileDelete
3744
* @see https://platform.openai.com/docs/api-reference/assistants/listAssistantFiles
3845
*
3946
* @param array<string, mixed> $parameters
47+
*
48+
* @throws OpenAIThrowable
4049
*/
4150
public function list(string $assistantId, array $parameters = []): AssistantFileListResponse;
4251
}

src/Contracts/Resources/AudioContract.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Audio\SpeechStreamResponse;
67
use OpenAI\Responses\Audio\TranscriptionResponse;
78
use OpenAI\Responses\Audio\TranslationResponse;
@@ -14,6 +15,8 @@ interface AudioContract
1415
* @see https://platform.openai.com/docs/api-reference/audio/createSpeech
1516
*
1617
* @param array<string, mixed> $parameters
18+
*
19+
* @throws OpenAIThrowable
1720
*/
1821
public function speech(array $parameters): string;
1922

@@ -23,6 +26,8 @@ public function speech(array $parameters): string;
2326
* @see https://platform.openai.com/docs/api-reference/audio/createSpeech
2427
*
2528
* @param array<string, mixed> $parameters
29+
*
30+
* @throws OpenAIThrowable
2631
*/
2732
public function speechStreamed(array $parameters): SpeechStreamResponse;
2833

@@ -32,6 +37,8 @@ public function speechStreamed(array $parameters): SpeechStreamResponse;
3237
* @see https://platform.openai.com/docs/api-reference/audio/createTranscription
3338
*
3439
* @param array<string, mixed> $parameters
40+
*
41+
* @throws OpenAIThrowable
3542
*/
3643
public function transcribe(array $parameters): TranscriptionResponse;
3744

@@ -41,6 +48,8 @@ public function transcribe(array $parameters): TranscriptionResponse;
4148
* @see https://platform.openai.com/docs/api-reference/audio/createTranslation
4249
*
4350
* @param array<string, mixed> $parameters
51+
*
52+
* @throws OpenAIThrowable
4453
*/
4554
public function translate(array $parameters): TranslationResponse;
4655
}

src/Contracts/Resources/ChatContract.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Chat\CreateResponse;
67
use OpenAI\Responses\Chat\CreateStreamedResponse;
78
use OpenAI\Responses\StreamResponse;
@@ -14,6 +15,8 @@ interface ChatContract
1415
* @see https://platform.openai.com/docs/api-reference/chat/create
1516
*
1617
* @param array<string, mixed> $parameters
18+
*
19+
* @throws OpenAIThrowable
1720
*/
1821
public function create(array $parameters): CreateResponse;
1922

@@ -24,6 +27,8 @@ public function create(array $parameters): CreateResponse;
2427
*
2528
* @param array<string, mixed> $parameters
2629
* @return StreamResponse<CreateStreamedResponse>
30+
*
31+
* @throws OpenAIThrowable
2732
*/
2833
public function createStreamed(array $parameters): StreamResponse;
2934
}

src/Contracts/Resources/CompletionsContract.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Completions\CreateResponse;
67
use OpenAI\Responses\Completions\CreateStreamedResponse;
78
use OpenAI\Responses\StreamResponse;
@@ -14,6 +15,8 @@ interface CompletionsContract
1415
* @see https://platform.openai.com/docs/api-reference/completions/create-completion
1516
*
1617
* @param array<string, mixed> $parameters
18+
*
19+
* @throws OpenAIThrowable
1720
*/
1821
public function create(array $parameters): CreateResponse;
1922

@@ -24,6 +27,8 @@ public function create(array $parameters): CreateResponse;
2427
*
2528
* @param array<string, mixed> $parameters
2629
* @return StreamResponse<CreateStreamedResponse>
30+
*
31+
* @throws OpenAIThrowable
2732
*/
2833
public function createStreamed(array $parameters): StreamResponse;
2934
}

src/Contracts/Resources/EditsContract.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Edits\CreateResponse;
67

78
interface EditsContract
@@ -13,6 +14,8 @@ interface EditsContract
1314
*
1415
* @param array<string, mixed> $parameters
1516
*
17+
* @throws OpenAIThrowable
18+
*
1619
* @deprecated OpenAI has deprecated this endpoint and will stop working by January 4, 2024.
1720
* https://openai.com/blog/gpt-4-api-general-availability#deprecation-of-the-edits-api
1821
*/

src/Contracts/Resources/EmbeddingsContract.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Embeddings\CreateResponse;
67

78
interface EmbeddingsContract
@@ -12,6 +13,8 @@ interface EmbeddingsContract
1213
* @see https://platform.openai.com/docs/api-reference/embeddings/create
1314
*
1415
* @param array<string, mixed> $parameters
16+
*
17+
* @throws OpenAIThrowable
1518
*/
1619
public function create(array $parameters): CreateResponse;
1720
}

src/Contracts/Resources/FilesContract.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\Files\CreateResponse;
67
use OpenAI\Responses\Files\DeleteResponse;
78
use OpenAI\Responses\Files\ListResponse;
@@ -13,20 +14,26 @@ interface FilesContract
1314
* Returns a list of files that belong to the user's organization.
1415
*
1516
* @see https://platform.openai.com/docs/api-reference/files/list
17+
*
18+
* @throws OpenAIThrowable
1619
*/
1720
public function list(): ListResponse;
1821

1922
/**
2023
* Returns information about a specific file.
2124
*
2225
* @see https://platform.openai.com/docs/api-reference/files/retrieve
26+
*
27+
* @throws OpenAIThrowable
2328
*/
2429
public function retrieve(string $file): RetrieveResponse;
2530

2631
/**
2732
* Returns the contents of the specified file.
2833
*
2934
* @see https://platform.openai.com/docs/api-reference/files/retrieve-content
35+
*
36+
* @throws OpenAIThrowable
3037
*/
3138
public function download(string $file): string;
3239

@@ -36,13 +43,17 @@ public function download(string $file): string;
3643
* @see https://platform.openai.com/docs/api-reference/files/upload
3744
*
3845
* @param array<string, mixed> $parameters
46+
*
47+
* @throws OpenAIThrowable
3948
*/
4049
public function upload(array $parameters): CreateResponse;
4150

4251
/**
4352
* Delete a file.
4453
*
4554
* @see https://platform.openai.com/docs/api-reference/files/delete
55+
*
56+
* @throws OpenAIThrowable
4657
*/
4758
public function delete(string $file): DeleteResponse;
4859
}

src/Contracts/Resources/FineTunesContract.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenAI\Contracts\Resources;
44

5+
use OpenAI\Exceptions\OpenAIThrowable;
56
use OpenAI\Responses\FineTunes\ListEventsResponse;
67
use OpenAI\Responses\FineTunes\ListResponse;
78
use OpenAI\Responses\FineTunes\RetrieveResponse;
@@ -18,34 +19,44 @@ interface FineTunesContract
1819
* @see https://platform.openai.com/docs/api-reference/fine-tunes/create
1920
*
2021
* @param array<string, mixed> $parameters
22+
*
23+
* @throws OpenAIThrowable
2124
*/
2225
public function create(array $parameters): RetrieveResponse;
2326

2427
/**
2528
* List your organization's fine-tuning jobs.
2629
*
2730
* @see https://platform.openai.com/docs/api-reference/fine-tunes/list
31+
*
32+
* @throws OpenAIThrowable
2833
*/
2934
public function list(): ListResponse;
3035

3136
/**
3237
* Gets info about the fine-tune job.
3338
*
3439
* @see https://platform.openai.com/docs/api-reference/fine-tunes/list
40+
*
41+
* @throws OpenAIThrowable
3542
*/
3643
public function retrieve(string $fineTuneId): RetrieveResponse;
3744

3845
/**
3946
* Immediately cancel a fine-tune job.
4047
*
4148
* @see https://platform.openai.com/docs/api-reference/fine-tunes/cancel
49+
*
50+
* @throws OpenAIThrowable
4251
*/
4352
public function cancel(string $fineTuneId): RetrieveResponse;
4453

4554
/**
4655
* Get fine-grained status updates for a fine-tune job.
4756
*
4857
* @see https://platform.openai.com/docs/api-reference/fine-tunes/events
58+
*
59+
* @throws OpenAIThrowable
4960
*/
5061
public function listEvents(string $fineTuneId): ListEventsResponse;
5162

@@ -55,6 +66,8 @@ public function listEvents(string $fineTuneId): ListEventsResponse;
5566
* @see https://platform.openai.com/docs/api-reference/fine-tunes/events
5667
*
5768
* @return StreamResponse<RetrieveStreamedResponseEvent>
69+
*
70+
* @throws OpenAIThrowable
5871
*/
5972
public function listEventsStreamed(string $fineTuneId): StreamResponse;
6073
}

0 commit comments

Comments
 (0)