Skip to content

Seamlessly integrate Notion with large language models (LLMs) - developed by Assistant Engine.

Notifications You must be signed in to change notification settings

AssistantEngine/open-functions-notion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notion Open Function

The Notion Open Function is an implementation of the Open Functions architecture designed to seamlessly connect to Notion. It enables language models (LLMs) to interact with Notion—listing databases and pages, retrieving database details, creating and updating pages, managing content blocks, and more—through a simple and structured interface.

Installation

To install the Notion Open Function, simply use Composer:

composer require assistant-engine/open-functions-notion

Usage

Using the OpenAI PHP SDK

Below is a basic example of how to use the Notion Open Function directly with the OpenAI PHP SDK:

<?php

use AssistantEngine\OpenFunctions\Notion\NotionOpenFunction;
use OpenAI;

// Set up your Notion integration API key
$apiKey = env('NOTION_API_KEY');  // Your Notion integration token

// Initialize the Notion Open Function
$notionFunction = new NotionOpenFunction($apiKey);

// Generate function definitions (for tool integration with an LLM)
$functionDefinitions = $notionFunction->generateFunctionDefinitions();

$client = OpenAI::client(env('OPENAI_TOKEN'));

$result = $client->chat()->create([
    'model'    => 'gpt-4o',
    'messages' => [],
    'tools'    => $functionDefinitions
]);

$choice = $result->choices[0];

if ($choice->finishReason === 'tool_calls') {
    $toolCalls = processToolCalls($choice->message->toolCalls, $notionFunction);
} 

function processToolCalls($toolCalls, $notionFunction)
{
    $result = [];

    foreach ($toolCalls as $toolCall) {
        // Extract the function name and arguments
        $functionName = $toolCall->function->name;
        $functionArgs = json_decode($toolCall->function->arguments, true);

        $response = $notionFunction->callMethod($functionName, $functionArgs);
        $result[] = $response;
    }

    return $result;
}

Using the Filament Assistant Plugin

The Notion Open Function can also be integrated as a tool within the Filament Assistant Plugin. To add it, include the following configuration in your config/filament-assistant.php file:

// inside config/filament-assistant.php

'tools' => [
    'notion' => [
        'namespace'   => 'notion',
        'description' => 'This tool allows you to interact with your Notion workspace to manage databases, pages, and content blocks.',
        'tool'        => function () {
            $apiKey = env('NOTION_API_KEY');
            return new \AssistantEngine\OpenFunctions\Notion\NotionOpenFunction($apiKey);
        },
    ]
]

With this configuration in place, your assistant can directly utilize the Notion tool to manage databases, pages, and content blocks.

Demo Assistant Example

Methods

Method Description Parameters
listDatabases List all databases in the specified Notion workspace. None (the workspace is defined by the API key configuration)
listPages List all pages in the specified Notion workspace. None (the workspace is defined by the API key configuration)
getDatabase Retrieve details of the specified database in the Notion workspace. databaseId: string (required) – The ID of the database to retrieve.
createPage Create a new page in Notion. parentId: string (required) – The ID of the parent page or database where the new page will be created.
data: object (required) – Must include:
title: string
content: array – Each item is an object with:
  • type: string (enum of supported block types)
  • text: string
updatePageTitle Update the title of an existing page in Notion. pageId: string (required) – The ID of the page to update.
newTitle: string (required) – The new title for the page.
searchPages Search pages in Notion with a query. query: string (required) – The search query.
retrieveBlockContent Retrieve the content of a block in Notion. blockId: string (required) – The ID of the block to retrieve.
updateBlockContent Update multiple block contents in Notion. blockUpdates: array (required) – An array of block updates. Each update should include:
id: string (required) – The ID of the block to update.
type: string (required, enum of supported block types)
text: string (required) – New text content for the block.
addBlockContent Add new content blocks to a parent block or page in Notion. parentId: string (required) – The ID of the parent block or page.
blocks: array (required) – An array of new content blocks. Each block should include:
type: string (required, enum of supported block types)
text: string (required) – The text content of the block.
deleteBlockContent Delete a block in Notion by its ID. blockId: string (required) – The ID of the block to delete.

More Projects

We’ve created more repositories to simplify AI integration and enhance tool calling with large language models:

  • Open Functions Core: Provides a standardized way to implement and invoke functions for tool calling with LLMs.

We are a young startup aiming to make it easy for developers to add AI to their applications. We welcome feedback, questions, comments, and contributions. Feel free to contact us at contact@assistant-engine.com.

Consultancy & Support

Do you need assistance integrating Open Functions into your application or help setting it up?
We offer consultancy services to help you get the most out of our package, whether you’re just getting started or optimizing an existing setup.

Reach out to us at contact@assistant-engine.com.

Contributing

We welcome contributions from the community! Feel free to submit pull requests, open issues, and help us improve the package.

License

This project is licensed under the MIT License. Please see License File for more information.

About

Seamlessly integrate Notion with large language models (LLMs) - developed by Assistant Engine.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages