Download the PHP package erdemkose/generative-ai-php without Composer
On this page you can find all versions of the php package erdemkose/generative-ai-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download erdemkose/generative-ai-php
More information about erdemkose/generative-ai-php
Files in erdemkose/generative-ai-php
Package generative-ai-php
Short Description API client for Google's Gemini API
License MIT
Informations about the package generative-ai-php
Gemini API PHP Client
Gemini API PHP Client allows you to use the Google's generative AI models, like Gemini Pro and Gemini Pro Vision.
This library is not developed or endorsed by Google.
- Erdem Köse - github.com/erdemkose
Table of Contents
- Installation
- How to use
- Basic text generation
- Text generation with system instruction
- Multimodal input
- Chat Session (Multi-Turn Conversations)
- Chat Session with history
- Streaming responses
- Streaming Chat Session
- Tokens counting
- Listing models
- Advanced Usages
- Using Beta version
- Safety Settings and Generation Configuration
- Using your own HTTP client
- Using your own HTTP client for streaming responses
Installation
You need an API key to gain access to Google's Gemini API. Visit Google AI Studio to get an API key.
First step is to install the Gemini API PHP client with Composer.
Gemini API PHP client does not come with an HTTP client.
If you are just testing or do not have an HTTP client library in your project,
you need to allow php-http/discovery
composer plugin or install a PSR-18 compatible client library.
How to use
Basic text generation
Text generation with system instruction
System instruction is currently supported only in beta version
Multimodal input
Image input modality is only enabled for Gemini Pro Vision model
Chat Session (Multi-Turn Conversations)
Chat Session with history
Streaming responses
Requires
curl
extension to be enabled
In the streaming response, the callback function will be called whenever a response is returned from the server.
Long responses may be broken into separate responses, and you can start receiving responses faster using a content stream.
Streaming Chat Session
Requires
curl
extension to be enabled
Embed Content
Tokens counting
Listing models
Advanced Usages
Using Beta version
Safety Settings and Generation Configuration
Using your own HTTP client
Using your own HTTP client for streaming responses
Requires
curl
extension to be enabled
Since streaming responses are fetched using curl
extension, they cannot use the custom HTTP client passed to the Gemini Client.
You need to pass a CurlHandler
if you want to override connection options.
The following curl options will be overwritten by the Gemini Client.
CURLOPT_URL
CURLOPT_POST
CURLOPT_POSTFIELDS
CURLOPT_WRITEFUNCTION
You can also pass the headers you want to be used in the requests.
All versions of generative-ai-php with dependencies
php-http/discovery Version ^1.19
psr/http-client Version ^1.0
psr/http-client-implementation Version *
psr/http-factory Version ^1.0.2
psr/http-factory-implementation Version *
psr/http-message Version ^1.0.1 || ^2.0