Skip to content

Commit ecdb49d

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

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

src/ai-bundle/src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getConfigTreeBuilder(): TreeBuilder
8484
->scalarNode('name')->isRequired()->end()
8585
->scalarNode('version')->defaultNull()->end()
8686
->arrayNode('options')
87-
->scalarPrototype()->end()
87+
->variablePrototype()->end()
8888
->end()
8989
->end()
9090
->end()
@@ -210,7 +210,7 @@ public function getConfigTreeBuilder(): TreeBuilder
210210
->scalarNode('name')->isRequired()->end()
211211
->scalarNode('version')->defaultNull()->end()
212212
->arrayNode('options')
213-
->scalarPrototype()->end()
213+
->variablePrototype()->end()
214214
->end()
215215
->end()
216216
->end()
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\DependencyInjection\AIExtension;
19+
use Symfony\AI\AIBundle\DependencyInjection\Configuration;
20+
use Symfony\Component\DependencyInjection\ContainerBuilder;
21+
22+
#[CoversClass(Configuration::class)]
23+
#[UsesClass(ContainerBuilder::class)]
24+
#[UsesClass(AIExtension::class)]
25+
class ConfigurationTest extends TestCase
26+
{
27+
#[DoesNotPerformAssertions]
28+
public function testExtensionLoad(): void
29+
{
30+
$container = new ContainerBuilder();
31+
$container->setParameter('kernel.debug', true);
32+
$extension = new AIExtension();
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)