1. Go to this page and download the library: Download elliotjreed/ai 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/ */
elliotjreed / ai example snippets
$claude = new ElliotJReed\AI\ClaudeAI\Prompt('API KEY', 'claude-3-haiku-20240307');
$chatGPT = new ElliotJReed\AI\ChatGPT\Prompt('API KEY', 'gpt-4o-mini');
$claude = new ElliotJReed\AI\ClaudeAI\Prompt('API KEY', 'claude-3-haiku-20240307', new \GuzzleHttp\Client());
$chatGPT = new ElliotJReed\AI\ChatGPT\Prompt('API KEY', 'gpt-4o-mini', new \GuzzleHttp\Client());
pt = new ElliotJReed\AI\ClaudeAI\Prompt('API KEY', 'claude-3-haiku-20240307');
$request = (new ElliotJReed\AI\Entity\Request())
->setInput('Which programming language will outlive humanity?');
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
pt = new ElliotJReed\AI\ClaudeAI\Prompt('API KEY', 'claude-3-haiku-20240307');
$request = (new ElliotJReed\AI\Entity\Request())
->setContext('The user input is coming from a software development advice website which provides information to aspiring software developers.')
->setRole('You are an expert in software development')
->setInstructions('Answer the user\'s query in a friendly, and clear and concise manner')
->setInput('Which programming language will outlive humanity?')
->setTemperature(0.5)
->setMaximumTokens(600)
->setExamples([(new ElliotJReed\AI\Entity\Example())
->setPrompt('Which programming language do you think will still be used in the year 3125?')
->setResponse('I think PHP will be around for at least another 7 million years.')
])
->setData('You could add some JSON, CSV, or Yaml data here.');
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
pt = new ElliotJReed\AI\ClaudeAI\Prompt('API KEY', 'claude-3-haiku-20240307');
$request = (new ElliotJReed\AI\Entity\Request())
->setContext('The user will ask various ethical questions posited through an online chat interface.')
->setRole('You are a philosopher and ethicist who favours utilitarian methodology when answering ethical questions.')
->setInstructions('Answer ethical questions using British English only, referencing the works of Jeremy Bentham, John Stuart Mill, and Peter Singer.')
->setInput('Should we all be vegan?')
->setTemperature(0.8)
->setMaximumTokens(600);
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
$secondResponse = $prompt->send($request
->setInput('Elaborate on your response, providing 3 bullet points for arguing in favour of veganism, and 3 bullet points arguing against.')
->setHistory($response->getHistory()));
echo 'Used input tokens: ' . $secondResponse->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $secondResponse->getUsage()->getOutputTokens() . \PHP_EOL . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
pt = new ElliotJReed\AI\ChatGPT\Prompt('API KEY', 'gpt-4o-mini');
$request = (new ElliotJReed\AI\Entity\Request())
->setInput('Which programming language will outlive humanity?');
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
pt = new ElliotJReed\AI\ChatGPT\Prompt('API KEY', 'gpt-4o-mini');
$request = (new ElliotJReed\AI\Entity\Request())
->setContext('The user input is coming from a software development advice website which provides information to aspiring software developers.')
->setRole('You are an expert in software development')
->setInstructions('Answer the user\'s query in a friendly, and clear and concise manner')
->setInput('Which programming language will outlive humanity?')
->setTemperature(0.5)
->setMaximumTokens(600)
->setExamples([(new ElliotJReed\AI\Entity\Example())
->setPrompt('Which programming language do you think will still be used in the year 3125?')
->setResponse('I think PHP will be around for at least another 7 million years.')
])
->setData('You could add some JSON, CSV, or Yaml data here.');
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
pt = new ElliotJReed\AI\ChatGPT\Prompt('API KEY', 'gpt-4o-mini');
$request = (new ElliotJReed\AI\Entity\Request())
->setContext('The user will ask various ethical questions posited through an online chat interface.')
->setRole('You are a philosopher and ethicist who favours utilitarian methodology when answering ethical questions.')
->setInstructions('Answer ethical questions using British English only, referencing the works of Jeremy Bentham, John Stuart Mill, and Peter Singer.')
->setInput('Should we all be vegan?')
->setTemperature(0.8)
->setMaximumTokens(600);
$response = $prompt->send($request);
echo 'Used input tokens: ' . $response->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $response->getUsage()->getOutputTokens() . \PHP_EOL . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
$secondResponse = $prompt->send($request
->setInput('Elaborate on your response, providing 3 bullet points for arguing in favour of veganism, and 3 bullet points arguing against.')
->setHistory($response->getHistory()));
echo 'Used input tokens: ' . $secondResponse->getUsage()->getInputTokens() . \PHP_EOL;
echo 'Used output tokens: ' . $secondResponse->getUsage()->getOutputTokens() . \PHP_EOL . \PHP_EOL;
echo 'Response from AI: ' . $response->getContent() . \PHP_EOL;
bash
php composer.phar install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.