Skip to content

Commit 3251004

Browse files
committed
add more tests
1 parent 5b592a3 commit 3251004

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Diff for: tests/Providers/Gemini/GeminiStreamTest.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use Illuminate\Http\Client\Request;
88
use Illuminate\Support\Facades\Http;
99
use Prism\Prism\Enums\Provider;
10+
use Prism\Prism\Facades\Tool;
1011
use Prism\Prism\Prism;
1112
use Tests\Fixtures\FixtureResponse;
1213

1314
beforeEach(function (): void {
1415
config()->set('prism.providers.gemini.api_key', env('GEMINI_API_KEY', 'sss-1234567890'));
1516
});
1617

17-
it('can generate text with a basic stream', function (): void {
18+
it('can generate text stream with a basic prompt', function (): void {
1819
FixtureResponse::fakeResponseSequence('*', 'gemini/stream-basic-text');
1920

2021
$response = Prism::text()
@@ -97,3 +98,43 @@
9798
->and($text)
9899
->toContain('The weather in San Francisco is currently 58°F (14°C) and partly cloudy. It feels like 55°F (13°C) with 79% humidity. There is a 0% chance of rain right now but showers are expected to develop.');
99100
});
101+
102+
it('can generate text stream using tools ', function (): void {
103+
FixtureResponse::fakeResponseSequence('*', 'gemini/stream-with-tools');
104+
105+
$tools = [
106+
Tool::as('weather')
107+
->for('useful when you need to search for current weather conditions')
108+
->withStringParameter('city', 'The city that you want the weather for')
109+
->using(fn (string $city): string => "The weather will be 75° and sunny in {$city}"),
110+
111+
Tool::as('search')
112+
->for('useful for searching current events or data')
113+
->withStringParameter('query', 'The detailed search query')
114+
->using(fn (string $query): string => "Search results for: {$query}"),
115+
];
116+
117+
$response = Prism::text()
118+
->using(Provider::Gemini, 'gemini-2.0-flash')
119+
->withTools($tools)
120+
->withPrompt('What\'s the current weather in San Francisco? And tell me if I need to wear a coat?')
121+
->asStream();
122+
123+
$text = '';
124+
$chunks = [];
125+
126+
foreach ($response as $chunk) {
127+
$chunks[] = $chunk;
128+
$text .= $chunk->text;
129+
}
130+
131+
expect($chunks)
132+
->not->toBeEmpty()
133+
->and($text)->not->toBeEmpty()
134+
->and($text)->toContain('The weather in San Francisco is currently 58°F (14°C) and partly cloudy. It feels like 55°F (13°C) with 79% humidity. There is a 0% chance of rain right now but showers are expected to develop.')
135+
->and($text)->toContain('a light jacket or coat would be advisable');
136+
137+
// Verify the HTTP request
138+
Http::assertSent(fn (Request $request): bool => str_contains($request->url(), 'streamGenerateContent?alt=sse')
139+
&& isset($request->data()['contents']));
140+
});

0 commit comments

Comments
 (0)