-
Notifications
You must be signed in to change notification settings - Fork 4
/
DeepInfra.php
73 lines (67 loc) · 2.7 KB
/
DeepInfra.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
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
<?php
declare(strict_types=1);
namespace AdrienBrault\Instructrice\LLM\Provider;
use AdrienBrault\Instructrice\LLM\Cost;
use AdrienBrault\Instructrice\LLM\LLMConfig;
use AdrienBrault\Instructrice\LLM\OpenAiJsonStrategy;
enum DeepInfra: string implements ProviderModel
{
case MIXTRAL_22 = 'mistralai/Mixtral-8x22B-Instruct-v0.1';
case WIZARDLM2_22 = 'microsoft/WizardLM-2-8x22B';
case WIZARDLM2_7 = 'microsoft/WizardLM-2-7B';
case DBRX = 'databricks/dbrx-instruct';
case GEMMA_7B = 'google/gemma-1.1-7b-it';
case LLAMA3_8B = 'meta-llama/Meta-Llama-3-8B-Instruct';
case LLAMA3_70B = 'meta-llama/Meta-Llama-3-70B-Instruct';
case LLAMA31_8B = 'meta-llama/Meta-Llama-3.1-8B-Instruct';
case LLAMA31_70B = 'meta-llama/Meta-Llama-3.1-70B-Instruct';
public function getApiKeyEnvVar(): ?string
{
return 'DEEPINFRA_API_KEY';
}
public function createConfig(string $apiKey): LLMConfig
{
return new LLMConfig(
'https://api.deepinfra.com/v1/openai/chat/completions',
$this->value,
match ($this) {
self::MIXTRAL_22 => 64000,
self::WIZARDLM2_22 => 64000,
self::WIZARDLM2_7 => 32000,
self::DBRX => 32000,
self::LLAMA3_8B, self::LLAMA3_70B, self::GEMMA_7B => 8000,
self::LLAMA31_8B, self::LLAMA31_70B => 8000,
},
match ($this) {
self::MIXTRAL_22 => 'Mixtral 8x22B',
self::WIZARDLM2_22 => 'WizardLM 2 8x22B',
self::WIZARDLM2_7 => 'WizardLM 2 7B',
self::DBRX => 'DBRX',
self::GEMMA_7B => 'Gemma 7B',
self::LLAMA3_8B => 'Llama3 8B',
self::LLAMA3_70B => 'Llama3 70B',
self::LLAMA31_8B => 'Llama 3.1 8B',
self::LLAMA31_70B => 'Llama 3.1 70B',
},
'DeepInfra',
match ($this) {
self::MIXTRAL_22 => Cost::create(0.65),
self::WIZARDLM2_22 => Cost::create(0.65),
self::WIZARDLM2_7 => Cost::create(0.1),
self::DBRX => Cost::create(0.6),
self::GEMMA_7B => Cost::create(0.1),
self::LLAMA3_8B => Cost::create(0.1),
self::LLAMA3_70B => new Cost(0.59, 0.79),
self::LLAMA31_8B => Cost::create(0.09),
self::LLAMA31_70B => new Cost(0.52, 0.75),
},
match ($this) {
default => OpenAiJsonStrategy::JSON_WITH_SCHEMA,
},
headers: [
'Authorization' => 'Bearer ' . $apiKey,
],
docUrl: 'https://deepinfra.com/' . $this->value
);
}
}