forked from laravel/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentAttributeTest.php
More file actions
91 lines (69 loc) · 3.17 KB
/
Copy pathAgentAttributeTest.php
File metadata and controls
91 lines (69 loc) · 3.17 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
85
86
87
88
89
90
91
<?php
use Laravel\Ai\Enums\Lab;
use Laravel\Ai\Gateway\TextGenerationOptions;
use Laravel\Ai\Prompts\AgentPrompt;
use Tests\Fixtures\Agents\AssistantAgent;
use Tests\Fixtures\Agents\AttributeAgent;
use Tests\Fixtures\Agents\IncompatibleMethodsAgent;
use Tests\Fixtures\Agents\MethodOptionsAgent;
use Tests\Fixtures\Agents\MethodOverridesAttributeAgent;
use Tests\Fixtures\Agents\NullableMethodOptionsAgent;
use Tests\Fixtures\Agents\ReasoningDisabledAgent;
use Tests\Fixtures\Agents\ReasoningMethodAgent;
test('text generation options can be created from agent attributes', function () {
$options = TextGenerationOptions::forAgent(new AttributeAgent);
expect($options->maxSteps)->toBe(10)
->and($options->maxTokens)->toBe(4096)
->and($options->temperature)->toBe(0.7)
->and($options->topP)->toBe(0.8);
});
test('text generation options are null when agent has no attributes', function () {
$options = TextGenerationOptions::forAgent(new AssistantAgent);
expect($options->maxSteps)->toBeNull()
->and($options->maxTokens)->toBeNull()
->and($options->temperature)->toBeNull()
->and($options->topP)->toBeNull();
});
test('text generation options can be resolved from agent methods', function () {
$options = TextGenerationOptions::forAgent(new MethodOptionsAgent);
expect($options->maxSteps)->toBe(3)
->and($options->maxTokens)->toBe(2048)
->and($options->temperature)->toBe(0.5);
});
test('agent methods take priority over attributes', function () {
$options = TextGenerationOptions::forAgent(new MethodOverridesAttributeAgent);
expect($options->maxSteps)->toBe(1)
->and($options->maxTokens)->toBe(512)
->and($options->temperature)->toBe(0.2);
});
test('null return from agent method falls back to attributes', function () {
$options = TextGenerationOptions::forAgent(new NullableMethodOptionsAgent);
expect($options->maxSteps)->toBe(10)
->and($options->maxTokens)->toBe(4096)
->and($options->temperature)->toBe(0.7);
});
test('non-public or parameterized option methods are ignored', function () {
$options = TextGenerationOptions::forAgent(new IncompatibleMethodsAgent);
expect($options->maxSteps)->toBe(8)
->and($options->maxTokens)->toBe(1024)
->and($options->temperature)->toBe(0.9);
});
test('reasoning attribute is read from agent class', function () {
$options = TextGenerationOptions::forAgent(new ReasoningDisabledAgent);
expect($options->reasoning)->toBeFalse();
});
test('reasoning method takes priority over attribute', function () {
$options = TextGenerationOptions::forAgent(new ReasoningMethodAgent);
expect($options->reasoning)->toBeFalse();
});
test('reasoning is null when neither attribute nor method is provided', function () {
$options = TextGenerationOptions::forAgent(new AssistantAgent);
expect($options->reasoning)->toBeNull();
});
test('provider attribute is used when prompting', function () {
AttributeAgent::fake();
(new AttributeAgent)->prompt('Hello');
AttributeAgent::assertPrompted(function (AgentPrompt $prompt) {
return $prompt->provider->name() === Lab::Anthropic->value;
});
});