-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXAI.php
More file actions
84 lines (76 loc) · 1.67 KB
/
XAI.php
File metadata and controls
84 lines (76 loc) · 1.67 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
<?php
namespace Utopia\Agents\Adapters;
class XAI extends OpenAI
{
/**
* Default XAI API endpoint
*/
protected const ENDPOINT = 'https://api.x.ai/v1/chat/completions';
/**
* Grok 2 Latest - Latest Grok model
*/
public const MODEL_GROK_2_LATEST = 'grok-2-latest';
/**
* Grok 2 Image - Latest Grok model with image support
*/
public const MODEL_GROK_2_IMAGE = 'grok-2-image';
/**
* Create a new XAI adapter
*
* @param string $apiKey
* @param string $model
* @param int $maxTokens
* @param float $temperature
* @param string|null $endpoint
* @param int $timeout
*
* @throws \Exception
*/
public function __construct(
string $apiKey,
string $model = self::MODEL_GROK_2_LATEST,
int $maxTokens = 1024,
float $temperature = 1.0,
?string $endpoint = null,
int $timeout = 90
) {
parent::__construct(
$apiKey,
$model,
$maxTokens,
$temperature,
$endpoint ?? self::ENDPOINT,
$timeout
);
}
/**
* Check if the model supports JSON schema
*
* @return bool
*/
public function isSchemaSupported(): bool
{
return false;
}
/**
* Get available models
*
* @return array<string>
*/
public function getModels(): array
{
return [
self::MODEL_GROK_2_LATEST,
self::MODEL_GROK_2_IMAGE,
];
}
/**
* Get the adapter name
*
* @return string
*/
public function getName(): string
{
return 'xai';
}
}