Skip to content

Commit 0082388

Browse files
valtzuchr-hertel
authored andcommitted
fix: Allow array arguments in model.options (#103)
Allow array arguments in `model.options`
1 parent b6f4589 commit 0082388

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

src/ai-bundle/config/options.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
->scalarNode('name')->isRequired()->end()
7474
->scalarNode('version')->defaultNull()->end()
7575
->arrayNode('options')
76-
->scalarPrototype()->end()
76+
->variablePrototype()->end()
7777
->end()
7878
->end()
7979
->end()
@@ -199,7 +199,7 @@
199199
->scalarNode('name')->isRequired()->end()
200200
->scalarNode('version')->defaultNull()->end()
201201
->arrayNode('options')
202-
->scalarPrototype()->end()
202+
->variablePrototype()->end()
203203
->end()
204204
->end()
205205
->end()

src/ai-bundle/tests/AIBundleTest.php

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\AIBundle\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\Attributes\CoversClass;
15+
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
16+
use PHPUnit\Framework\Attributes\UsesClass;
17+
use PHPUnit\Framework\TestCase;
18+
use Symfony\AI\AIBundle\AIBundle;
19+
use Symfony\Component\DependencyInjection\ContainerBuilder;
20+
21+
#[CoversClass(AIBundle::class)]
22+
#[UsesClass(ContainerBuilder::class)]
23+
class AIBundleTest extends TestCase
24+
{
25+
#[DoesNotPerformAssertions]
26+
public function testExtensionLoad(): void
27+
{
28+
$container = new ContainerBuilder();
29+
$container->setParameter('kernel.debug', true);
30+
$container->setParameter('kernel.environment', 'dev');
31+
$container->setParameter('kernel.build_dir', 'public');
32+
$extension = (new AIBundle())->getContainerExtension();
33+
34+
$configs = $this->getFullConfig();
35+
$extension->load($configs, $container);
36+
}
37+
38+
/**
39+
* @return array<string, mixed>
40+
*/
41+
private function getFullConfig(): array
42+
{
43+
return [
44+
'ai' => [
45+
'platform' => [
46+
'anthropic' => [
47+
'api_key' => 'anthropic_key_full',
48+
],
49+
'azure' => [
50+
'my_azure_instance' => [
51+
'api_key' => 'azure_key_full',
52+
'base_url' => 'https://myazure.openai.azure.com/',
53+
'deployment' => 'gpt-35-turbo',
54+
'api_version' => '2024-02-15-preview',
55+
],
56+
'another_azure_instance' => [
57+
'api_key' => 'azure_key_2',
58+
'base_url' => 'https://myazure2.openai.azure.com/',
59+
'deployment' => 'gpt-4',
60+
'api_version' => '2024-02-15-preview',
61+
],
62+
],
63+
'google' => [
64+
'api_key' => 'google_key_full',
65+
],
66+
'openai' => [
67+
'api_key' => 'openai_key_full',
68+
],
69+
'mistral' => [
70+
'api_key' => 'mistral_key_full',
71+
],
72+
'openrouter' => [
73+
'api_key' => 'openrouter_key_full',
74+
],
75+
],
76+
'agent' => [
77+
'my_chat_agent' => [
78+
'platform' => 'openai_platform_service_id',
79+
'model' => [
80+
'name' => 'gpt',
81+
'version' => 'gpt-3.5-turbo',
82+
'options' => [
83+
'temperature' => 0.7,
84+
'max_tokens' => 150,
85+
'nested' => ['options' => ['work' => 'too']],
86+
],
87+
],
88+
'structured_output' => false,
89+
'system_prompt' => 'You are a helpful assistant.',
90+
'include_tools' => true,
91+
'tools' => [
92+
'enabled' => true,
93+
'services' => [
94+
['service' => 'my_tool_service_id', 'name' => 'myTool', 'description' => 'A test tool'],
95+
'another_tool_service_id', // String format
96+
],
97+
],
98+
'fault_tolerant_toolbox' => false,
99+
],
100+
'another_agent' => [
101+
'model' => ['name' => 'claude', 'version' => 'claude-3-opus-20240229'],
102+
'system_prompt' => 'Be concise.',
103+
],
104+
],
105+
'store' => [
106+
'azure_search' => [
107+
'my_azure_search_store' => [
108+
'endpoint' => 'https://mysearch.search.windows.net',
109+
'api_key' => 'azure_search_key',
110+
'index_name' => 'my-documents',
111+
'api_version' => '2023-11-01',
112+
'vector_field' => 'contentVector',
113+
],
114+
],
115+
'chroma_db' => [
116+
'my_chroma_store' => [
117+
'collection' => 'my_collection',
118+
],
119+
],
120+
'mongodb' => [
121+
'my_mongo_store' => [
122+
'database' => 'my_db',
123+
'collection' => 'my_collection',
124+
'index_name' => 'vector_index',
125+
'vector_field' => 'embedding',
126+
'bulk_write' => true,
127+
],
128+
],
129+
'pinecone' => [
130+
'my_pinecone_store' => [
131+
'namespace' => 'my_namespace',
132+
'filter' => ['category' => 'books'],
133+
'top_k' => 10,
134+
],
135+
],
136+
],
137+
'indexer' => [
138+
'my_text_indexer' => [
139+
'store' => 'my_azure_search_store_service_id',
140+
'platform' => 'google_platform_service_id',
141+
'model' => [
142+
'name' => 'embeddings',
143+
'version' => 'text-embedding-004',
144+
'options' => ['dimension' => 768],
145+
],
146+
],
147+
],
148+
],
149+
];
150+
}
151+
}

0 commit comments

Comments
 (0)