Addon 2x [021] ChatGPT Bots - Thêm Bot ChatGPT cho XenForo 2 1.1.0

PVS

Super Moderator
Thành viên BQT
Tham gia
28/02/2015
Bài viết
16,728
Được Like
12,680
[021] ChatGPT Bots - Thêm Bot ChatGPT cho XenForo 2 1.1.0
Add-on này cung cấp các chức năng trợ giúp để làm việc với ChatGPT.
Nó cho phép bạn đặt key API cho các add-on hoạt động với ChatGPT và tránh tải các phần phụ thuộc trùng lặp.

Hướng dẫn sử dụng dành cho nhà phát triển

Nhận key API OpenAI
PHP:
$apiKey = \XF::options()->bsChatGptApiKey;

Nhận API OpenAI
PHP:
/** \Orhanerday\OpenAi\OpenAi $api */
$api = \XF::app()->container('chatGPT');

Nhận trả lời từ 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,
    ])
);

Kho lưu trữ tin nhắn

fetchMessagesFromThread – Tải ngữ cảnh cho bot từ chủ đề. Các câu trích dẫn của bot được chuyển thành tin nhắn của họ cho đúng ngữ cảnh.
PHP:
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
)

wrapMessage – Tạo mảng tin nhắn, chuẩn bị nội dung cho bot (loại bỏ BB code không cần thiết).
PHP:
public function wrapMessage(string $content, string $role = 'user'): array
  
/*
returns [
    'content' => $preparedContent,
    'role' => $role
]
*/

prepareContent – Soạn nội dung tin nhắn cho bot (loại bỏ BB code không cần thiết).
getQuotes – Phân tích các trích dẫn từ văn bản, đưa nó về dạng thuận tiện.
PHP:
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 - Xóa dấu ngoặc kép khỏi văn bản. Có thể xóa dấu ngoặc kép cho bài đăng hoặc người dùng cụ thể.
PHP:
public function removeQuotes(
    string $text,
    int $userId = null,
    int $postId = null,
    string $postType = 'post'
): string

Options.png

Chúc các bạn thành công.


Nguồn: xenforo.com​
 

Đính kèm

  • BS-ChatGPTBots-1.1.0.zip
    121.3 KB · Lượt xem: 32

Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mr. Tuấn

Mobile/Zalo: 0988 488 096

Telegram: bluekpro

Email: [email protected]

Nhà Tài Trợ

Mút Xốp Không Gian
pallet Thịnh Phát
Top Bottom