-
Notifications
You must be signed in to change notification settings - Fork 4
/
Groq.php
67 lines (61 loc) · 2.18 KB
/
Groq.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
<?php
declare(strict_types=1);
namespace AdrienBrault\Instructrice\LLM\Provider;
use AdrienBrault\Instructrice\LLM\Cost;
use AdrienBrault\Instructrice\LLM\LLMConfig;
enum Groq: string implements ProviderModel
{
case MIXTRAL_8x7B = 'mixtral-8x7b-32768';
case GEMMA_7B = 'gemma-7b-it';
case LLAMA3_8B = 'llama3-8b-8192';
case LLAMA3_70B = 'llama3-70b-8192';
case LLAMA31_8B = 'llama-3.1-8b-instant';
case LLAMA31_70B = 'llama-3.1-70b-versatile';
case LLAMA31_405B = 'llama-3.1-405b-reasoning';
public function getApiKeyEnvVar(): ?string
{
return 'GROQ_API_KEY';
}
public function createConfig(string $apiKey): LLMConfig
{
return new LLMConfig(
'https://api.groq.com/openai/v1/chat/completions',
$this->value,
match ($this) {
self::MIXTRAL_8x7B => 32768,
self::LLAMA31_8B, self::LLAMA31_70B, self::LLAMA31_405B => 128000,
default => 8192,
},
match ($this) {
self::MIXTRAL_8x7B => 'Mixtral 8x7B',
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',
self::LLAMA31_405B => 'Llama 3.1 405B',
},
'Groq',
Cost::create(match ($this) {
self::MIXTRAL_8x7B => 0.27,
self::GEMMA_7B => 0.1,
self::LLAMA3_8B => 0.1,
self::LLAMA3_70B => 0.8,
self::LLAMA31_8B => 0.1, // guess
self::LLAMA31_70B => 0.8, // guess
self::LLAMA31_405B => 0.8, // guess
}),
maxTokens: match ($this) {
self::LLAMA31_8B, self::LLAMA31_70B, self::LLAMA31_405B => 8000,
default => null,
},
strategy: match ($this) {
default => null,
},
headers: [
'Authorization' => 'Bearer ' . $apiKey,
],
docUrl: 'https://console.groq.com/docs/models',
);
}
}