Skip to content

Commit e4be153

Browse files
authored
fix(gemini): update caching and structured request handling (#426)
1 parent 28c275b commit e4be153

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Providers/Gemini/Handlers/Structured.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ protected function addStep(array $data, Request $request): void
110110
promptTokens: data_get($data, 'usageMetadata.promptTokenCount', 0),
111111
completionTokens: data_get($data, 'usageMetadata.candidatesTokenCount', 0),
112112
thoughtTokens: data_get($data, 'usageMetadata.thoughtsTokenCount', null),
113+
cacheReadInputTokens: data_get($data, 'usageMetadata.cachedContentTokenCount', null),
113114
),
114115
meta: new Meta(
115116
id: data_get($data, 'id', ''),

tests/Providers/Gemini/GeminiStructuredTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@
109109
]))
110110
->withProviderOptions(['cachedContentName' => $object->name])
111111
->withPrompt('Summarise this document using the properties and descriptions defined in the schema.')
112-
->generate();
112+
->asStructured();
113113

114114
Http::assertSentInOrder([
115-
fn (Request $request): bool => true,
115+
fn (Request $request): bool => $request->url() == 'https://generativelanguage.googleapis.com/v1beta/cachedContents',
116116
fn (Request $request): bool => $request->data()['cachedContent'] === $object->name,
117117
]);
118118

@@ -123,6 +123,7 @@
123123
'article_count',
124124
]);
125125

126+
expect($response->usage->cacheReadInputTokens)->toBe(88759);
126127
expect($response->structured['article_count'])->toBe(358);
127128
expect($response->structured['legal_jurisdiction'])->toBe('European Union');
128129
expect($response->structured['legislation_type'])->toBe('Treaty');

0 commit comments

Comments
 (0)