The Client
class is a PHP wrapper designed for easy interaction with the OpenAI API, specifically tailored for the OctopusAI project. This class provides methods to generate rewritten, completed, summarized, and elaborated versions of input values using the OpenAI GPT-3.5 Turbo model.
To use the Client
class in your project, you need to include it and its dependencies. Make sure to install the required packages by running:
composer require openai/openai
namespace AzahariZaman\OctopusAI\Classes;
class Client
{
// Properties...
/**
* Client constructor.
*/
public function __construct()
{
// Initialization...
}
/**
* Generate a rewritten version of the input value.
*
* @param string $value The input value to be rewritten.
* @return string The rewritten value.
*/
public function rewrite($value)
// Additional methods...
/**
* Generate the response using the OpenAI API.
*
* @param string $value The input value for the prompt.
* @param string $mode The mode of operation ('rewrite', 'complete', 'summarize', 'elaborate').
* @param float $temperature The temperature for response generation (default is 0).
* @return string The generated response.
*/
protected function generateResponse($value, $mode, $temperature = 0.7): string
/**
* Generate the prompt for the OpenAI API based on the provided value and mode.
*
* @param string $value The input value for the prompt.
* @param string $mode The mode of operation ('rewrite', 'complete', 'summarize', 'elaborate').
* @return string The generated prompt.
*/
protected function makePrompt($value, $mode): string
// Additional helper methods...
}
use AzahariZaman\OctopusAI\Classes\Client;
// Instantiate the OctopusAI Client
$client = new Client();
Generate a rewritten version of the input value.
$rewrittenValue = $client->rewrite($inputValue);
Generate a completed version of the input sentence.
$completedSentence = $client->complete($inputSentence);
Generate a summarized version of the input sentences.
$summarizedResult = $client->summarize($inputSentences);
Generate an elaborated version of the input sentences.
$elaboratedResult = $client->elaborate($inputSentences);
Generate a response to a given prompt.
$response = $client->prompt($promptValue);
The Client
class is configured using settings retrieved from the OctopusAISettings
class. Ensure that the OpenAI API key and other relevant settings are properly configured in the OctopusAISettings class.
The Client
class provides a convenient way to interact with the OpenAI API for the OctopusAI project. It encapsulates the logic for generating responses in different modes, making it easy to integrate with various applications. Refer to the documentation for the OctopusAISettings
class to customize the behavior of the Client
based on specific project requirements.