PHP code example of sonichaos360 / lugpt

1. Go to this page and download the library: Download sonichaos360/lugpt 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/ */

    

sonichaos360 / lugpt example snippets




use Sonichaos360\LuGPT\Completions;

$apiKey = 'your_openai_api_key';
$model = 'gpt-3.5-turbo';
$maxTokens = '1500';
$temp = '1';
$conversationsPath = '../conversations'; //Optional, necessary only if you will manage conversation history using createConversation()

$luGPT = new Completions($apiKey, $model, $maxTokens, $temp, $conversationsPath);


$systemMessage = 'You are an assistant that translates English to French.';
$userMessage = 'Translate the following sentence: "Hello, how are you?"';
$response = $luGPT->Chat($systemMessage, $userMessage);

echo $response['choices'][0]['message']['content'];

// Create a new conversation
$conversationId = $luGPT->createConversation();

// Send messages within the conversation
$systemMessage = 'You are an assistant that translates between any languages.';
$userMessage1 = 'Translate the following sentence from English to French: "Hello, how are you?"';
$response1 = $luGPT->Chat($systemMessage, $userMessage1, $conversationId);

echo $response1['choices'][0]['message']['content']." | ";

$userMessage2 = 'Now, please translate this: "I am fine, thank you."';
$response2 = $luGPT->Chat($systemMessage, $userMessage2, $conversationId);

echo $response2['choices'][0]['message']['content']." | ";

$prompt = 'Translate the following English sentence to French: "Hello, how are you?"';
$response = $luGPT->Completion($prompt);

echo $response["choices"][0]["text"];