1. Go to this page and download the library: Download sysborg/chatgpt 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/ */
use Sysborg\ChatGPT\Facades\ChatGPT;
$response = ChatGPT::chat('Hello, how are you?');
echo $response->getContent();
$messages = [
['role' => 'user', 'content' => 'What is the capital of Brazil?'],
['role' => 'assistant', 'content' => 'The capital of Brazil is Brasília.'],
['role' => 'user', 'content' => 'What is the population?']
];
$response = ChatGPT::chatWithHistory($messages);
echo $response->getContent();
$response = ChatGPT::completion('Once upon a time in a distant kingdom');
echo $response->getContent();
$response = ChatGPT::vision(
'https://example.com/image.jpg',
'Describe this image in detail'
);
// With base64 image
$base64 = base64_encode(file_get_contents('/path/to/image.jpg'));
$response = ChatGPT::visionFromBase64(
$base64,
'What do you see in this image?'
);
echo $response->getAnalysis();
$response = ChatGPT::setModel('gpt-4')
->setTemperature(0.9)
->setMaxTokens(2000)
->chat('Tell a creative story');
$response = ChatGPT::chat('Hi!');
echo $response->getContent();
echo $response->getModel();
echo $response->getTotalTokens();
echo $response->getFinishReason();
if ($response->isComplete()) {
echo "Completed successfully";
}
if ($response->isTruncated()) {
echo "Response was truncated";
}
$response = ChatGPT::vision($imageUrl, 'Analyze this image');
echo $response->getAnalysis();
print_r($response->getDetectedEntities());
echo $response->getSummary();
if ($response->hasSafetyConcerns()) {
echo "This image may contain sensitive content";
}