-
-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathStructuredModeResolver.php
More file actions
69 lines (59 loc) · 1.68 KB
/
Copy pathStructuredModeResolver.php
File metadata and controls
69 lines (59 loc) · 1.68 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
<?php
declare(strict_types=1);
namespace Prism\Prism\Providers\OpenAI\Support;
use Prism\Prism\Enums\StructuredMode;
use Prism\Prism\Exceptions\PrismException;
class StructuredModeResolver
{
public static function forModel(string $model): StructuredMode
{
if (self::unsupported($model)) {
throw new PrismException(sprintf('Structured output is not supported for %s', $model));
}
if (self::supportsStructuredMode($model)) {
return StructuredMode::Structured;
}
return StructuredMode::Json;
}
protected static function supportsStructuredMode(string $model): bool
{
return in_array($model, [
'gpt-4o-mini',
'gpt-4o-mini-2024-07-18',
'gpt-4o-2024-08-06',
'gpt-4o',
'chatgpt-4o-latest',
'o3-mini',
'o3-mini-2025-01-31',
'gpt-4.1',
'gpt-4.1-nano',
'gpt-4.1-mini',
'gpt-4.5-preview',
'gpt-4.5-preview-2025-02-27',
'gpt-5',
'gpt-5-mini',
'gpt-5-nano',
'gpt-5.1',
'gpt-5.2',
'gpt-5.4',
'gpt-5.4-mini',
'gpt-5.4-nano',
]);
}
protected static function supportsJsonMode(string $model): bool
{
if (preg_match('/^gpt-4-.*/', $model)) {
return true;
}
return $model === 'gpt-3.5-turbo';
}
protected static function unsupported(string $model): bool
{
return in_array($model, [
'o1-mini',
'o1-mini-2024-09-12',
'o1-preview',
'o1-preview-2024-09-12',
]);
}
}