-
Notifications
You must be signed in to change notification settings - Fork 51
Add support to add systemInstruction and update API to V1Beta #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b46086a
2250e09
48b9e0d
eba2700
8219a6c
7f6335c
e6fd486
f83115e
64edece
89ec139
bf78600
40886a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,22 @@ | ||
| <p align="center"> | ||
| <img src="https://raw.githubusercontent.com/gemini-api-php/client/main/assets/example.png" width="800" alt="Gemini API PHP Client - Example"> | ||
| <img src="https://raw.githubusercontent.com/alexandrevega/gemini-api-client/main/assets/example.png" width="800" alt="Gemini API PHP Client - Example"> | ||
| </p> | ||
| <p align="center"> | ||
| <a href="https://packagist.org/packages/gemini-api-php/client"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/gemini-api-php/client"></a> | ||
| <a href="https://packagist.org/packages/gemini-api-php/client"><img alt="Latest Version" src="https://img.shields.io/packagist/v/gemini-api-php/client"></a> | ||
| <a href="https://packagist.org/packages/gemini-api-php/client"><img alt="License" src="https://img.shields.io/github/license/gemini-api-php/client"></a> | ||
| <a href="https://packagist.org/packages/galexandrevega/gemini-api-client"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/alexandrevega/gemini-api-client"></a> | ||
| <a href="https://packagist.org/packages/alexandrevega/gemini-api-client"><img alt="Latest Version" src="https://img.shields.io/packagist/v/alexandrevega/gemini-api-client"></a> | ||
| <a href="https://packagist.org/packages/alexandrevega/gemini-api-client"><img alt="License" src="https://img.shields.io/github/license/alexandrevega/gemini-api-client"></a> | ||
| </p> | ||
|
|
||
| # Gemini API PHP Client | ||
|
|
||
| This library is a fork of [gemini-api-php/client](https://github.com/gemini-api-php/client) adding system instructions and updating api to v1beta. | ||
|
|
||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to this project |
||
| 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](https://github.com/erdemkose)** | ||
| - Alexandre Vega - **[github.com/alexandrevega](https://github.com/alexandrevega)** | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to this project |
||
|
|
||
| ## Table of Contents | ||
| - [Installation](#installation) | ||
|
|
@@ -24,6 +27,7 @@ _This library is not developed or endorsed by Google._ | |
| - [Chat Session with history](#chat-session-with-history) | ||
| - [Streaming responses](#streaming-responses) | ||
| - [Streaming Chat Session](#streaming-chat-session) | ||
| - [System Instruction](#system-instruction) | ||
| - [Tokens counting](#tokens-counting) | ||
| - [Listing models](#listing-models) | ||
| - [Advanced Usages](#advanced-usages) | ||
|
|
@@ -39,7 +43,7 @@ _This library is not developed or endorsed by Google._ | |
| First step is to install the Gemini API PHP client with Composer. | ||
|
|
||
| ```shell | ||
| composer require gemini-api-php/client | ||
| composer require alexandrevega/gemini-api-client | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to this project |
||
| ``` | ||
|
|
||
| Gemini API PHP client does not come with an HTTP client. | ||
|
|
@@ -257,6 +261,58 @@ Response #1 | |
| This code will print "Hello World!" to the standard output. | ||
| ``` | ||
|
|
||
| ### System Instruction | ||
| You can add [System Instructions](https://ai.google.dev/gemini-api/docs/system-instructions?hl=en&lang=web) to steer the behaviour of Gemini. | ||
|
|
||
| ```php | ||
| use GeminiAPI\Client; | ||
| use GeminiAPI\Enums\Role; | ||
| use GeminiAPI\Resources\Content; | ||
| use GeminiAPI\Resources\Parts\TextPart; | ||
|
|
||
| $history = [ | ||
| Content::text('Hello World in PHP', Role::User), | ||
| Content::text( | ||
| <<<TEXT | ||
| <?php | ||
| echo "Hello World!"; | ||
| ?> | ||
|
|
||
| This code will print "Hello World!" to the standard output. | ||
| TEXT, | ||
| Role::Model, | ||
| ), | ||
| ]; | ||
|
|
||
| $client = new Client('GEMINI_API_KEY'); | ||
| $chat = $client->geminiPro() | ||
| ->withSystemInstruction("You're an expert developer") | ||
| ->startChat() | ||
| ->withHistory($history); | ||
|
|
||
| $response = $chat->sendMessage(new TextPart('in Go')); | ||
| print $response->text(); | ||
| ``` | ||
|
|
||
| ```text | ||
| Response #0 | ||
| package main | ||
|
|
||
| import "fmt" | ||
|
|
||
| func main() { | ||
|
|
||
| Response #1 | ||
| fmt.Println("Hello World!") | ||
| } | ||
|
|
||
| This code will print "Hello World!" to the standard output. | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| ### Embed Content | ||
|
|
||
| ```php | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "name": "gemini-api-php/client", | ||
| "name": "alexandrevega/gemini-api-client", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to this project |
||
| "description": "API client for Google's Gemini API", | ||
| "keywords": [ | ||
| "php", | ||
|
|
@@ -17,6 +17,10 @@ | |
| { | ||
| "name": "Erdem Köse", | ||
| "email": "erdemkose@gmail.com" | ||
| }, | ||
| { | ||
| "name": "Carlos Ramos", | ||
| "email": "contact@cramos.dev" | ||
|
Comment on lines
+20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these changes do not apply to this project |
||
| } | ||
| ], | ||
| "require": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,7 +103,7 @@ public function embeddingModel(ModelName $modelName): EmbeddingModel | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| /**x | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
| * @throws ClientExceptionInterface | ||
| */ | ||
| public function generateContent(GenerateContentRequest $request): GenerateContentResponse | ||
|
|
@@ -163,7 +163,7 @@ public function generateContentStream( | |
| } | ||
| } | ||
|
|
||
| curl_setopt($ch, CURLOPT_URL, "{$this->baseUrl}/v1/{$request->getOperation()}"); | ||
| curl_setopt($ch, CURLOPT_URL, "{$this->baseUrl}/v1beta/{$request->getOperation()}"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the version be configurable ? |
||
| curl_setopt($ch, CURLOPT_POST, true); | ||
| curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($request)); | ||
| curl_setopt($ch, CURLOPT_HTTPHEADER, $headerLines); | ||
|
|
@@ -250,7 +250,7 @@ private function doRequest(RequestInterface $request): string | |
| throw new RuntimeException('Missing client or factory for Gemini API operation'); | ||
| } | ||
|
|
||
| $uri = "{$this->baseUrl}/v1/{$request->getOperation()}"; | ||
| $uri = "{$this->baseUrl}/v1beta/{$request->getOperation()}"; | ||
| $httpRequest = $this->requestFactory | ||
| ->createRequest($request->getHttpMethod(), $uri); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these changes do not apply to this project