-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.php
More file actions
85 lines (77 loc) · 2.88 KB
/
Copy pathFactory.php
File metadata and controls
85 lines (77 loc) · 2.88 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\AI\Platform\Bridge\Venice;
use Symfony\AI\Platform\Bridge\Venice\Contract\VeniceContract;
use Symfony\AI\Platform\Contract;
use Symfony\AI\Platform\ModelRouter\CatalogBasedModelRouter;
use Symfony\AI\Platform\ModelRouterInterface;
use Symfony\AI\Platform\Platform;
use Symfony\AI\Platform\PlatformInterface;
use Symfony\AI\Platform\Provider;
use Symfony\AI\Platform\ProviderInterface;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\Clock\MonotonicClock;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Component\HttpClient\ScopingHttpClient;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
/**
* @author Guillaume Loulier <personal@guillaumeloulier.fr>
*/
final class Factory
{
/**
* @param non-empty-string $name
*/
public static function createProvider(
string $endpoint = 'https://api.venice.ai/api/v1/',
#[\SensitiveParameter] ?string $apiKey = null,
?HttpClientInterface $httpClient = null,
?ClockInterface $clock = null,
?Contract $contract = null,
?EventDispatcherInterface $eventDispatcher = null,
string $name = 'venice',
): ProviderInterface {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
$httpClient = ScopingHttpClient::forBaseUri($httpClient, $endpoint);
if (null !== $apiKey) {
$httpClient = ScopingHttpClient::forBaseUri($httpClient, $endpoint, [
'auth_bearer' => $apiKey,
]);
}
return new Provider(
$name,
[new VeniceClient($httpClient, $clock ?? new MonotonicClock())],
[new VeniceResultConverter()],
new ModelCatalog($httpClient),
$contract ?? VeniceContract::create(),
$eventDispatcher,
);
}
/**
* @param non-empty-string $name
*/
public static function createPlatform(
#[\SensitiveParameter] ?string $apiKey = null,
string $endpoint = 'https://api.venice.ai/api/v1/',
?HttpClientInterface $httpClient = null,
?ClockInterface $clock = null,
?Contract $contract = null,
?EventDispatcherInterface $eventDispatcher = null,
string $name = 'venice',
?ModelRouterInterface $modelRouter = null,
): PlatformInterface {
return new Platform(
[self::createProvider($endpoint, $apiKey, $httpClient, $clock, $contract, $eventDispatcher, $name)],
$modelRouter ?? new CatalogBasedModelRouter(),
$eventDispatcher,
);
}
}