1. Go to this page and download the library: Download saassdk/gptsdk-php 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/ */
saassdk / gptsdk-php example snippets
class CustomLogger implements AILogger {
public function (AiRequest $aiRequest): AiRequest {
// Custom log handling logic
echo $message;
}
}
class CustomCompiler implements PromptCompiler {
public function compile(AiRequest $aiRequest): array {
// Custom compilation logic
return str_replace(array_keys($variables), array_values($variables), $template);
}
}
class CustomVendor implements AIVendor {
public function complete(AiRequest $aiRequest): ResponseInterface {
// Custom API integration logic
}
}
bash
composer
php
use Gptsdk\AI\AnthropicAIVendor;
use Gptsdk\AI\CompletionAi;
use Gptsdk\AI\OpenAIVendor;
use Gptsdk\Compilers\DoubleBracketsPromptCompiler;
use Gptsdk\Enum\CompilerType;
use Gptsdk\Storage\GithubPromptStorage;
use Gptsdk\Types\AiRequest;
use Symfony\Component\HttpClient\HttpClient;
use Gptsdk\Storage\TempLocalPromptStorage;
ate()),
'anthropic' => new AnthropicAIVendor(HttpClient::create())
],
[
CompilerType::DOUBLE_BRACKETS->value => new DoubleBracketsPromptCompiler()
],
new GithubPromptStorage(
HttpClient::create(),
$githubOwner,
$githubRepositoryName,
$githubToken,
$tempLocalPromptStorage
)
);
print_r(
$completionAi->complete([
new AiRequest(
apiKey: $openAiToken,
aiVendor: 'openai',
llmOptions: ['model' => 'gpt-3.5-turbo'],
promptPath: 'first1.prompt',
variableValues: [
'variable1' => 'Hello'
]
)
])[0]->plainResponse
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.