Notion AI is a powerful artificial intelligence feature based on GPT-3 that is part of the productivity app Notion. You can use Notion AI within Notion itself, but there is currently no official API available.
This is an unofficial PHP client for the Notion AI API that makes it easy to interact with Notion AI in your PHP projects.
You can install the package via composer:
composer require albertcht/notion-ai
- Initialize a Notion AI instance
$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId');
- Set options of Guzzle client in the third paramter
See: https://docs.guzzlephp.org/en/stable/request-options.html
$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId', ['timeout' => 120]);
- Replace a PSR Http Client if needed
$client = new GuzzleHttp\Client();
$notion->setClient($client);
- Send a request with general
sendRequest
function
If some APIs are not wrapped in this package, you can interact with Notion AI by this function
$notion->sendRequest([
[
'type' => $promptType,
'pageTitle' => $pageTitle,
'selectedText' => $selectedText,
]
]);
- Send a request with stream response
// you can set buffer size of stream in the second parameter
$notion->stream(function ($output) {
echo $output;
if (ob_get_length()) {
ob_get_flush();
flush();
}
}, 128);
$notion->sendRequest([
[
'type' => $promptType,
'pageTitle' => $pageTitle,
'selectedText' => $selectedText,
]
]);
- Supported APIs
public function writeWithPrompt(string $promptType, string $selectedText, string $pageTitle = ''): ?string;
public function continueWriting(string $previousContent, string $pageTitle = '', string $restContent = ''): ?string;
public function helpMeEdit(string $prompt, string $selectedText, string $pageTitle = ''): ?string;
public function helpMeWrite(string $prompt, string $previousContent = '', string $pageTitle = '', string $restContent = ''): ?string;
public function helpMeDraft(string $prompt, string $previousContent = '', string $pageTitle = '', string $restContent = ''): ?string;
public function translate(string $text, string $language): ?string;
public function changeTone(string $text, string $tone): ?string;
public function summarize(string $selectedText, string $pageTitle = ''): ?string;
public function improveWriting(string $selectedText, string $pageTitle = ''): ?string;
public function fixSpellingGrammar(string $selectedText, string $pageTitle = ''): ?string;
public function explainThis(string $selectedText, string $pageTitle = ''): ?string;
public function makeLonger(string $selectedText, string $pageTitle = ''): ?string;
public function makeShorter(string $selectedText, string $pageTitle = ''): ?string;
public function findActionItems(string $selectedText, string $pageTitle = ''): ?string;
public function simplifyLanguage(string $selectedText, string $pageTitle = ''): ?string;
public function writeWithTopic(string $topic, string $prompt): ?string;
public function brainstormIdeas(string $prompt): ?string;
public function outline(string $prompt): ?string;
public function socialMediaPost(string $prompt): ?string;
public function creativeStory(string $prompt): ?string;
public function poem(string $prompt): ?string;
public function essay(string $prompt): ?string;
public function meetingAgenda(string $prompt): ?string;
public function pressRelease(string $prompt): ?string;
public function jobDescription(string $prompt): ?string;
public function salesEmail(string $prompt): ?string;
public function recruitingEmail(string $prompt): ?string;
public function prosConsList(string $prompt): ?string;
There are enums you can refer to when you call APIs:
composer test
- Get token from Notion
- Get space id from Notion
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
You can support me by a cup of coffee. An open-source project also relies on community's contribution. Any PRs are welcome to help maintain this package.
The MIT License (MIT). Please see License File for more information.