@@ -51,10 +51,12 @@ you need to allow `php-http/discovery` composer plugin or install a PSR-18 compa
5151### Basic text generation
5252
5353``` php
54- $client = new GeminiAPI\Client('GEMINI_API_KEY');
54+ use GeminiAPI\Client;
55+ use GeminiAPI\Resources\Parts\TextPart;
5556
57+ $client = new Client('GEMINI_API_KEY');
5658$response = $client->geminiPro()->generateContent(
57- new TextPart('PHP in less than 100 chars')
59+ new TextPart('PHP in less than 100 chars'),
5860);
5961
6062print $response->text();
@@ -67,8 +69,12 @@ print $response->text();
6769> Image input modality is only enabled for Gemini Pro Vision model
6870
6971``` php
70- $client = new GeminiAPI\Client('GEMINI_API_KEY');
72+ use GeminiAPI\Client;
73+ use GeminiAPI\Enums\MimeType;
74+ use GeminiAPI\Resources\Parts\ImagePart;
75+ use GeminiAPI\Resources\Parts\TextPart;
7176
77+ $client = new Client('GEMINI_API_KEY');
7278$response = $client->geminiProVision()->generateContent(
7379 new TextPart('Explain what is in the image'),
7480 new ImagePart(
@@ -87,8 +93,10 @@ print $response->text();
8793### Chat Session (Multi-Turn Conversations)
8894
8995``` php
90- $client = new GeminiAPI\Client('GEMINI_API_KEY');
96+ use GeminiAPI\Client;
97+ use GeminiAPI\Resources\Parts\TextPart;
9198
99+ $client = new Client('GEMINI_API_KEY');
92100$chat = $client->geminiPro()->startChat();
93101
94102$response = $chat->sendMessage(new TextPart('Hello World in PHP'));
@@ -121,7 +129,10 @@ This code will print "Hello World!" to the standard output.
121129### Chat Session with history
122130
123131``` php
124- $client = new GeminiAPI\Client('GEMINI_API_KEY');
132+ use GeminiAPI\Client;
133+ use GeminiAPI\Enums\Role;
134+ use GeminiAPI\Resources\Content;
135+ use GeminiAPI\Resources\Parts\TextPart;
125136
126137$history = [
127138 Content::text('Hello World in PHP', Role::User),
@@ -136,6 +147,8 @@ $history = [
136147 Role::Model,
137148 ),
138149];
150+
151+ $client = new Client('GEMINI_API_KEY');
139152$chat = $client->geminiPro()
140153 ->startChat()
141154 ->withHistory($history);
@@ -165,7 +178,9 @@ In the streaming response, the callback function will be called whenever a respo
165178Long responses may be broken into separate responses, and you can start receiving responses faster using a content stream.
166179
167180``` php
168- $client = new GeminiAPI\Client('GEMINI_API_KEY');
181+ use GeminiAPI\Client;
182+ use GeminiAPI\Resources\Parts\TextPart;
183+ use GeminiAPI\Responses\GenerateContentResponse;
169184
170185$callback = function (GenerateContentResponse $response): void {
171186 static $count = 0;
@@ -175,6 +190,7 @@ $callback = function (GenerateContentResponse $response): void {
175190 $count++;
176191};
177192
193+ $client = new Client('GEMINI_API_KEY');
178194$client->geminiPro()->generateContentStream(
179195 $callback,
180196 [new TextPart('PHP in less than 100 chars')],
@@ -190,7 +206,11 @@ $client->geminiPro()->generateContentStream(
190206> Requires ` curl ` extension to be enabled
191207
192208``` php
193- $client = new GeminiAPI\Client('GEMINI_API_KEY');
209+ use GeminiAPI\Client;
210+ use GeminiAPI\Enums\Role;
211+ use GeminiAPI\Resources\Content;
212+ use GeminiAPI\Resources\Parts\TextPart;
213+ use GeminiAPI\Responses\GenerateContentResponse;
194214
195215$history = [
196216 Content::text('Hello World in PHP', Role::User),
@@ -205,9 +225,6 @@ $history = [
205225 Role::Model,
206226 ),
207227];
208- $chat = $client->geminiPro()
209- ->startChat()
210- ->withHistory($history);
211228
212229$callback = function (GenerateContentResponse $response): void {
213230 static $count = 0;
@@ -217,6 +234,11 @@ $callback = function (GenerateContentResponse $response): void {
217234 $count++;
218235};
219236
237+ $client = new Client('GEMINI_API_KEY');
238+ $chat = $client->geminiPro()
239+ ->startChat()
240+ ->withHistory($history);
241+
220242$chat->sendMessageStream($callback, new TextPart('in Go'));
221243```
222244
@@ -238,8 +260,11 @@ This code will print "Hello World!" to the standard output.
238260### Embed Content
239261
240262``` php
241- $client = new GeminiAPI\Client('GEMINI_API_KEY');
263+ use GeminiAPI\Client;
264+ use GeminiAPI\Enums\ModelName;
265+ use GeminiAPI\Resources\Parts\TextPart;
242266
267+ $client = new Client('GEMINI_API_KEY');
243268$response = $client->embeddingModel(ModelName::Embedding)
244269 ->embedContent(
245270 new TextPart('PHP in less than 100 chars'),
@@ -256,8 +281,10 @@ print_r($response->embedding->values);
256281### Tokens counting
257282
258283``` php
259- $client = new GeminiAPI\Client('GEMINI_API_KEY');
284+ use GeminiAPI\Client;
285+ use GeminiAPI\Resources\Parts\TextPart;
260286
287+ $client = new Client('GEMINI_API_KEY');
261288$response = $client->geminiPro()->countTokens(
262289 new TextPart('PHP in less than 100 chars'),
263290);
@@ -269,8 +296,9 @@ print $response->totalTokens;
269296### Listing models
270297
271298``` php
272- $client = new GeminiAPI\Client('GEMINI_API_KEY') ;
299+ use GeminiAPI\Client;
273300
301+ $client = new Client('GEMINI_API_KEY');
274302$response = $client->listModels();
275303
276304print_r($response->models);
@@ -297,19 +325,26 @@ print_r($response->models);
297325#### Safety Settings and Generation Configuration
298326
299327``` php
300- $client = new GeminiAPI\Client('GEMINI_API_KEY');
301- $safetySetting = new GeminiAPI\SafetySetting(
328+ use GeminiAPI\Client;
329+ use GeminiAPI\Enums\HarmCategory;
330+ use GeminiAPI\Enums\HarmBlockThreshold;
331+ use GeminiAPI\GenerationConfig;
332+ use GeminiAPI\Resources\Parts\TextPart;
333+ use GeminiAPI\SafetySetting;
334+
335+ $safetySetting = new SafetySetting(
302336 HarmCategory::HARM_CATEGORY_HATE_SPEECH,
303337 HarmBlockThreshold::BLOCK_LOW_AND_ABOVE,
304338);
305- $generationConfig = (new GeminiAPI\ GenerationConfig())
339+ $generationConfig = (new GenerationConfig())
306340 ->withCandidateCount(1)
307341 ->withMaxOutputTokens(40)
308342 ->withTemperature(0.5)
309343 ->withTopK(40)
310344 ->withTopP(0.6)
311345 ->withStopSequences(['STOP']);
312346
347+ $client = new Client('GEMINI_API_KEY');
313348$response = $client->geminiPro()
314349 ->withAddedSafetySetting($safetySetting)
315350 ->withGenerationConfig($generationConfig)
@@ -321,11 +356,15 @@ $response = $client->geminiPro()
321356#### Using your own HTTP client
322357
323358``` php
324- $guzzle = new GuzzleHttp\Client([
359+ use GeminiAPI\Client as GeminiClient;
360+ use GeminiAPI\Resources\Parts\TextPart;
361+ use GuzzleHttp\Client as GuzzleClient;
362+
363+ $guzzle = new GuzzleClient([
325364 'proxy' => 'http://localhost:8125',
326365]);
327- $client = new GeminiAPI\Client('GEMINI_API_KEY', $guzzle);
328366
367+ $client = new GeminiClient('GEMINI_API_KEY', $guzzle);
329368$response = $client->geminiPro()->generateContent(
330369 new TextPart('PHP in less than 100 chars')
331370);
@@ -348,15 +387,18 @@ The following curl options will be overwritten by the Gemini Client.
348387You can also pass the headers you want to be used in the requests.
349388
350389``` php
351- $client = new GeminiAPI\Client('GEMINI_API_KEY');
390+ use GeminiAPI\Client;
391+ use GeminiAPI\Resources\Parts\TextPart;
392+ use GeminiAPI\Responses\GenerateContentResponse;
352393
353394$callback = function (GenerateContentResponse $response): void {
354395 print $response->text();
355396};
356397
357398$ch = curl_init();
358- curl_setopt($ch, CURLOPT_PROXY, 'http://localhost:8125');
399+ curl_setopt($ch, \ CURLOPT_PROXY, 'http://localhost:8125');
359400
401+ $client = new Client('GEMINI_API_KEY');
360402$client->withRequestHeaders([
361403 'User-Agent' => 'My Gemini-backed app'
362404 ])
0 commit comments