/
ServiceProvider.php
40 lines (31 loc) · 1.07 KB
/
ServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Zemit\Provider\OpenAi;
use Orhanerday\OpenAi\OpenAi;
use Phalcon\Di\DiInterface;
use Zemit\Bootstrap\Config;
use Zemit\Provider\AbstractServiceProvider;
class ServiceProvider extends AbstractServiceProvider
{
protected string $serviceName = 'openAi';
public function register(DiInterface $di): void
{
$di->setShared($this->getName(), function () use ($di) {
$config = $di->get('config');
assert($config instanceof Config);
$openAiConfig = $config->pathToArray('openai') ?? [];
$openAi = new OpenAi($openAiConfig['secretKey'] ?? null);
if (!empty($openAiConfig['organizationId'])) {
$openAi->setORG($openAiConfig['organizationId']);
}
return $openAi;
});
}
}