albertcht/notion-ai

Notion AI的PHP API客户端

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

This package is auto-updated.

Last update: 2024-09-15 06:50:31 UTC


README

Latest Version on Packagist Tests Total Downloads

Demo Notion AI

关于此包

Notion AI是一个基于GPT-3的强大人工智能功能,是生产力应用Notion的一部分。您可以在Notion内部使用Notion AI,但目前还没有官方API可用。

这是一个Notion AI API的非官方PHP客户端,可以轻松地在您的PHP项目中与Notion AI交互。

安装

您可以通过composer安装此包

composer require albertcht/notion-ai

用法

  • 初始化一个Notion AI实例
$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId');
  • 在第三个参数中设置Guzzle客户端的选项

参见:https://docs.guzzlephp.org/en/stable/request-options.html

$notion = new AlbertCht\NotionAi\NotionAi('token', 'spaceId', ['timeout' => 120]);
  • 如有需要,替换PSR Http客户端
$client = new GuzzleHttp\Client();
$notion->setClient($client);
  • 使用通用sendRequest函数发送请求

如果您需要使用未在此包中封装的API,您可以通过此函数与Notion AI交互

$notion->sendRequest([
    [
        'type' => $promptType,
        'pageTitle' => $pageTitle,
        'selectedText' => $selectedText,
    ]
]);
  • 使用流响应发送请求
// 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,
    ]
]);
  • 支持的API
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;

枚举

在调用API时,您可以参考以下枚举

测试

composer test

如何从Notion获取token和space id?

  • 从Notion获取token

Screenshot of token.

  • 从Notion获取space id

Screenshot of spaceId.

变更日志

请参阅CHANGELOG以获取最近更改的更多信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全漏洞

请参阅我们的安全策略以了解如何报告安全漏洞。

捐赠

Buy Me A Coffee

您可以通过一杯咖啡支持我。开源项目也依赖于社区的贡献。任何PR都欢迎帮助维护此包。

鸣谢

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。