-
-
Notifications
You must be signed in to change notification settings - Fork 663
Add support for Responses API #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit
Hold shift + click to select a range
d9f8bbb
Add support for Responses API
momostafa 3cea3dc
Updated miss placed files that occurred during first upload
momostafa 99a3ed5
Heavy refactoring to match codebase pattern, added testing files
momostafa 8ea527a
fixed some phpstan errors
momostafa 412f35c
fixing minor bugs after live testing now all models work during live …
momostafa 2c4c3fb
Merge branch 'openai-php:main' into dev
momostafa 29436e8
Fixed lint errors
momostafa 63c8c7c
Merge branch 'dev' of github.com:momostafa/openai-client into dev
momostafa dd263ac
Fixed all PHPStan Errors and all other tests Pass 100%
momostafa 5585119
Completed missing Tests, Created ClientFakeResponses, Modified Fakeable
momostafa caf4413
Updated Test files, Fixed Lint errors, all tests pass except test:unit
momostafa a8d5ac9
chore: remove log file
iBotPeaches 780ce1a
chore: pint
iBotPeaches fa48f22
chore: inline Responses doc to readme
iBotPeaches f41bec2
Merge remote-tracking branch 'upstream/main' into dev
iBotPeaches b1f5217
chore: align client contract to pattern
iBotPeaches dc444b8
docs: re-order chat/completion
iBotPeaches 69c7a13
fix: use longer replacement to not clobber Responses/*
iBotPeaches 1f68d23
fix: parse metadata (optionally)
iBotPeaches 5c28547
test: don't assert on plain arrays
iBotPeaches 3bc814b
test: assert stream properly on responses
iBotPeaches d533727
chore: add missing docblock property
iBotPeaches b982826
fix: add metadata into Responses payload
iBotPeaches 779446e
test: fix double nesting on delete attrs
iBotPeaches 56dd359
test: correct bad assertions on tests
iBotPeaches bec19fb
fix: remove ResponseObject
iBotPeaches 18bf40e
feat: split out usage into classes
iBotPeaches e9d3d95
feat: split out error into classes
iBotPeaches b21aca2
Merge remote-tracking branch 'origin/main' into dev
iBotPeaches d06d33b
feat: split out incomplete_details into classes
iBotPeaches 5792dea
chore(wip): introduction of 'output' typing
iBotPeaches 7fff62e
fix: correct OutputMessageContentOutputText + child classes
iBotPeaches d8ce1a6
OutputMessage
iBotPeaches b9db0a1
chore: continued work on output message
iBotPeaches 26990e2
chore: start of ComputerToolActions
iBotPeaches 4dda791
feat: complete "computer tool call"
iBotPeaches c9c5a56
fix: add response contract to existing classes
iBotPeaches 501d61f
fix: more fixes to typing on CreateResponse
iBotPeaches 314e189
feat: add 'reasoning' prop for response
iBotPeaches 63f6c10
feat: add 'text' (format) to create
iBotPeaches 788752b
feat: add 'tool_choice'
iBotPeaches 8798fbf
fix: add 'truncation'
iBotPeaches 5181077
feat: add tool: FileSearch response
iBotPeaches 219c6b8
feat: add tool: FunctionTool response
iBotPeaches 0701c15
feat: add tool 'ComputerUse'
iBotPeaches e56f9e9
fix: wire up 'tools' to CreateResponse
iBotPeaches e811af7
Added InputMessage types, refactored ListInputItems
momostafa 2c7f014
Merge branch 'dev' of github.com:momostafa/openai-client into dev
momostafa 323b5a4
Merge branch 'openai-php:main' into dev
momostafa 2952a02
Merge branch 'dev' of github.com:momostafa/openai-client into dev
momostafa efeb8d7
Corrected some properties to use camelCase
momostafa 1d20ee8
fix: cleanup docblock on CreateResponse
iBotPeaches 96c7fa0
chore: remove unused test response object
iBotPeaches f8c94d1
chore: remove extra newline
iBotPeaches 7a61c8b
fix: 'role' is always 'assistant'
iBotPeaches 697145a
test: augment tests with single click
iBotPeaches 30ef112
chore: add missing int for computer single click
iBotPeaches ac7868d
test: progression towards 100% coverage on create response
iBotPeaches 274498a
test: assertion on OutputFileSearchToolCall
iBotPeaches d4170aa
chore: ints for x/y on click event
iBotPeaches e14b07c
fix: further cleanup on CreateResponse
iBotPeaches 130f74b
feat: add computer tool call output
iBotPeaches 84cbb39
feat: add function tool call output
iBotPeaches 60bcce4
fix: city, region and timezone can return null
iBotPeaches 09d00e5
fix: json_schema description can be missing
iBotPeaches cc27c28
Lint Test Pass, Fixed Array map at ListInputItems
momostafa a3654b8
chore: rework text format typing on create response
iBotPeaches 62ad3e6
feat: rework into phpstan-types
iBotPeaches 9565b66
fix: work on ListInputItems for phpstan-types
iBotPeaches 88aea0d
fix: wire up RetrieveResponse
iBotPeaches 2bc99a7
fix: migrate to phpstan-type for delete
iBotPeaches ac3f976
fix: wip towards stream responses
iBotPeaches 717736b
chore: add typing props for delete
iBotPeaches 5f6fab5
test: correct tests for retrieve response
iBotPeaches 3aeb362
fix: add outputItem types for streaming
iBotPeaches 0cf96d3
fix: contentPart/textDelta/textAnnotation added
iBotPeaches 73adbc3
fix: outputrefusal*/outputText wired up
iBotPeaches 9c01bc7
chore: rename Refusal types
iBotPeaches 3efb38e
feat: finish typing for streaming
iBotPeaches a86b365
Wired all classes under Responses/Input
momostafa 557c25f
Merge branch 'dev' of github.com:momostafa/openai-client into dev
momostafa 5cf7c26
chore: type ListInputItems
iBotPeaches 262f363
fix: finalize ListInputItems
iBotPeaches 5d0827e
test: ListInputItem tests
iBotPeaches 531085c
test: stream testing
iBotPeaches 5d51c4c
fix: shove mock meta object into stream
iBotPeaches dba2c42
test: correct streaming tests
iBotPeaches dfc606e
chore: use local type
iBotPeaches 1938e1d
docs: cleanup readme
iBotPeaches 35e43b5
chore: align constructors
iBotPeaches 7979cf2
Merge branch 'openai-php:main' into dev
momostafa 985a244
fix: mark 'status' as optional in reasoning
iBotPeaches 86281f6
Merge remote-tracking branch 'origin/main' into dev
iBotPeaches d69b0e5
fix: add encrypted_content to reasoning
iBotPeaches d4d6a28
Merge branch 'openai-php:main' into dev
momostafa 616689c
Merge remote-tracking branch 'origin/main' into dev
iBotPeaches ceaa9e2
fix: file search filters can be null
iBotPeaches File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenAI\Responses\Responses; | ||
|
|
||
| use OpenAI\Contracts\ResponseContract; | ||
| use OpenAI\Responses\Concerns\ArrayAccessible; | ||
| use OpenAI\Responses\Concerns\HasMetaInformation; | ||
| use OpenAI\Contracts\ResponseHasMetaInformationContract; | ||
| use OpenAI\Contracts\StringableContract; | ||
| use OpenAI\Testing\Responses\Concerns\Fakeable; | ||
|
|
||
| /** | ||
| * @implements ResponseContract<array{id: string, object: string, created_at: int, status: string, error: ?array<string, mixed>, incomplete_details: ?array<string, mixed>, instructions: ?string, max_output_tokens: ?int, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: ?string, reasoning: array<string, mixed>, store: bool, temperature: ?float, text: array{format: array{type: string}}, tools: array<mixed>, top_p: ?float, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: ?string, metadata: array<string, string>}> | ||
| */ | ||
| final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract, StringableContract | ||
| { | ||
| use ArrayAccessible; | ||
|
|
||
| use Fakeable; | ||
| use HasMetaInformation; | ||
|
|
||
| private function __construct( | ||
iBotPeaches marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * The response id. | ||
| */ | ||
| public readonly string $id, | ||
|
|
||
| /** | ||
| * The object type, which is always response. | ||
| */ | ||
| public readonly string $object, | ||
|
|
||
| /** | ||
| * The Unix timestamp (in seconds) when the response was created. | ||
| */ | ||
| public readonly int $createdAt, | ||
|
|
||
| /** | ||
| * The status of the response. | ||
| */ | ||
| public readonly string $status, | ||
|
|
||
| /** | ||
| * The model used for response. | ||
| */ | ||
| public readonly string $model, | ||
|
|
||
| /** | ||
| * The output of the response. | ||
| * | ||
| * @var array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}> | ||
| */ | ||
| public readonly array $output, | ||
|
|
||
| /** | ||
| * Set of 16 key-value pairs that can be attached to the object. | ||
| * This can be useful for storing additional information about the object in a structured format. | ||
| */ | ||
| public readonly array $metadata, | ||
|
|
||
| /** | ||
| * The input for the response. | ||
| * | ||
| * @var string|array | ||
| */ | ||
| public readonly string|array $input = [], | ||
|
|
||
| public readonly ?array $error = null, | ||
| public readonly ?array $incompleteDetails = null, | ||
| public readonly ?string $instructions = null, | ||
| public readonly ?int $maxOutputTokens = null, | ||
| public readonly bool $parallelToolCalls = false, | ||
| public readonly ?string $previousResponseId = null, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param array{id: string, object: string, created_at: int, status: string, error: ?array<string, mixed>, incomplete_details: ?array<string, mixed>, instructions: ?string, max_output_tokens: ?int, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: ?string, reasoning: array<string, mixed>, store: bool, temperature: ?float, text: array{format: array{type: string}}, tools: array<mixed>, top_p: ?float, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: ?string, metadata: array<string, string>} $attributes | ||
| */ | ||
| public static function from(array $attributes, array $meta): self | ||
| { | ||
|
|
||
iBotPeaches marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new self( | ||
| $attributes['id'], | ||
| $attributes['object'], | ||
| $attributes['created_at'], | ||
| $attributes['status'], | ||
| $attributes['model'], | ||
| $attributes['output'], | ||
| $attributes['metadata'] ?? [], | ||
| $attributes['input'] ?? [], | ||
| $attributes['error'] ?? null, | ||
| $attributes['incomplete_details'] ?? null, | ||
| $attributes['instructions'] ?? null, | ||
| $attributes['max_output_tokens'] ?? null, | ||
| $attributes['parallel_tool_calls'] ?? false, | ||
| $attributes['previous_response_id'] ?? null, | ||
| $attributes['reasoning'] ?? [], | ||
| $attributes['store'] ?? false, | ||
| $attributes['temperature'] ?? null, | ||
| $attributes['text'] ?? [], | ||
| $attributes['tools'] ?? [], | ||
| $attributes['top_p'] ?? null, | ||
| $attributes['truncation'] ?? 'disabled', | ||
| $attributes['usage'] ?? null, | ||
| $attributes['user'] ?? null, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toString(): string | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'id' => $this->id, | ||
| 'object' => $this->object, | ||
| 'created_at' => $this->createdAt, | ||
| 'status' => $this->status, | ||
| 'model' => $this->model, | ||
| 'output' => $this->output, | ||
| 'metadata' => $this->metadata, | ||
| 'input' => $this->input, | ||
| 'error' => $this->error, | ||
| 'incomplete_details' => $this->incompleteDetails, | ||
| 'instructions' => $this->instructions, | ||
| 'max_output_tokens' => $this->maxOutputTokens, | ||
| 'parallel_tool_calls' => $this->parallelToolCalls, | ||
| 'previous_response_id' => $this->previousResponseId, | ||
| 'reasoning' => $this->reasoning, | ||
| 'store' => $this->store, | ||
| 'temperature' => $this->temperature, | ||
| 'text' => $this->text, | ||
| 'tools' => $this->tools, | ||
| 'top_p' => $this->topP, | ||
| 'truncation' => $this->truncation, | ||
| 'usage' => $this->usage, | ||
| 'user' => $this->user, | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenAI\Responses\Responses; | ||
|
|
||
| use OpenAI\Contracts\ResponseStreamContract; | ||
| use OpenAI\Responses\StreamResponse; | ||
| use OpenAI\Testing\Resources\Responses; | ||
| use Psr\Http\Message\ResponseInterface; | ||
| use OpenAI\Responses\Responses\PartialResponses\CreatedPartialResponse; | ||
|
|
||
| /** | ||
| * @implements ResponseStreamContract<CreatedPartialResponse> | ||
| */ | ||
| final class CreateStreamedResponse extends StreamResponse implements ResponseStreamContract | ||
| { | ||
| protected static function partialResponseClass(): string | ||
| { | ||
| return CreatedPartialResponse::class; | ||
| } | ||
|
|
||
| /** | ||
| * @return \Generator<CreatedPartialResponse> | ||
| */ | ||
| public static function fromResponse(ResponseInterface $response): \Generator | ||
| { | ||
| foreach (self::decodeStream($response) as $line) { | ||
| yield CreatedPartialResponse::from(json_decode($line, true, 512, JSON_THROW_ON_ERROR), []); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param callable(CreatedPartialResponse): void $callback | ||
| */ | ||
| public static function stream(ResponseInterface $response, callable $callback): void | ||
| { | ||
| foreach (self::decodeStream($response) as $line) { | ||
| $callback(CreatedPartialResponse::from(json_decode($line, true, 512, JSON_THROW_ON_ERROR), [])); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenAI\Responses\Responses\Input; | ||
|
|
||
| use OpenAI\Contracts\ResponseContract; | ||
| use OpenAI\Responses\Concerns\ArrayAccessible; | ||
| use OpenAI\Responses\Concerns\HasMetaInformation; | ||
| use OpenAI\Contracts\ResponseHasMetaInformationContract; | ||
| use OpenAI\Contracts\StringableContract; | ||
|
|
||
| /** | ||
| * @implements ResponseContract<array{id: string, object: string, content: string}> | ||
| */ | ||
| final class Data implements ResponseContract, ResponseHasMetaInformationContract, StringableContract | ||
| { | ||
| use ArrayAccessible; | ||
| use HasMetaInformation; | ||
|
|
||
| private function __construct( | ||
| /** | ||
| * The input id. | ||
| */ | ||
| public readonly string $id, | ||
|
|
||
| /** | ||
| * The object type, which is always input. | ||
| */ | ||
| public readonly string $object, | ||
|
|
||
| /** | ||
| * The content of the input. | ||
| */ | ||
| public readonly string $content, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param array{id: string, object: string, content: string} $attributes | ||
| */ | ||
| public static function from(array $attributes, array $meta): self | ||
| { | ||
| return new self( | ||
| $attributes['id'], | ||
| $attributes['object'], | ||
| $attributes['content'], | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toString(): string | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'id' => $this->id, | ||
| 'object' => $this->object, | ||
| 'content' => $this->content, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenAI\Responses\Responses; | ||
|
|
||
| use OpenAI\Contracts\ResponseContract; | ||
| use OpenAI\Responses\Concerns\ArrayAccessible; | ||
| use OpenAI\Responses\Concerns\HasMetaInformation; | ||
| use OpenAI\Contracts\ResponseHasMetaInformationContract; | ||
| use OpenAI\Contracts\StringableContract; | ||
|
|
||
| /** | ||
| * @implements ResponseContract<array{id: string, object: string, deleted: bool}> | ||
| */ | ||
| final class DeleteResponse implements ResponseContract, ResponseHasMetaInformationContract, StringableContract | ||
| { | ||
| use ArrayAccessible; | ||
| use HasMetaInformation; | ||
|
|
||
| private function __construct( | ||
| /** | ||
| * The response id. | ||
| */ | ||
| public readonly string $id, | ||
|
|
||
| /** | ||
| * The object type, which is always response. | ||
| */ | ||
| public readonly string $object, | ||
|
|
||
| /** | ||
| * Whether the response was successfully deleted. | ||
| */ | ||
| public readonly bool $deleted, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param array{id: string, object: string, deleted: bool} $attributes | ||
| */ | ||
| public static function from(array $attributes, array $meta): self | ||
| { | ||
| return new self( | ||
| $attributes['id'], | ||
| $attributes['object'], | ||
| $attributes['deleted'], | ||
| $meta, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toString(): string | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'id' => $this->id, | ||
| 'object' => $this->object, | ||
| 'deleted' => $this->deleted, | ||
| ]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.