This repository was archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
V1 Advanced examples
耗子 edited this page Mar 31, 2023
·
4 revisions
V1 supports the ChatGPT Plus plan, you can pass true
to the third parameter when calling addAccount
.
<?php
use HaoZiTeam\ChatGPT\V1 as ChatGPTV1;
$chatGPT = new ChatGPTV1();
$chatGPT->addAccount('<your_access_token>', 'first', true);
$answer = $chatGPT->ask('Hello, how are you?');
Multi-account polling can effectively solve the rate limit problem caused by a single account.
<?php
use HaoZiTeam\ChatGPT\V1 as ChatGPTV1;
$chatGPT = new ChatGPTV1();
$chatGPT->addAccount('<your_access_token>', 'first');
$chatGPT->addAccount('<your_access_token>', 'second');
$answer = $chatGPT->ask('Hello, how are you?', null, null, 'first', false);
Among them, the name can be left blank, and an account will be randomly selected automatically. At the same time, the returned array contains the name of the current account, and you can control the flow based on this name to prevent the account from being banned.
V1 supports conversation. After the request is successful, it will return the conversation_id
and the current message_id
. Pass these two IDs in the next request to contact the context.
<?php
use HaoZiTeam\ChatGPT\V1 as ChatGPTV1;
$chatGPT = new ChatGPTV1();
$chatGPT->addAccount('<your_access_token>');
$answer = $chatGPT->ask('Hello, how are you?');
$answer2 = $chatGPT->ask('What can you do?', $answer['conversation_id'], $answer['parent_id']);
All interfaces of V1 are listed here, you can call them as needed.
<?php
use HaoZiTeam\ChatGPT\V1 as ChatGPTV1;
$chatGPT = new ChatGPTV1('<base_url>', '<time_out>'); // Global settings
$chatGPT->addAccount('<your_access_token>', '<name>', '<paid>'); // Add an account to use
$chatGPT->getAccount('<name>'); // Get an account's info
$chatGPT->getAccounts(); // Get all account's info
$chatGPT->ask('<prompt>', '<conversation_id>', '<parent_id>', '<account>', '<stream>'); // Ask to ChatGPT
$chatGPT->getConversations('<offset>', '<limit>', '<account>'); // Get an account's conversation list
$chatGPT->getConversationMessages('<conversation_id>', '<account>'); // Get a messages list for an account's conversation
$chatGPT->generateConversationTitle('<conversation_id>', '<message_id>', '<account>'); // Generate a conversation title by a message
$chatGPT->updateConversationTitle('<conversation_id>', '<title>', '<account>'); // Change a conversation's title
$chatGPT->deleteConversation('<conversation_id>', '<account>'); // Delete a conversation
$chatGPT->clearConversations('<account>'); // Clear an account's conversations