Skip to content

Commit

Permalink
feat: Add beta branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatih Aydın committed Sep 28, 2024
1 parent e27b63f commit 4123010
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ For more information, take a look at the [google-gemini-php/client](https://gith
- [Text-and-image Input](#text-and-image-input)
- [Multi-turn Conversations (Chat)](#multi-turn-conversations-chat)
- [Stream Generate Content](#stream-generate-content)
- [Structured Output](#structured-output)
- [Count tokens](#count-tokens)
- [Configuration](#configuration)
- [Embedding Resource](#embedding-resource)
Expand Down Expand Up @@ -146,6 +147,57 @@ foreach ($stream as $response) {
}
```


#### Structured Output
Gemini generates unstructured text by default, but some applications require structured text. For these use cases, you can constrain Gemini to respond with JSON, a structured data format suitable for automated processing. You can also constrain the model to respond with one of the options specified in an enum.

```php
$result = Gemini::geminiFlash()
->withGenerationConfig(
generationConfig: new GenerationConfig(
responseMimeType: ResponseMimeType::APPLICATION_JSON,
responseSchema: new Schema(
type: DataType::ARRAY,
items: new Schema(
type: DataType::OBJECT,
properties: [
"recipe_name" => new Schema(type: DataType::STRING),
"cooking_time_in_minutes" => new Schema(type: DataType::INTEGER)
]
)
)
)
)
->generateContent("List 5 popular cookie recipes with cooking time");


$result->json();

//[
// {
// +"cooking_time_in_minutes": 10,
// +"recipe_name": "Chocolate Chip Cookies",
// },
// {
// +"cooking_time_in_minutes": 12,
// +"recipe_name": "Oatmeal Raisin Cookies",
// },
// {
// +"cooking_time_in_minutes": 10,
// +"recipe_name": "Peanut Butter Cookies",
// },
// {
// +"cooking_time_in_minutes": 10,
// +"recipe_name": "Snickerdoodles",
// },
// {
// +"cooking_time_in_minutes": 12,
// +"recipe_name": "Sugar Cookies",
// },
// ]

```

#### Count tokens
When using long prompts, it might be useful to count tokens before sending any content to the model.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.1.0",
"google-gemini-php/client": "^1.0",
"google-gemini-php/client": "^1.0.0-beta",
"laravel/framework": "^9.0|^10.0|^11.0"
},
"require-dev": {
Expand Down
4 changes: 1 addition & 3 deletions src/Testing/GeminiFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Gemini\Testing\ClientFake;

class GeminiFake extends ClientFake
{
}
class GeminiFake extends ClientFake {}
1 change: 1 addition & 0 deletions tests/Arch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'Gemini\Contracts\ResponseContract',
'Gemini\Laravel\Testing\GeminiFake',
'Gemini\Responses\StreamResponse',
'Gemini\Enums\ModelType',
]);

test('service providers')
Expand Down

0 comments on commit 4123010

Please sign in to comment.