1818use PhpLlm \LlmChain \ToolBox \AsTool ;
1919use PhpLlm \LlmChainBundle \DataCollector ;
2020use PhpLlm \LlmChainBundle \TraceableLanguageModel ;
21- use PhpLlm \LlmChainBundle \TraceableToolRegistry ;
21+ use PhpLlm \LlmChainBundle \TraceableToolBox ;
2222use Symfony \Component \Config \FileLocator ;
2323use Symfony \Component \DependencyInjection \ChildDefinition ;
2424use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -37,33 +37,33 @@ public function load(array $configs, ContainerBuilder $container): void
3737 $ configuration = new Configuration ();
3838 $ config = $ this ->processConfiguration ($ configuration , $ configs );
3939
40- foreach ($ config ['runtimes ' ] as $ name => $ runtime ) {
41- $ this ->processRuntimeConfig ($ name , $ runtime , $ container );
40+ foreach ($ config ['runtimes ' ] as $ runtimeName => $ runtime ) {
41+ $ this ->processRuntimeConfig ($ runtimeName , $ runtime , $ container );
4242 }
43- if (1 === count ($ config ['runtimes ' ])) {
44- $ container ->setAlias (Runtime::class, 'llm_chain.runtime. ' .$ name );
43+ if (1 === count ($ config ['runtimes ' ]) && isset ( $ runtimeName ) ) {
44+ $ container ->setAlias (Runtime::class, 'llm_chain.runtime. ' .$ runtimeName );
4545 }
4646
47- foreach ($ config ['llms ' ] as $ name => $ llm ) {
48- $ this ->processLlmConfig ($ name , $ llm , $ container );
47+ foreach ($ config ['llms ' ] as $ llmName => $ llm ) {
48+ $ this ->processLlmConfig ($ llmName , $ llm , $ container );
4949 }
50- if (1 === count ($ config ['llms ' ])) {
51- $ container ->setAlias (LanguageModel::class, 'llm_chain.llm. ' .$ name );
50+ if (1 === count ($ config ['llms ' ]) && isset ( $ llmName ) ) {
51+ $ container ->setAlias (LanguageModel::class, 'llm_chain.llm. ' .$ llmName );
5252 }
5353
54- foreach ($ config ['embeddings ' ] as $ name => $ embeddings ) {
55- $ this ->processEmbeddingsConfig ($ name , $ embeddings , $ container );
54+ foreach ($ config ['embeddings ' ] as $ embeddingsName => $ embeddings ) {
55+ $ this ->processEmbeddingsConfig ($ embeddingsName , $ embeddings , $ container );
5656 }
57- if (1 === count ($ config ['embeddings ' ])) {
58- $ container ->setAlias (EmbeddingModel::class, 'llm_chain.embeddings. ' .$ name );
57+ if (1 === count ($ config ['embeddings ' ]) && isset ( $ embeddingsName ) ) {
58+ $ container ->setAlias (EmbeddingModel::class, 'llm_chain.embeddings. ' .$ embeddingsName );
5959 }
6060
61- foreach ($ config ['stores ' ] as $ name => $ store ) {
62- $ this ->processStoreConfig ($ name , $ store , $ container );
61+ foreach ($ config ['stores ' ] as $ storeName => $ store ) {
62+ $ this ->processStoreConfig ($ storeName , $ store , $ container );
6363 }
64- if (1 === count ($ config ['stores ' ])) {
65- $ container ->setAlias (VectorStoreInterface::class, 'llm_chain.store. ' .$ name );
66- $ container ->setAlias (StoreInterface::class, 'llm_chain.store. ' .$ name );
64+ if (1 === count ($ config ['stores ' ]) && isset ( $ storeName ) ) {
65+ $ container ->setAlias (VectorStoreInterface::class, 'llm_chain.store. ' .$ storeName );
66+ $ container ->setAlias (StoreInterface::class, 'llm_chain.store. ' .$ storeName );
6767 }
6868
6969 $ container ->registerAttributeForAutoconfiguration (AsTool::class, static function (ChildDefinition $ definition , AsTool $ attribute ): void {
@@ -76,10 +76,13 @@ public function load(array $configs, ContainerBuilder $container): void
7676
7777 if (false === $ container ->getParameter ('kernel.debug ' )) {
7878 $ container ->removeDefinition (DataCollector::class);
79- $ container ->removeDefinition (TraceableToolRegistry ::class);
79+ $ container ->removeDefinition (TraceableToolBox ::class);
8080 }
8181 }
8282
83+ /**
84+ * @param array<string, mixed> $runtime
85+ */
8386 private function processRuntimeConfig (string $ name , array $ runtime , ContainerBuilder $ container ): void
8487 {
8588 if ('openai ' === $ runtime ['type ' ]) {
@@ -104,6 +107,9 @@ private function processRuntimeConfig(string $name, array $runtime, ContainerBui
104107 }
105108 }
106109
110+ /**
111+ * @param array<string, mixed> $llm
112+ */
107113 private function processLlmConfig (string $ name , array $ llm , ContainerBuilder $ container ): void
108114 {
109115 $ runtime = isset ($ llm ['runtime ' ]) ? 'llm_chain.runtime. ' .$ llm ['runtime ' ] : Runtime::class;
@@ -123,7 +129,10 @@ private function processLlmConfig(string $name, array $llm, ContainerBuilder $co
123129 }
124130 }
125131
126- private function processEmbeddingsConfig (string $ name , mixed $ embeddings , ContainerBuilder $ container ): void
132+ /**
133+ * @param array<string, mixed> $embeddings
134+ */
135+ private function processEmbeddingsConfig (string $ name , array $ embeddings , ContainerBuilder $ container ): void
127136 {
128137 $ runtime = isset ($ embeddings ['runtime ' ]) ? 'llm_chain.runtime. ' .$ embeddings ['runtime ' ] : Runtime::class;
129138
@@ -133,7 +142,10 @@ private function processEmbeddingsConfig(string $name, mixed $embeddings, Contai
133142 $ container ->setDefinition ('llm_chain.embeddings. ' .$ name , $ definition );
134143 }
135144
136- private function processStoreConfig (string $ name , mixed $ stores , ContainerBuilder $ container ): void
145+ /**
146+ * @param array<string, mixed> $stores
147+ */
148+ private function processStoreConfig (string $ name , array $ stores , ContainerBuilder $ container ): void
137149 {
138150 if ('chroma-db ' === $ stores ['engine ' ]) {
139151 $ definition = new ChildDefinition (ChromaDbStore::class);
0 commit comments