ChatGPT ile çalışan eklentiler için bir API anahtarı ayarlamanıza ve yinelenen bağımlılıkları yüklemenize olanak tanır.
Geliştirici kullanım kılavuzu
OpenAI API anahtarını alın$apiKey = \XF::options()->bsChatGptApiKey;
/** \Orhanerday\OpenAi\OpenAi $api */
$api = \XF::app()->container('chatGPT');
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,
])
);
fetchMessagesFromThread– Konudan bot için bağlamı yükler. Bot alıntıları, doğru bağlam için mesajlarına dönüştürülür.
public function fetchMessagesFromThread(
Thread $thread,
int $stopPosition = null, // Thread post position to which to load the context
?User $assistant = null, // Bot user to mark his messages in context
bool $transformAssistantQuotesToMessages = true, // If false, bot message quote messages will not be transformed into his messages
int $startPosition = null, // Thread post position from which to load the context
bool $removeQuotesFromAssistantMessages = true // Removes user post quotes from bot posts
)
public function wrapMessage(string $content, string $role = 'user'): array
/*
returns [
'content' => $preparedContent,
'role' => $role
]
*/
prepareContent– Bot için mesaj içeriğini hazırlayın (gereksiz BB kodlarını kaldırır).
getQuotes– Metinden alıntıları ayrıştırarak uygun bir forma getirir.
public function getQuotes(
string $text,
int $userId = null, // filter quotes by user id
int $postId = null, // filter quotes by post id
string $postType = 'post' // post type in quotes
): array
/*
returns [
[
'post_id' => int|null,
'user_id' => int|null,
'content' => string|null, (quote content)
'message' => string|null, (reply on quote, text which located below quote)
'match' => string (full quote match)
]
]
*/
removeQuotes– Metinden alıntıları kaldırın. Belirli gönderiler veya kullanıcılar için alıntıları kaldırabilir.
public function removeQuotes(
string $text,
int $userId = null,
int $postId = null,
string $postType = 'post'
): string