-
-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathGeminiTextTest.php
More file actions
634 lines (516 loc) · 27.3 KB
/
Copy pathGeminiTextTest.php
File metadata and controls
634 lines (516 loc) · 27.3 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
<?php
declare(strict_types=1);
namespace Tests\Providers\Gemini;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Prism\Prism\Enums\Citations\CitationSourceType;
use Prism\Prism\Enums\FinishReason;
use Prism\Prism\Enums\Provider;
use Prism\Prism\Exceptions\PrismException;
use Prism\Prism\Facades\Prism;
use Prism\Prism\Schema\ArraySchema;
use Prism\Prism\Schema\BooleanSchema;
use Prism\Prism\Schema\NumberSchema;
use Prism\Prism\Schema\StringSchema;
use Prism\Prism\Testing\TextStepFake;
use Prism\Prism\Text\ResponseBuilder;
use Prism\Prism\Tool;
use Prism\Prism\ValueObjects\Media\Document;
use Prism\Prism\ValueObjects\Media\Image;
use Prism\Prism\ValueObjects\MessagePartWithCitations;
use Prism\Prism\ValueObjects\Messages\AssistantMessage;
use Prism\Prism\ValueObjects\Messages\SystemMessage;
use Prism\Prism\ValueObjects\Messages\ToolResultMessage;
use Prism\Prism\ValueObjects\Messages\UserMessage;
use Prism\Prism\ValueObjects\ProviderTool;
use Tests\Fixtures\FixtureResponse;
beforeEach(function (): void {
config()->set('prism.providers.gemini.api_key', env('GEMINI_API_KEY', 'sss-1234567890'));
});
describe('Text generation for Gemini', function (): void {
it('can generate text with a prompt', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-a-prompt');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withPrompt('Who are you?')
->withMaxTokens(10)
->asText();
expect($response->text)->toBe(
"I am a large language model, trained by Google. I am an AI, and I don't have a name, feelings, or personal experiences. My purpose is to process information and respond to a wide range of prompts and questions in a helpful and informative way.\n"
)
->and($response->usage->promptTokens)->toBe(4)
->and($response->usage->completionTokens)->toBe(57)
->and($response->meta->id)->toBe('')
->and($response->meta->model)->toBe('gemini-1.5-flash')
->and($response->finishReason)->toBe(FinishReason::Stop);
});
it('can generate text with a system prompt', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-system-prompt');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withSystemPrompt('You are a helpful AI assistant named Prism generated by echolabs')
->withPrompt('Who are you?')
->asText();
expect($response->text)->toBe('I am Prism, a helpful AI assistant created by echo labs.')
->and($response->usage->promptTokens)->toBe(17)
->and($response->usage->completionTokens)->toBe(14)
->and($response->meta->id)->toBe('')
->and($response->meta->model)->toBe('gemini-1.5-flash')
->and($response->finishReason)->toBe(FinishReason::Stop);
});
it('can generate text using multiple tools and multiple steps', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-multiple-tools');
$tools = [
(new Tool)
->as('get_weather')
->for('use this tool when you need to get weather for the city')
->withStringParameter('city', 'The city that you want the weather for')
->using(fn (string $city): string => 'The weather will be 45° and cold'),
(new Tool)
->as('search_games')
->for('useful for searching current games times in the city')
->withStringParameter('city', 'The city that you want the game times for')
->using(fn (string $city): string => 'The tigers game is at 3pm in detroit'),
];
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withTools($tools)
->withMaxSteps(5)
->withPrompt('What time is the tigers game today in Detroit and should I wear a coat? please check all the details from tools')
->asText();
// Assert tool calls in the first step
$firstStep = $response->steps[0];
expect($firstStep->toolCalls)->toHaveCount(2);
expect($firstStep->toolCalls[0]->name)->toBe('search_games');
expect($firstStep->toolCalls[0]->arguments())->toBe([
'city' => 'Detroit',
]);
expect($firstStep->toolCalls[1]->name)->toBe('get_weather');
expect($firstStep->toolCalls[1]->arguments())->toBe([
'city' => 'Detroit',
]);
// Verify the assistant message from step 1 is present in step 2's input messages
$secondStep = $response->steps[1];
expect($secondStep->messages)->toHaveCount(3);
expect($secondStep->messages[0])->toBeInstanceOf(UserMessage::class);
expect($secondStep->messages[1])->toBeInstanceOf(AssistantMessage::class);
expect($secondStep->messages[1]->toolCalls)->toHaveCount(2);
expect($secondStep->messages[1]->toolCalls[0]->name)->toBe('search_games');
expect($secondStep->messages[1]->toolCalls[1]->name)->toBe('get_weather');
expect($secondStep->messages[2])->toBeInstanceOf(ToolResultMessage::class);
// Assert usage (combined from both responses)
expect($response->usage->promptTokens)->toBe(350)
->and($response->usage->completionTokens)->toBe(42);
// Assert response
expect($response->meta->id)->toBe('')
->and($response->meta->model)->toBe('gemini-1.5-flash')
->and($response->text)->toBe('The tigers game is at 3pm today in Detroit. The weather will be 45° and cold, so you should wear a coat.');
});
it('handles specific tool choice', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-required-tool-call');
$tools = [
(new Tool)
->as('weather')
->for('useful when you need to search for current weather conditions')
->withStringParameter('city', 'The city that you want the weather for')
->withObjectParameter(
'options',
'Additional options for the weather tool',
[
new StringSchema('unit', 'The unit of temperature (Celsius or Fahrenheit)'),
new BooleanSchema('decimals', 'Whether to include decimals in the temperature'),
new NumberSchema('days', 'Number of days into the future to forecast'),
new ArraySchema(
'alerts',
'Weather alerts to include in the response',
items: new StringSchema('alert', 'A specific type of weather alert to include (e.g. flooding, tornado, etc.)'),
nullable: true
),
]
)
->using(fn (string $city, array $options): string => 'The weather will be 75° and sunny'),
(new Tool)
->as('search')
->for('useful for searching curret events or data')
->withStringParameter('query', 'The detailed search query')
->using(fn (string $query): string => 'The tigers game is at 3pm in detroit'),
];
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withPrompt('When is the Tigers game today, and what will the weather be like?')
->withTools($tools)
->withToolChoice('weather')
->asText();
expect($response->steps[0]->toolCalls[0]->name)->toBe('weather');
});
});
describe('Image support with Gemini', function (): void {
it('can send images from path', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/image-detection');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withMessages([
new UserMessage(
'What is this image',
additionalContent: [
Image::fromLocalPath('tests/Fixtures/diamond.png'),
],
),
])
->asText();
// Assert response
expect($response->text)->toBe("That's an illustration of a **diamond**. More specifically, it's a stylized, geometric representation of a diamond, often used as an icon or symbol")
->and($response->usage->promptTokens)->toBe(263)
->and($response->usage->completionTokens)->toBe(35)
->and($response->meta->id)->toBe('')
->and($response->meta->model)->toBe('gemini-1.5-flash')
->and($response->finishReason)->toBe(FinishReason::Stop);
// Assert request format
Http::assertSent(function (Request $request): bool {
$message = $request->data()['contents'][0]['parts'];
expect($message[0])->toBe([
'text' => 'What is this image',
]);
expect($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data']);
expect($message[1]['inline_data']['mime_type'])->toBe('image/png');
expect($message[1]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/diamond.png'))
);
return true;
});
});
it('can send images from base64', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/image-detection');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withMessages([
new UserMessage(
'What is this image',
additionalContent: [
Image::fromBase64(
base64_encode(file_get_contents('tests/Fixtures/diamond.png')),
'image/png'
),
],
),
])
->asText();
Http::assertSent(function (Request $request): bool {
$message = $request->data()['contents'][0]['parts'];
expect($message[0])->toBe([
'text' => 'What is this image',
]);
expect($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data']);
expect($message[1]['inline_data']['mime_type'])->toBe('image/png');
expect($message[1]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/diamond.png'))
);
return true;
});
});
it('can send images from url', function (): void {
FixtureResponse::fakeResponseSequence('generateContent', 'gemini/image-detection');
$image = 'https://prismphp.com/storage/diamond.png';
Http::fake([
$image => Http::response(
file_get_contents('tests/Fixtures/diamond.png'),
200,
['Content-Type' => 'image/png']
),
]);
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withMessages([
new UserMessage(
'What is this image',
additionalContent: [
Image::fromUrl($image),
],
),
])
->asText();
Http::assertSentInOrder([
fn (): true => true,
function (Request $request): bool {
$message = $request->data()['contents'][0]['parts'];
expect($message[0])->toBe([
'text' => 'What is this image',
]);
expect($message[1]['inline_data'])->toHaveKeys(['mime_type', 'data']);
expect($message[1]['inline_data']['mime_type'])->toBe('image/png');
expect($message[1]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/diamond.png'))
);
return true;
},
]);
});
});
describe('Document support for Gemini', function (): void {
it('can read process pdf documents', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/text-with-pdf-documents');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withMessages([
new UserMessage(
content: 'What is this document about?',
additionalContent: [
Document::fromBase64(base64_encode(file_get_contents('tests/Fixtures/test-pdf.pdf')), 'application/pdf'),
]
),
])
->asText();
expect($response->text)->toBe("The document is about the answer to the Ultimate Question of Life, the Universe, and Everything, which is stated to be 42. This is a reference to the science fiction series \"The Hitchhiker's Guide to the Galaxy\" by Douglas Adams.\n");
Http::assertSent(function (Request $request): bool {
$message = $request->data()['contents'][0]['parts'];
expect($message[1])->toBe([
'text' => 'What is this document about?',
]);
expect($message[0]['inline_data'])->toHaveKeys(['mime_type', 'data']);
expect($message[0]['inline_data']['mime_type'])->toBe('application/pdf');
expect($message[0]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/test-pdf.pdf'))
);
return true;
});
});
it('can read process text documents', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/text-with-text-documents');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withMessages([
new UserMessage(
content: 'What is this document about?',
additionalContent: [
Document::fromText(file_get_contents('tests/Fixtures/test-text.txt')),
]
),
])
->asText();
expect($response->text)->toBe("This document is about the number 42 and its significance, likely referencing the book \"The Hitchhiker's Guide to the Galaxy\" by Douglas Adams. In that book, a supercomputer called Deep Thought calculates that 42 is the answer to the Ultimate Question of Life, the Universe, and Everything. However, frustratingly, no one knows what the actual question *is*.\n\nTherefore, the document could be:\n\n* **An explanation of the concept of 42 within the context of *The Hitchhiker's Guide to the Galaxy***: This is the most likely scenario.\n* **A humorous exploration of possible interpretations of 42**: Playing on the ambiguity of the answer.\n* **A coincidence**: The document could be about something completely unrelated to the book, and the mention of 42 is just a bizarre coincidence. However, given the specific phrasing (\"The Answer to the Ultimate Question...\"), this is very unlikely.\n* **A piece of fan fiction or creative writing**: Using the 42 concept as a jumping-off point.\n\nIn short, it's almost certainly related to *The Hitchhiker's Guide to the Galaxy* and the significance of the number 42 within that fictional universe.\n");
Http::assertSent(function (Request $request): bool {
$message = $request->data()['contents'][0]['parts'];
expect($message[1])->toBe([
'text' => 'What is this document about?',
]);
expect($message[0]['inline_data'])->toHaveKeys(['mime_type', 'data']);
expect($message[0]['inline_data']['mime_type'])->toBe('text/plain');
expect($message[0]['inline_data']['data'])->toBe(
base64_encode(file_get_contents('tests/Fixtures/test-text.txt'))
);
return true;
});
});
});
describe('provider tools', function (): void {
it('adds a provider tool to the request', function (): void {
$fake = Prism::fake([
(new ResponseBuilder)
->addStep(
TextStepFake::make()
)
->toResponse(),
]);
Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withPrompt('What is the stock price of Google right now?')
->withProviderTools([new ProviderTool('google_search')])
->asText();
$fake->assertRequest(function (array $requests): void {
expect($requests[0]->providerTools())->toHaveCount(1);
expect($requests[0]->providerTools()[0])->toBeInstanceOf(ProviderTool::class);
expect($requests[0]->providerTools()[0]->type)->toBe('google_search');
});
});
it('adds provider tools if set', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-search-grounding');
Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withPrompt('What is the stock price of Google right now?')
->withProviderTools([new ProviderTool('google_search')])
->asText();
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['tools'][0])->toHaveKey('google_search');
expect($data['tools'][0]['google_search'])->toBeObject();
return true;
});
});
it('throws an exception if provider tools are enabled with other tools', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-search-grounding');
$tools = [
(new Tool)
->as('search_games')
->for('useful for searching current games times in the city')
->withStringParameter('city', 'The city that you want the game times for')
->using(fn (string $city): string => 'The tigers game is at 3pm in detroit'),
];
Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withMaxSteps(3)
->withTools($tools)
->withProviderTools([new ProviderTool('google_search')])
->withPrompt('What sport fixtures are on today, and will I need a coat based on today\'s weather forecast?')
->asText();
})->throws(PrismException::class, 'Use of provider tools with custom tools is not currently supported by Gemini.');
it('adds file_search provider tool with options to the request', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-file-search');
Prism::text()
->using(Provider::Gemini, 'gemini-2.5-flash')
->withPrompt('What are the main topics covered in the documents?')
->withProviderTools([
new ProviderTool(
type: 'file_search',
name: 'file_search',
options: [
'file_search_store_names' => ['fileSearchStores/prism-test-store-k48zypdei7oj'],
]
),
])
->asText();
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['tools'][0])->toHaveKey('file_search');
expect($data['tools'][0]['file_search'])->toBeArray();
expect($data['tools'][0]['file_search'])->toHaveKey('file_search_store_names');
expect($data['tools'][0]['file_search']['file_search_store_names'])->toBe(['fileSearchStores/prism-test-store-k48zypdei7oj']);
return true;
});
});
it('creates citations in additionalContent from search groundings', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-search-grounding');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-2.0-flash')
->withPrompt('What is the stock price of Google right now?')
->withProviderOptions(['searchGrounding' => true])
->asText();
expect($response->additionalContent)->toHaveKey('citations');
expect($response->additionalContent['citations'])->toHaveCount(6);
$concatenatedPartLength = collect($response->additionalContent['citations'])
->sum(fn (MessagePartWithCitations $messagePart): int => strlen($messagePart->outputText));
expect(strlen($response->text))->toBe($concatenatedPartLength);
expect($response->additionalContent['citations'][1]->citations)->toHaveCount(1);
expect($response->additionalContent['citations'][1]->citations[0])
->sourceTitle->toBe('ft.com')
->source->toBe('https://vertexaisearch.cloud.google.com/grounding-api-redirect/AQXblrzVmdvQ-8RyZbo6knG4xQpbHhzoZtCKui-qEXo7n-Gda_UaV5RNo3GuuAV7OBLY8oRmb0giKvPjP0FXgI8gktbMyJOx9yUkSYbBUJpfbLaHQy13zjpVAC596HzWEfbPjoh1_5EtEinrM1LW0D0_6OwQ_iDClBsm62K-L-I=')
->sourceType->toBe(CitationSourceType::Url);
expect($response->additionalContent['searchQueries'])->toHaveCount(1);
expect($response->additionalContent['searchEntryPoint'])->toHaveKey('renderedContent');
});
});
describe('Error handling for Gemini', function (): void {
it('includes finish reason details in exception for content filter', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-content-filter');
expect(fn () => Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash')
->withPrompt('Test prompt')
->asText()
)->toThrow(PrismException::class, 'Gemini: unhandled finish reason "content-filter" (raw: SAFETY)');
});
});
describe('Cache support for Gemini', function (): void {
it('can use a cache object with a text request', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/use-cache-with-text');
/** @var Gemini */
$provider = Prism::provider(Provider::Gemini);
$object = $provider->cache(
model: 'gemini-1.5-flash-002',
messages: [
new UserMessage('', [
Document::fromLocalPath('tests/Fixtures/long-document.pdf'),
]),
],
systemPrompts: [
new SystemMessage('You are a legal analyst.'),
],
ttl: 30
);
$response = Prism::text()
->using(Provider::Gemini, 'gemini-1.5-flash-002')
->withProviderOptions(['cachedContentName' => $object->name])
->withPrompt('In no more than 100 words, what is the document about?')
->asText();
Http::assertSentInOrder([
fn (Request $request): bool => true,
fn (Request $request): bool => $request->data()['cachedContent'] === $object->name,
]);
expect($response->text)->toBe("That's the Consolidated Version of the Treaty on the Functioning of the European Union (TFEU), adopted on 25 March 1957. It outlines the principles, competencies, and policies of the European Union. The TFEU organizes the EU's functioning and details its areas of competence, including exclusive, shared, and supporting competences. It also covers non-discrimination, citizenship, and various EU policies (e.g., internal market, agriculture, and justice). Finally, it sets out institutional and financial provisions.\n");
expect($response->usage->promptTokens)->toBe(16);
expect($response->usage->completionTokens)->toBe(116);
expect($response->usage->cacheReadInputTokens)->toBe(88759);
});
});
describe('Thinking Mode for Gemini', function (): void {
it('uses thought tokens on 2.5 series models by default without specifying a budget', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-a-prompt-with-thinking-budget');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-2.5-flash-preview')
->withPrompt('Explain the concept of Occam\'s Razor and provide a simple, everyday example.')
->asText();
expect($response->usage->thoughtTokens)->toBe(1209);
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['generationConfig'] ?? [])->not->toHaveKey('thinkingConfig');
return true;
});
});
it('sets thinking budget to 0', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-a-prompt-with-no-thinking-budget');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-2.5-flash-preview')
->withPrompt('Explain the concept of Occam\'s Razor and provide a simple, everyday example.')
->withProviderOptions(['thinkingBudget' => 0])
->asText();
expect($response->usage->thoughtTokens)->toBeNull();
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['generationConfig'])->toHaveKey('thinkingConfig')
->and($data['generationConfig']['thinkingConfig'])->toMatchArray([
'thinkingBudget' => 0,
]);
return true;
});
});
it('can use thinking level with 3.0-pro', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-a-prompt-with-thinking-budget');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-3.0-pro')
->withPrompt('Explain the concept of Occam\'s Razor and provide a simple, everyday example.')
->withProviderOptions(['thinkingLevel' => 'low'])
->asText();
expect($response->usage->thoughtTokens)->toBe(1209);
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['generationConfig'])
->toHaveKey('thinkingConfig')
->and($data['generationConfig']['thinkingConfig'])->toMatchArray([
'thinkingLevel' => 'low',
]);
return true;
});
});
it('configure pass a thinking config', function (): void {
FixtureResponse::fakeResponseSequence('*', 'gemini/generate-text-with-a-prompt-with-thinking-budget');
$response = Prism::text()
->using(Provider::Gemini, 'gemini-3.0-pro')
->withPrompt('Explain the concept of Occam\'s Razor and provide a simple, everyday example.')
->withProviderOptions([
'thinkingConfig' => [
'thinkingLevel' => 'low',
'includeThoughts' => false,
],
])
->asText();
expect($response->usage->thoughtTokens)->toBe(1209);
Http::assertSent(function (Request $request): true {
$data = $request->data();
expect($data['generationConfig'])
->toHaveKey('thinkingConfig')
->and($data['generationConfig']['thinkingConfig'])->toMatchArray([
'thinkingLevel' => 'low',
'includeThoughts' => false,
]);
return true;
});
});
});