-
-
Notifications
You must be signed in to change notification settings - Fork 124
[Platform] Migrate OpenAI to Responses API #871
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
Open
paulinevos
wants to merge
7
commits into
symfony:main
Choose a base branch
from
paulinevos:responses-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
942a88e
Replace OpenAI's `o1-preview` with `o3`
paulinevos 0c7ac1a
Disable GPT audio example and capability
paulinevos 3c9299a
Add PDF capabilities to OpenAI vision capable models
paulinevos d2ddf2e
Create content normalizers for Responses API
paulinevos 1abdea1
Create tool (call) normalizers for Responses API
paulinevos 22e7074
Create Responses normalizers for message types
paulinevos 8166232
Migrate from OpenAI chat completions to Responses
paulinevos 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
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
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
59 changes: 59 additions & 0 deletions
59
src/platform/src/Bridge/OpenAi/Contract/Gpt/Message/AssistantMessageNormalizer.php
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,59 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Platform\Bridge\OpenAi\Contract\Gpt\Message; | ||
|
|
||
| use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
| use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer; | ||
| use Symfony\AI\Platform\Message\AssistantMessage; | ||
| use Symfony\AI\Platform\Model; | ||
| use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
| use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
|
|
||
| /** | ||
| * @author Guillermo Lengemann <[email protected]> | ||
| */ | ||
| final class AssistantMessageNormalizer extends ModelContractNormalizer implements NormalizerAwareInterface | ||
| { | ||
| use NormalizerAwareTrait; | ||
|
|
||
| /** | ||
| * @param AssistantMessage $data | ||
| * | ||
| * @return array{ | ||
| * role: 'assistant', | ||
| * type: 'message', | ||
| * content: ?string | ||
| * } | ||
| */ | ||
| public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
| { | ||
| if ($data->hasToolCalls()) { | ||
| return $this->normalizer->normalize($data->getToolCalls(), $format, $context); | ||
| } | ||
|
|
||
| return [ | ||
| 'role' => $data->getRole()->value, | ||
| 'type' => 'message', | ||
| 'content' => $data->getContent(), | ||
| ]; | ||
| } | ||
|
|
||
| protected function supportedDataClass(): string | ||
| { | ||
| return AssistantMessage::class; | ||
| } | ||
|
|
||
| protected function supportsModel(Model $model): bool | ||
| { | ||
| return $model instanceof Gpt; | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/platform/src/Bridge/OpenAi/Contract/Gpt/Message/Content/DocumentNormalizer.php
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,49 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Platform\Bridge\OpenAi\Contract\Gpt\Message\Content; | ||
|
|
||
| use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
| use Symfony\AI\Platform\Capability; | ||
| use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer; | ||
| use Symfony\AI\Platform\Message\Content\Document; | ||
| use Symfony\AI\Platform\Message\Content\File; | ||
| use Symfony\AI\Platform\Model; | ||
|
|
||
| /** | ||
| * @author Guillermo Lengemann <[email protected]> | ||
| */ | ||
| class DocumentNormalizer extends ModelContractNormalizer | ||
| { | ||
| /** | ||
| * @param File $data | ||
| * | ||
| * @return array{type: 'input_file', filename: string, file_data: string} | ||
| */ | ||
| public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
| { | ||
| return [ | ||
| 'type' => 'input_file', | ||
| 'filename' => $data->getFilename(), | ||
| 'file_data' => $data->asDataUrl(), | ||
| ]; | ||
| } | ||
|
|
||
| protected function supportedDataClass(): string | ||
| { | ||
| return Document::class; | ||
| } | ||
|
|
||
| protected function supportsModel(Model $model): bool | ||
| { | ||
| return $model instanceof Gpt && $model->supports(Capability::INPUT_PDF); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/platform/src/Bridge/OpenAi/Contract/Gpt/Message/Content/ImageNormalizer.php
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,50 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Platform\Bridge\OpenAi\Contract\Gpt\Message\Content; | ||
|
|
||
| use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
| use Symfony\AI\Platform\Capability; | ||
| use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer; | ||
| use Symfony\AI\Platform\Message\Content\Image; | ||
| use Symfony\AI\Platform\Model; | ||
|
|
||
| /** | ||
| * See: https://platform.openai.com/docs/guides/images-vision#giving-a-model-images-as-input. | ||
| */ | ||
| final class ImageNormalizer extends ModelContractNormalizer | ||
| { | ||
| /** | ||
| * @param Image $data | ||
| * | ||
| * @return array{ | ||
| * type: 'input_image', | ||
| * image_url: string | ||
| * } | ||
| */ | ||
| public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
| { | ||
| return [ | ||
| 'type' => 'input_image', | ||
| 'image_url' => $data->asDataUrl(), | ||
| ]; | ||
| } | ||
|
|
||
| protected function supportedDataClass(): string | ||
| { | ||
| return Image::class; | ||
| } | ||
|
|
||
| protected function supportsModel(Model $model): bool | ||
| { | ||
| return $model instanceof Gpt && $model->supports(Capability::INPUT_IMAGE); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/platform/src/Bridge/OpenAi/Contract/Gpt/Message/Content/ImageUrlNormalizer.php
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,50 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Platform\Bridge\OpenAi\Contract\Gpt\Message\Content; | ||
|
|
||
| use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
| use Symfony\AI\Platform\Capability; | ||
| use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer; | ||
| use Symfony\AI\Platform\Message\Content\ImageUrl; | ||
| use Symfony\AI\Platform\Model; | ||
|
|
||
| /** | ||
| * See: https://platform.openai.com/docs/guides/images-vision#giving-a-model-images-as-input. | ||
| */ | ||
| final class ImageUrlNormalizer extends ModelContractNormalizer | ||
| { | ||
| /** | ||
| * @param ImageUrl $data | ||
| * | ||
| * @return array{ | ||
| * type: 'input_image', | ||
| * image_url: string | ||
| * } | ||
| */ | ||
| public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
| { | ||
| return [ | ||
| 'type' => 'input_image', | ||
| 'image_url' => $data->getUrl(), | ||
| ]; | ||
| } | ||
|
|
||
| protected function supportedDataClass(): string | ||
| { | ||
| return ImageUrl::class; | ||
| } | ||
|
|
||
| protected function supportsModel(Model $model): bool | ||
| { | ||
| return $model instanceof Gpt && $model->supports(Capability::INPUT_IMAGE); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
src/platform/src/Bridge/OpenAi/Contract/Gpt/Message/Content/TextNormalizer.php
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,49 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Platform\Bridge\OpenAi\Contract\Gpt\Message\Content; | ||
|
|
||
| use Symfony\AI\Platform\Bridge\OpenAi\Gpt; | ||
| use Symfony\AI\Platform\Contract\Normalizer\ModelContractNormalizer; | ||
| use Symfony\AI\Platform\Message\Content\Text; | ||
| use Symfony\AI\Platform\Model; | ||
|
|
||
| /** | ||
| * See: https://platform.openai.com/docs/guides/images-vision#giving-a-model-images-as-input. | ||
| */ | ||
| final class TextNormalizer extends ModelContractNormalizer | ||
| { | ||
| /** | ||
| * @param Text $data | ||
| * | ||
| * @return array{ | ||
| * type: 'input_text', | ||
| * text: string | ||
| * } | ||
| */ | ||
| public function normalize(mixed $data, ?string $format = null, array $context = []): array | ||
| { | ||
| return [ | ||
| 'type' => 'input_text', | ||
| 'text' => $data->getText(), | ||
| ]; | ||
| } | ||
|
|
||
| protected function supportedDataClass(): string | ||
| { | ||
| return Text::class; | ||
| } | ||
|
|
||
| protected function supportsModel(Model $model): bool | ||
| { | ||
| return $model instanceof Gpt; | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after reverting these changes, the example will work again - i guess that due to my hackle with that other PR, sry!