@@ -25,29 +25,54 @@ public function configure(DefinitionConfigurator $definition): void
2525 $ root = $ definition ->rootNode ();
2626 assert ($ root instanceof ArrayNodeDefinition);
2727 $ children = $ root ->children ();
28- $ children ->scalarNode ('api_key ' )->defaultValue ('%env(OPENAI_API_KEY)% ' );
29- $ children ->scalarNode ('organization ' )->defaultValue ('%env(default::OPENAI_ORGANIZATION)% ' );
28+ $ children
29+ ->scalarNode ('api_key ' )
30+ ->defaultValue ('%env(OPENAI_API_KEY)% ' )
31+ ->info ('OpenAI API Key used to authenticate with the OpenAI API ' )
32+ ->isRequired ();
33+ $ children
34+ ->scalarNode ('organization ' )
35+ ->info ('OpenAI API Organization used to authenticate with the OpenAI API ' )
36+ ->defaultValue ('%env(default::OPENAI_ORGANIZATION)% ' )
37+ ->info ('' );
38+ $ children
39+ ->scalarNode ('project ' )
40+ ->defaultNull ()
41+ ->info ('OpenAI API project ' );
42+ $ children
43+ ->scalarNode ('base_uri ' )
44+ ->defaultNull ()
45+ ->info ('OpenAI API base URL used to make requests. Defaults to: api.openai.com/v1 ' );
3046 }
3147
3248 /**
33- * @param array{api_key: string, organization: string} $config
49+ * @param array{api_key: string, organization: string, project: ?string, base_uri: ?string } $config
3450 */
3551 public function loadExtension (array $ config , ContainerConfigurator $ container , ContainerBuilder $ builder ): void
3652 {
3753 $ container ->services ()
3854 ->set ('openai.http_client ' , Psr18Client::class)
39- ->arg (0 , service ('http_client ' ))
55+ ->arg (0 , service ('http_client ' ));
4056
57+ $ factory = $ container ->services ()
4158 ->set (Factory::class)
4259 ->factory ([\OpenAI::class, 'factory ' ])
4360 ->call ('withHttpClient ' , [service ('openai.http_client ' )])
4461 ->call ('withHttpHeader ' , ['OpenAI-Beta ' , 'assistants=v2 ' ])
4562 ->call ('withApiKey ' , [$ config ['api_key ' ]])
46- ->call ('withOrganization ' , [$ config ['organization ' ]])
63+ ->call ('withOrganization ' , [$ config ['organization ' ]]);
64+ if ($ config ['project ' ]) {
65+ $ factory ->call ('withProject ' , [$ config ['project ' ]]);
66+ }
67+ if ($ config ['base_uri ' ]) {
68+ $ factory ->call ('withBaseUri ' , [$ config ['base_uri ' ]]);
69+ }
4770
71+ $ container ->services ()
4872 ->set (Client::class)
49- ->factory ([service (Factory::class), 'make ' ])
73+ ->factory ([service (Factory::class), 'make ' ]);
5074
75+ $ container ->services ()
5176 ->alias (ClientContract::class, Client::class)
5277 ->alias ('openai ' , Client::class);
5378 }
0 commit comments