PHP code example of creativecrafts / laravel-ai-assistant
1. Go to this page and download the library: Download creativecrafts/laravel-ai-assistant 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/ */
creativecrafts / laravel-ai-assistant example snippets
use CreativeCrafts\LaravelAiAssistant\Tasks\AiAssistant;
$assistant = AiAssistant::init();
$assistant->setModelName('gpt-3.5-turbo')
->adjustTemperature(0.7)
->setDeveloperMessage('Please maintain a friendly tone.')
->setUserMessage('What is the weather like today?');
$response = $assistant->sendChatMessage();
$assistant->setFilePath('/path/to/audio.mp3');
$transcription = $assistant->transcribeTo('en', 'Transcribe the following audio:');
// Adding a custom function tool
$assistant->includeFunctionCallTool(
'calculateSum',
'Calculates the sum of two numbers',
['num1' => 'number', 'num2' => 'number'],
isStrict: true,
use CreativeCrafts\LaravelAiAssistant\AiAssistant;
$assistant = AiAssistant::init()
->setModelName('gpt-3.5-turbo')
->adjustTemperature(0.7)
->setDeveloperMessage('Maintain a formal tone.')
->setUserMessage('Tell me a joke.')
->sendChatMessage();
use CreativeCrafts\LaravelAiAssistant\AiAssistant;
$transcription = AiAssistant::init()
->setFilePath('/path/to/audio.mp3');
->transcribeTo('en', 'Transcribe this audio:');
use CreativeCrafts\LaravelAiAssistant\AiAssistant;
$response = AiAssistant::init()
->includeFunctionCallTool(
'calculateSum',
'Calculates the sum of two numbers',
['num1' => 'number', 'num2' => 'number'],
isStrict: true,
use CreativeCrafts\LaravelAiAssistant\AiAssistant;
$assistant = AiAssistant::init()
->setModelName('gpt-4') // Optional, defaults to config default model
->adjustTemperature(0.5) // Optional defaults to 0.7
->setAssistantName('My Assistant') // Optional, defaults to '' and Open Ai will assign random name
->setAssistantDescription('An assistant for handling tasks') // Optional, defaults to ''
->setInstructions('Be as helpful as possible.') // Optional, defaults to ''
->create();
use CreativeCrafts\LaravelAiAssistant\AiAssistant;
$response = \CreativeCrafts\LaravelAiAssistant\AiAssistant::init()
->setAssistantId($assistantId) // Required
->createTask() // Can optionally pass a list of tasks as an array, defaults to []
->askQuestion('Translate this text to French: "Hello, how are you?"')
->process()
->response(); // returns the response from the assistant as a string