Skip to content

Commit 8a1e7c1

Browse files
authored
Merge pull request #12 from utopia-php/chore-update-model-check
chore: remove supported models check, add sonnet 4
2 parents 915b26a + 8ba6877 commit 8a1e7c1

7 files changed

Lines changed: 38 additions & 43 deletions

File tree

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@ use Utopia\Agents\Adapters\Anthropic;
8484

8585
$anthropic = new Anthropic(
8686
apiKey: 'your-api-key',
87-
model: Anthropic::MODEL_CLAUDE_3_SONNET,
87+
model: Anthropic::MODEL_CLAUDE_3_HAIKU,
8888
maxTokens: 2048,
8989
temperature: 0.7
9090
);
9191
```
9292

9393
Available Anthropic Models:
94-
- `MODEL_CLAUDE_3_OPUS`: Most powerful model
95-
- `MODEL_CLAUDE_3_SONNET`: Balanced performance
96-
- `MODEL_CLAUDE_3_HAIKU`: Fast and efficient
97-
- `MODEL_CLAUDE_2_1`: Previous generation
94+
- `MODEL_CLAUDE_4_OPUS`: Flagship model with exceptional reasoning for the most demanding tasks
95+
- `MODEL_CLAUDE_3_OPUS`: Premium model with superior performance on complex analysis and creative work
96+
- `MODEL_CLAUDE_4_SONNET`: Intelligent and responsive model optimized for productivity workflows
97+
- `MODEL_CLAUDE_3_7_SONNET`: Enhanced model with improved reasoning and coding capabilities
98+
- `MODEL_CLAUDE_3_5_SONNET`: Versatile model balancing capability and speed for general use
99+
- `MODEL_CLAUDE_3_5_HAIKU`: Ultra-fast model for quick responses and lightweight processing
100+
- `MODEL_CLAUDE_3_HAIKU`: Rapid model designed for speed and efficiency on straightforward tasks
98101

99102
#### Deepseek
100103

src/Agents/Adapter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ abstract public function getModel(): string;
8383
*
8484
* @param string $model
8585
* @return self
86-
*
87-
* @throws \Exception if model is not supported
8886
*/
8987
abstract public function setModel(string $model): self;
9088

src/Agents/Adapters/Anthropic.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,39 @@
1212
class Anthropic extends Adapter
1313
{
1414
/**
15-
* Claude 3 Opus - Most powerful model for highly complex tasks
15+
* Claude 4 Opus - Flagship model with exceptional reasoning for the most demanding tasks
1616
*/
17-
public const MODEL_CLAUDE_3_OPUS = 'claude-3-opus-20240229';
17+
public const MODEL_CLAUDE_4_OPUS = 'claude-opus-4-0';
1818

1919
/**
20-
* Claude 3 Sonnet - Ideal balance of intelligence and speed
20+
* Claude 3 Opus - Premium model with superior performance on complex analysis and creative work
2121
*/
22-
public const MODEL_CLAUDE_3_SONNET = 'claude-3-7-sonnet-20250219';
22+
public const MODEL_CLAUDE_3_OPUS = 'claude-3-opus-latest';
2323

2424
/**
25-
* Claude 3 Haiku - Fastest and most compact model
25+
* Claude 4 Sonnet - Intelligent and responsive model optimized for productivity workflows
2626
*/
27-
public const MODEL_CLAUDE_3_HAIKU = 'claude-3-haiku-20240229';
27+
public const MODEL_CLAUDE_4_SONNET = 'claude-sonnet-4-0';
2828

2929
/**
30-
* Claude 2.1 - Previous generation model
30+
* Claude 3.7 Sonnet - Enhanced model with improved reasoning and coding capabilities
3131
*/
32-
public const MODEL_CLAUDE_2_1 = 'claude-2.1';
32+
public const MODEL_CLAUDE_3_7_SONNET = 'claude-3-7-sonnet-latest';
33+
34+
/**
35+
* Claude 3.5 Sonnet - Versatile model balancing capability and speed for general use
36+
*/
37+
public const MODEL_CLAUDE_3_5_SONNET = 'claude-3-5-sonnet-latest';
38+
39+
/**
40+
* Claude 3.5 Haiku - Ultra-fast model for quick responses and lightweight processing
41+
*/
42+
public const MODEL_CLAUDE_3_5_HAIKU = 'claude-3-5-haiku-latest';
43+
44+
/**
45+
* Claude 3 Haiku - Rapid model designed for speed and efficiency on straightforward tasks
46+
*/
47+
public const MODEL_CLAUDE_3_HAIKU = 'claude-3-haiku-20240307';
3348

3449
/**
3550
* Cache TTL for 3600 seconds
@@ -74,7 +89,7 @@ class Anthropic extends Adapter
7489
*/
7590
public function __construct(
7691
string $apiKey,
77-
string $model = self::MODEL_CLAUDE_3_SONNET,
92+
string $model = self::MODEL_CLAUDE_3_HAIKU,
7893
int $maxTokens = 1024,
7994
float $temperature = 1.0,
8095
int $timeout = 90
@@ -356,10 +371,13 @@ protected function process(Chunk $chunk, ?callable $listener): string
356371
public function getModels(): array
357372
{
358373
return [
374+
self::MODEL_CLAUDE_4_OPUS,
359375
self::MODEL_CLAUDE_3_OPUS,
360-
self::MODEL_CLAUDE_3_SONNET,
376+
self::MODEL_CLAUDE_4_SONNET,
377+
self::MODEL_CLAUDE_3_7_SONNET,
378+
self::MODEL_CLAUDE_3_5_SONNET,
379+
self::MODEL_CLAUDE_3_5_HAIKU,
361380
self::MODEL_CLAUDE_3_HAIKU,
362-
self::MODEL_CLAUDE_2_1,
363381
];
364382
}
365383

@@ -378,15 +396,9 @@ public function getModel(): string
378396
*
379397
* @param string $model
380398
* @return self
381-
*
382-
* @throws \Exception
383399
*/
384400
public function setModel(string $model): self
385401
{
386-
if (! in_array($model, $this->getModels())) {
387-
throw new \Exception('Unsupported model: '.$model);
388-
}
389-
390402
$this->model = $model;
391403

392404
return $this;

src/Agents/Adapters/Deepseek.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,9 @@ public function getModel(): string
259259
*
260260
* @param string $model
261261
* @return self
262-
*
263-
* @throws \Exception
264262
*/
265263
public function setModel(string $model): self
266264
{
267-
if (! in_array($model, $this->getModels())) {
268-
throw new \Exception('Unsupported model: '.$model);
269-
}
270-
271265
$this->model = $model;
272266

273267
return $this;

src/Agents/Adapters/Gemini.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,9 @@ public function getModel(): string
268268
*
269269
* @param string $model
270270
* @return self
271-
*
272-
* @throws \Exception
273271
*/
274272
public function setModel(string $model): self
275273
{
276-
if (! in_array($model, $this->getModels())) {
277-
throw new \Exception('Unsupported model: '.$model);
278-
}
279-
280274
$this->model = $model;
281275

282276
return $this;

src/Agents/Adapters/OpenAI.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,15 +324,9 @@ public function getModel(): string
324324
*
325325
* @param string $model
326326
* @return self
327-
*
328-
* @throws \Exception
329327
*/
330328
public function setModel(string $model): self
331329
{
332-
if (! in_array($model, $this->getModels())) {
333-
throw new \Exception('Unsupported model: '.$model);
334-
}
335-
336330
$this->model = $model;
337331

338332
return $this;

tests/Agents/Conversation/ConversationAnthropicTest.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 Anthropic(
1919
$apiKey,
20-
Anthropic::MODEL_CLAUDE_3_SONNET,
20+
Anthropic::MODEL_CLAUDE_3_HAIKU,
2121
1024,
2222
1.0
2323
);

0 commit comments

Comments
 (0)