- Compatible XF Versions
- 2.0
- 2.1
- 2.2
This add-on provides helper functions for working with ChatGPT.
It allows you to set an API key for add-ons that work with ChatGPT and avoid loading duplicate dependencies.
Get the OpenAI API key
Get OpenAI API
Get reply from ChatGPT
It allows you to set an API key for add-ons that work with ChatGPT and avoid loading duplicate dependencies.
Developer usage guide
Get the OpenAI API key
PHP:
$apiKey = \XF::options()->bsChatGptApiKey;
Get OpenAI API
PHP:
/** \Orhanerday\OpenAi\OpenAi $api */
$api = \XF::app()->container('chatGPT');
Get reply from ChatGPT
PHP:
use BS\ChatGPTBots\Response;
/** \Orhanerday\OpenAi\OpenAi $api */
$api = \XF::app()->container('chatGPT');
$messages = [
['role' => 'user', 'content' => 'Hello!']
];
$reply = Response::getReply(
$api->chat([
'model' => 'gpt-3.5-turbo',
'messages' => $messages,
'temperature' => 1.0,
'max_tokens' => 420,
'frequency_penalty' => 0,
'presence_penalty' => 0,
])
);