mirror of
https://github.com/symfony/ai-bundle.git
synced 2026-03-23 23:12:08 +01:00
[Platform] Generate JSON schema using Validator metadata
This commit is contained in:
@@ -101,7 +101,8 @@
|
||||
"symfony/ai-weaviate-store": "^0.6",
|
||||
"symfony/expression-language": "^7.3|^8.0",
|
||||
"symfony/security-core": "^7.3|^8.0",
|
||||
"symfony/translation": "^7.3|^8.0"
|
||||
"symfony/translation": "^7.3|^8.0",
|
||||
"symfony/validator": "^7.3|^8.0"
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"autoload": {
|
||||
|
||||
@@ -64,6 +64,7 @@ use Symfony\AI\Platform\Contract\JsonSchema\Describer\MethodDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Describer\PropertyInfoDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Describer\SerializerDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Describer\TypeInfoDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Describer\ValidatorConstraintsDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Describer\WithAttributeDescriber;
|
||||
use Symfony\AI\Platform\Contract\JsonSchema\Factory as SchemaFactory;
|
||||
use Symfony\AI\Platform\EventListener\TemplateRendererListener;
|
||||
@@ -180,6 +181,11 @@ return static function (ContainerConfigurator $container): void {
|
||||
service('serializer.mapping.class_metadata_factory')->ignoreOnInvalid(),
|
||||
])
|
||||
->tag('ai.platform.json_schema.describer')
|
||||
->set('ai.platform.json_schema.describer.validator', ValidatorConstraintsDescriber::class)
|
||||
->args([
|
||||
service('validator')->nullOnInvalid(),
|
||||
])
|
||||
->tag('ai.platform.json_schema.describer')
|
||||
->set('ai.platform.json_schema.describer.with_attribute', WithAttributeDescriber::class)
|
||||
->tag('ai.platform.json_schema.describer')
|
||||
->set('ai.platform.json_schema.describer', Describer::class)
|
||||
|
||||
@@ -139,6 +139,7 @@ use Symfony\Component\HttpClient\HttpClient;
|
||||
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
/**
|
||||
@@ -370,6 +371,10 @@ final class AiBundle extends AbstractBundle
|
||||
$builder->removeDefinition('ai.command.setup_message_store');
|
||||
$builder->removeDefinition('ai.command.drop_message_store');
|
||||
}
|
||||
|
||||
if (!ContainerBuilder::willBeAvailable('symfony/validator', ValidatorInterface::class, ['symfony/ai-bundle'])) {
|
||||
$builder->removeDefinition('ai.platform.json_schema.describer.validator');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -163,12 +163,11 @@ class AiBundleTest extends TestCase
|
||||
|
||||
$this->assertFalse($container->hasDefinition('ai.command.setup_store'));
|
||||
$this->assertFalse($container->hasDefinition('ai.command.drop_store'));
|
||||
$this->assertSame([
|
||||
'ai.command.setup_store' => true,
|
||||
'ai.command.drop_store' => true,
|
||||
'ai.command.setup_message_store' => true,
|
||||
'ai.command.drop_message_store' => true,
|
||||
], $container->getRemovedIds());
|
||||
$removedIds = $container->getRemovedIds();
|
||||
$this->assertArrayHasKey('ai.command.setup_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.drop_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.setup_message_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.drop_message_store', $removedIds);
|
||||
}
|
||||
|
||||
public function testMessageStoreCommandsArentDefinedWithoutMessageStore()
|
||||
@@ -185,12 +184,11 @@ class AiBundleTest extends TestCase
|
||||
|
||||
$this->assertFalse($container->hasDefinition('ai.command.setup_message_store'));
|
||||
$this->assertFalse($container->hasDefinition('ai.command.drop_message_store'));
|
||||
$this->assertSame([
|
||||
'ai.command.setup_store' => true,
|
||||
'ai.command.drop_store' => true,
|
||||
'ai.command.setup_message_store' => true,
|
||||
'ai.command.drop_message_store' => true,
|
||||
], $container->getRemovedIds());
|
||||
$removedIds = $container->getRemovedIds();
|
||||
$this->assertArrayHasKey('ai.command.setup_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.drop_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.setup_message_store', $removedIds);
|
||||
$this->assertArrayHasKey('ai.command.drop_message_store', $removedIds);
|
||||
}
|
||||
|
||||
public function testStoreCommandsAreDefined()
|
||||
|
||||
Reference in New Issue
Block a user