Skip to content

Commit 5fa62fc

Browse files
authored
Merge pull request #9 from utopia-php/chore-update-openai-list
chore: update openai model list
2 parents 1f0f38e + be4e01a commit 5fa62fc

4 files changed

Lines changed: 48 additions & 16 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ $openai = new OpenAI(
7070
```
7171

7272
Available OpenAI Models:
73-
- `MODEL_GPT_4_TURBO`: Latest GPT-4 Turbo
74-
- `MODEL_GPT_4`: Standard GPT-4
75-
- `MODEL_GPT_3_5_TURBO`: Fast GPT-3.5 Turbo
73+
- `MODEL_GPT_4_5_PREVIEW`: GPT-4.5 Preview - OpenAI's most advanced model with enhanced reasoning, broader knowledge, and improved instruction following
74+
- `MODEL_GPT_4_1`: GPT-4.1 - Advanced large language model with strong reasoning capabilities and improved context handling
75+
- `MODEL_GPT_4O`: GPT-4o - Multimodal model optimized for both text and image processing with faster response times
76+
- `MODEL_O4_MINI`: o4-mini - Compact version of GPT-4o offering good performance with higher throughput and lower latency
77+
- `MODEL_O3`: o3 - Balanced model offering good performance for general language tasks with efficient resource usage
78+
- `MODEL_O3_MINI`: o3-mini - Streamlined model optimized for speed and efficiency while maintaining good capabilities for routine tasks
7679

7780
#### Anthropic
7881

src/Agents/Adapters/OpenAI.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,34 @@
1111
class OpenAI extends Adapter
1212
{
1313
/**
14-
* GPT-4 Turbo - Latest and most capable model
14+
* GPT-4.5 Preview - OpenAI's most advanced model with enhanced reasoning, broader knowledge, and improved instruction following
1515
*/
16-
public const MODEL_GPT_4_TURBO = 'gpt-4-turbo-preview';
16+
public const MODEL_GPT_4_5_PREVIEW = 'gpt-4.5-preview';
1717

1818
/**
19-
* GPT-4 - Previous generation model
19+
* GPT-4.1 - Advanced large language model with strong reasoning capabilities and improved context handling
2020
*/
21-
public const MODEL_GPT_4 = 'gpt-4';
21+
public const MODEL_GPT_4_1 = 'gpt-4.1';
2222

2323
/**
24-
* GPT-3.5 Turbo - Fast and efficient model
24+
* GPT-4o - Multimodal model optimized for both text and image processing with faster response times
2525
*/
26-
public const MODEL_GPT_3_5_TURBO = 'gpt-3.5-turbo';
26+
public const MODEL_GPT_4O = 'gpt-4o';
27+
28+
/**
29+
* o4-mini - Compact version of GPT-4o offering good performance with higher throughput and lower latency
30+
*/
31+
public const MODEL_O4_MINI = 'o4-mini';
32+
33+
/**
34+
* o3 - Balanced model offering good performance for general language tasks with efficient resource usage
35+
*/
36+
public const MODEL_O3 = 'o3';
37+
38+
/**
39+
* o3-mini - Streamlined model optimized for speed and efficiency while maintaining good capabilities for routine tasks
40+
*/
41+
public const MODEL_O3_MINI = 'o3-mini';
2742

2843
/**
2944
* Default OpenAI API endpoint
@@ -74,7 +89,7 @@ class OpenAI extends Adapter
7489
*/
7590
public function __construct(
7691
string $apiKey,
77-
string $model = self::MODEL_GPT_3_5_TURBO,
92+
string $model = self::MODEL_O3_MINI,
7893
int $maxTokens = 1024,
7994
float $temperature = 1.0,
8095
?string $endpoint = null,
@@ -138,11 +153,22 @@ public function send(array $messages, ?callable $listener = null): Message
138153
$payload = [
139154
'model' => $this->model,
140155
'messages' => $formattedMessages,
141-
'max_tokens' => $this->maxTokens,
142156
'temperature' => $this->temperature,
143157
'stream' => true,
144158
];
145159

160+
// Use 'max_completion_tokens' for o-series models, else 'max_tokens'
161+
$oSeriesModels = [
162+
self::MODEL_O3,
163+
self::MODEL_O3_MINI,
164+
self::MODEL_O4_MINI,
165+
];
166+
if (in_array($this->model, $oSeriesModels)) {
167+
$payload['max_completion_tokens'] = $this->maxTokens;
168+
} else {
169+
$payload['max_tokens'] = $this->maxTokens;
170+
}
171+
146172
$content = '';
147173
$response = $client->fetch(
148174
$this->endpoint,
@@ -230,9 +256,12 @@ protected function process(Chunk $chunk, ?callable $listener): string
230256
public function getModels(): array
231257
{
232258
return [
233-
self::MODEL_GPT_4_TURBO,
234-
self::MODEL_GPT_4,
235-
self::MODEL_GPT_3_5_TURBO,
259+
self::MODEL_GPT_4_5_PREVIEW,
260+
self::MODEL_GPT_4_1,
261+
self::MODEL_GPT_4O,
262+
self::MODEL_O4_MINI,
263+
self::MODEL_O3,
264+
self::MODEL_O3_MINI,
236265
];
237266
}
238267

tests/Agents/AgentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AgentTest extends TestCase
1616
protected function setUp(): void
1717
{
1818
// Create a mock adapter
19-
$this->mockAdapter = new OpenAI('test-api-key', OpenAI::MODEL_GPT_3_5_TURBO);
19+
$this->mockAdapter = new OpenAI('test-api-key', OpenAI::MODEL_O3_MINI);
2020
$this->agent = new Agent($this->mockAdapter);
2121
}
2222

tests/Agents/Conversation/ConversationOpenAITest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function createAdapter(): Adapter
1717

1818
return new OpenAI(
1919
$apiKey,
20-
OpenAI::MODEL_GPT_4,
20+
OpenAI::MODEL_O3_MINI,
2121
1024,
2222
1.0
2323
);

0 commit comments

Comments
 (0)