Skip to content

Commit

Permalink
Change the root namespace and refer to the new repository
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemkose committed Dec 23, 2023
1 parent 92914d2 commit 6fae105
Show file tree
Hide file tree
Showing 45 changed files with 167 additions and 171 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 generative-ai-php
Copyright (c) 2023 gemini-api-php/client

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<p align="center">
<img src="https://raw.githubusercontent.com/erdemkose/generative-ai-php/main/assets/example.png" width="800" alt="Generative AI PHP Client">
<img src="https://raw.githubusercontent.com/gemini-api-php/client/main/assets/example.png" width="800" alt="Gemini API PHP Client - Example">
</p>
<p align="center">
<a href="https://packagist.org/packages/erdemkose/generative-ai-php"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/erdemkose/generative-ai-php"></a>
<a href="https://packagist.org/packages/erdemkose/generative-ai-php"><img alt="Latest Version" src="https://img.shields.io/packagist/v/erdemkose/generative-ai-php"></a>
<a href="https://packagist.org/packages/erdemkose/generative-ai-php"><img alt="License" src="https://img.shields.io/github/license/erdemkose/generative-ai-php"></a>
<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>
</p>

# Generative AI PHP Client
Generative AI PHP Client allows you to use the Google's Generative AI models, like Gemini Pro and Gemini Pro Vision.
# 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._

Expand All @@ -25,16 +26,16 @@ _This library is not developed or endorsed by Google._

## Installation

> You need an API key to gain access to Google Generative AI services.
> You need an API key to gain access to Google's Gemini API.
> Visit [Google AI Studio](https://makersuite.google.com/) to get an API key.
First step is to install the Generative AI PHP client with Composer.
First step is to install the Gemini API PHP client with Composer.

```shell
composer require erdemkose/generative-ai-php
composer require gemini-api-php/client
```

Generative AI PHP client does not come with an HTTP client.
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.

Expand All @@ -43,7 +44,7 @@ you need to allow `php-http/discovery` composer plugin or install a PSR-18 compa
### Basic text generation

```php
$client = new GenerativeAI\Client('YOUR_GEMINI_PRO_API_TOKEN');
$client = new GeminiAPI\Client('GEMINI_API_KEY');

$response = $client->geminiPro()->generateContent(
new TextPart('PHP in less than 100 chars')
Expand All @@ -59,7 +60,7 @@ print $response->text();
> Image input modality is only enabled for Gemini Pro Vision model
```php
$client = new GenerativeAI\Client('YOUR_GEMINI_PRO_API_TOKEN');
$client = new GeminiAPI\Client('GEMINI_API_KEY');

$response = $client->geminiProVision()->generateContent(
new TextPart('Explain what is in the image'),
Expand All @@ -79,7 +80,7 @@ print $response->text();
### Chat Session (Multi-Turn Conversations)

```php
$client = new GenerativeAI\Client('YOUR_GEMINI_PRO_API_TOKEN');
$client = new GeminiAPI\Client('GEMINI_API_KEY');

$chat = $client->geminiPro()->startChat();

Expand Down Expand Up @@ -113,7 +114,7 @@ This code will print "Hello World!" to the standard output.
### Tokens counting

```php
$client = new GenerativeAI\Client('YOUR_GEMINI_PRO_API_TOKEN');
$client = new GeminiAPI\Client('GEMINI_API_KEY');

$response = $client->geminiPro()->countTokens(
new TextPart('PHP in less than 100 chars'),
Expand All @@ -126,20 +127,20 @@ print $response->totalTokens;
### Listing models

```php
$client = new GenerativeAI\Client('YOUR_GEMINI_PRO_API_TOKEN');
$client = new GeminiAPI\Client('GEMINI_API_KEY');

$response = $client->listModels();

print_r($response->models);
//[
// [0] => GenerativeAI\Resources\Model Object
// [0] => GeminiAPI\Resources\Model Object
// (
// [name] => models/gemini-pro
// [displayName] => Gemini Pro
// [description] => The best model for scaling across a wide range of tasks
// ...
// )
// [1] => GenerativeAI\Resources\Model Object
// [1] => GeminiAPI\Resources\Model Object
// (
// [name] => models/gemini-pro-vision
// [displayName] => Gemini Pro Vision
Expand Down
Binary file modified assets/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "erdemkose/generative-ai-php",
"description": "Generative AI PHP is a client for Google's Generative AI service, Gemini Pro",
"name": "gemini-api-php/client",
"description": "API client for Google's Gemini API",
"keywords": [
"php",
"client",
Expand All @@ -10,17 +10,12 @@
"gemini",
"gemini pro",
"gemini pro vision",
"PaLM",
"language",
"model",
"generative",
"ai",
"generative-ai-php"
"ai"
],
"license": "MIT",
"authors": [
{
"name": "erdemkose",
"name": "Erdem Köse",
"email": "erdemkose@gmail.com"
}
],
Expand All @@ -42,12 +37,12 @@
},
"autoload": {
"psr-4": {
"GenerativeAI\\": "src/"
"GeminiAPI\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"GenerativeAI\\Tests\\": "tests/"
"GeminiAPI\\Tests\\": "tests/"
}
},
"minimum-stability": "stable",
Expand Down
10 changes: 5 additions & 5 deletions src/ChatSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace GenerativeAI;
namespace GeminiAPI;

use GenerativeAI\Enums\Role;
use GenerativeAI\Resources\Content;
use GenerativeAI\Resources\Parts\PartInterface;
use GenerativeAI\Responses\GenerateContentResponse;
use GeminiAPI\Enums\Role;
use GeminiAPI\Resources\Content;
use GeminiAPI\Resources\Parts\PartInterface;
use GeminiAPI\Responses\GenerateContentResponse;
use Psr\Http\Client\ClientExceptionInterface;

class ChatSession
Expand Down
24 changes: 12 additions & 12 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

declare(strict_types=1);

namespace GenerativeAI;

use GenerativeAI\Enums\ModelName;
use GenerativeAI\Requests\CountTokensRequest;
use GenerativeAI\Requests\GenerateContentRequest;
use GenerativeAI\Requests\ListModelsRequest;
use GenerativeAI\Requests\RequestInterface;
use GenerativeAI\Responses\CountTokensResponse;
use GenerativeAI\Responses\GenerateContentResponse;
use GenerativeAI\Responses\ListModelsResponse;
namespace GeminiAPI;

use GeminiAPI\Enums\ModelName;
use GeminiAPI\Requests\CountTokensRequest;
use GeminiAPI\Requests\GenerateContentRequest;
use GeminiAPI\Requests\ListModelsRequest;
use GeminiAPI\Requests\RequestInterface;
use GeminiAPI\Responses\CountTokensResponse;
use GeminiAPI\Responses\GenerateContentResponse;
use GeminiAPI\Responses\ListModelsResponse;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientExceptionInterface;
Expand Down Expand Up @@ -103,7 +103,7 @@ public function withBaseUrl(string $baseUrl): self
private function doRequest(RequestInterface $request): string
{
if (!isset($this->client, $this->requestFactory, $this->streamFactory)) {
throw new RuntimeException('Missing client or factory for Generative AI operation');
throw new RuntimeException('Missing client or factory for Gemini API operation');
}

$uri = sprintf(
Expand All @@ -125,7 +125,7 @@ private function doRequest(RequestInterface $request): string
if ($response->getStatusCode() !== 200) {
throw new RuntimeException(
sprintf(
'Generative AI operation failed: operation=%s, status_code=%d, response=%s',
'Gemini API operation failed: operation=%s, status_code=%d, response=%s',
$request->getOperation(),
$response->getStatusCode(),
$response->getBody(),
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/BlockReason.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum BlockReason: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/FinishReason.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum FinishReason: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/HarmBlockThreshold.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum HarmBlockThreshold: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/HarmCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum HarmCategory: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/HarmProbability.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum HarmProbability: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/MimeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum MimeType: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/ModelName.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum ModelName: string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Enums;
namespace GeminiAPI\Enums;

enum Role: string
{
Expand Down
4 changes: 2 additions & 2 deletions src/GenerationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace GenerativeAI;
namespace GeminiAPI;

use GenerativeAI\Traits\ArrayTypeValidator;
use GeminiAPI\Traits\ArrayTypeValidator;
use JsonSerializable;
use UnexpectedValueException;

Expand Down
22 changes: 11 additions & 11 deletions src/GenerativeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace GenerativeAI;

use GenerativeAI\Enums\ModelName;
use GenerativeAI\Enums\Role;
use GenerativeAI\Requests\CountTokensRequest;
use GenerativeAI\Requests\GenerateContentRequest;
use GenerativeAI\Responses\CountTokensResponse;
use GenerativeAI\Responses\GenerateContentResponse;
use GenerativeAI\Resources\Content;
use GenerativeAI\Resources\Parts\PartInterface;
use GenerativeAI\Traits\ArrayTypeValidator;
namespace GeminiAPI;

use GeminiAPI\Enums\ModelName;
use GeminiAPI\Enums\Role;
use GeminiAPI\Requests\CountTokensRequest;
use GeminiAPI\Requests\GenerateContentRequest;
use GeminiAPI\Responses\CountTokensResponse;
use GeminiAPI\Responses\GenerateContentResponse;
use GeminiAPI\Resources\Content;
use GeminiAPI\Resources\Parts\PartInterface;
use GeminiAPI\Traits\ArrayTypeValidator;
use Psr\Http\Client\ClientExceptionInterface;

class GenerativeModel
Expand Down
8 changes: 4 additions & 4 deletions src/Requests/CountTokensRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace GenerativeAI\Requests;
namespace GeminiAPI\Requests;

use GenerativeAI\Enums\ModelName;
use GenerativeAI\Traits\ArrayTypeValidator;
use GenerativeAI\Resources\Content;
use GeminiAPI\Enums\ModelName;
use GeminiAPI\Traits\ArrayTypeValidator;
use GeminiAPI\Resources\Content;
use JsonSerializable;

use function json_encode;
Expand Down
12 changes: 6 additions & 6 deletions src/Requests/GenerateContentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace GenerativeAI\Requests;
namespace GeminiAPI\Requests;

use GenerativeAI\Enums\ModelName;
use GenerativeAI\GenerationConfig;
use GenerativeAI\SafetySetting;
use GenerativeAI\Traits\ArrayTypeValidator;
use GenerativeAI\Resources\Content;
use GeminiAPI\Enums\ModelName;
use GeminiAPI\GenerationConfig;
use GeminiAPI\SafetySetting;
use GeminiAPI\Traits\ArrayTypeValidator;
use GeminiAPI\Resources\Content;
use JsonSerializable;

use function json_encode;
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/ListModelsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Requests;
namespace GeminiAPI\Requests;

class ListModelsRequest implements RequestInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Requests/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace GenerativeAI\Requests;
namespace GeminiAPI\Requests;

interface RequestInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/Candidate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace GenerativeAI\Resources;
namespace GeminiAPI\Resources;

use GenerativeAI\Enums\FinishReason;
use GenerativeAI\Traits\ArrayTypeValidator;
use GeminiAPI\Enums\FinishReason;
use GeminiAPI\Traits\ArrayTypeValidator;
use UnexpectedValueException;

class Candidate
Expand Down
Loading

0 comments on commit 6fae105

Please sign in to comment.