forked from openai-php/client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.php
More file actions
28 lines (19 loc) · 689 Bytes
/
Copy pathtest.php
File metadata and controls
28 lines (19 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
require __DIR__ . '/vendor/autoload.php';
// Load .env
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$yourApiKey = getenv('YOUR_API_KEY');
$client = OpenAI::factory()
->withApiKey($_ENV["GEMINI_API_KEY"])
->withOrganization('your-organization') // default: null
->withProject('Your Project') // default: null
->withBaseUri('https://generativelanguage.googleapis.com/v1beta/openai') // default: api.openai.com/v1
->make();
$result = $client->chat()->create([
'model' => 'gemini-2.0-flash',
'messages' => [
['role' => 'user', 'content' => 'Hello!, who are you'],
],
]);
echo $result->choices[0]->message->content;