gemini-api-php / client

Google Gemini API PHP Client allows you to use the Gemini AI model
MIT License
118 stars 23 forks source link

Add Streaming Response #21

Closed ahmadnajmdev closed 9 months ago

ahmadnajmdev commented 9 months ago

Add Streaming Response Here is Documentation: https://ai.google.dev/tutorials/rest_quickstart#stream_generate_content

erdemkose commented 9 months ago

@ahmadnajmdev How do you like the proposed streaming response change in #23? It requires curl extension to be enabled in PHP.

You can see the example in the README.md file.

$client = new GeminiAPI\Client('GEMINI_API_KEY');

$callback = function (GenerateContentResponse $response): void {
    static $count = 0;

    print "\nResponse #{$count}\n";
    print $response->text();
    $count++;
};

$client->geminiPro()->generateContentStream(
    $callback,
    new TextPart('PHP in less than 100 chars')
);
// Response #0
// PHP: a versatile, general-purpose scripting language for web development, popular for
// Response #1
//  its simple syntax and rich library of functions.
ahmadnajmdev commented 9 months ago

Erdem,

Thanks for sharing the proposed streaming response change in #23. It looks helpful.

Thanks, Ahmad

On Fri, Jan 5, 2024, 9:03 AM Erdem Köse @.***> wrote:

@ahmadnajmdev https://github.com/ahmadnajmdev How do you like the proposed streaming response change in #23 https://github.com/gemini-api-php/client/pull/23? You can see the example in the README.md file

https://github.com/gemini-api-php/client/pull/23/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R154

— Reply to this email directly, view it on GitHub https://github.com/gemini-api-php/client/issues/21#issuecomment-1878170402, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUTIETAALEWAD4IGL3SILUDYM6JTJAVCNFSM6AAAAABBHT7RMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZYGE3TANBQGI . You are receiving this because you were mentioned.Message ID: @.***>