PHP code example of assistant-engine / php-openai-client
1. Go to this page and download the library: Download assistant-engine/php-openai-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
assistant-engine / php-openai-client example snippets
use AssistantEngine\OpenAI\Client;
$client = Client::make($_ENV['OPEN_AI_KEY']);
$response = $client->responses()->create([
'model' => 'gpt-4o',
'input' => "Can you recommend me what I can eat today?"
]);
print_r($response->getOutputText());
$response2 = $client->responses()->create([
'model' => 'gpt-4o',
'previous_response_id' => $response->id,
'input' => "maybe Pizza?",
]);
print_r($response2->getOutputText());
use AssistantEngine\OpenAI\Client;
$client = Client::make($_ENV['OPEN_AI_KEY']);
$response = $client->responses()->create([
'model' => 'gpt-4o',
'tools' => [
[
'type' => 'file_search',
"vector_store_ids" => ["vs_123456789"]
]
],
'input' => "when is the event in berlin happening?"
]);
print_r($response->getOutputText());
use AssistantEngine\OpenAI\Client;
$client = Client::make($_ENV['OPEN_AI_KEY']);
$response = $client->responses()->create([
'model' => 'gpt-4o',
'tools' => [
[
'type' => 'web_search_preview'
]
],
'input' => "what was a positive news story from today?"
]);
print_r($response->getOutputText());
use AssistantEngine\OpenAI\Client;
$client = Client::make($_ENV['OPEN_AI_KEY']);
// Define query parameters for pagination and ordering
$params = [
'after' => 'item-id-to-start-after', // Optional: list items after this ID
'limit' => 50, // Optional: limit number of items (default is 20)
'order' => 'desc', // Optional: order items in descending order
];
$respId = "resp_123456789";
$list = $client->responses()->inputItems()->list($respId, $params);
print_r($list);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.