albertcht/notion-ai

Api Client of Notion AI in PHP

v0.1.0 2023-04-12 12:28 UTC

This package is auto-updated.

Last update: 2024-11-15 07:07:48 UTC


README

Latest Version on Packagist Tests Total Downloads

Demo Notion AI

About this package

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.

Installation

You can install the package via composer:

composer require albertcht/notion-ai

Usage

  • 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;

Enums

There are enums you can refer to when you call APIs:

Testing

composer test

How to get token and space id from Notion?

  • Get token from Notion

Screenshot of token.

  • Get space id from Notion

Screenshot of spaceId.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Donation

Buy Me A Coffee

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.

Credits

License

The MIT License (MIT). Please see License File for more information.