├── LICENSE ├── Notion_to_Chatbot.ipynb └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Anil Chandra Naidu Matcha 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Notion_to_Chatbot.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [], 7 | "authorship_tag": "ABX9TyONKGQWGXfxDcJVvzPuRuWH", 8 | "include_colab_link": true 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | }, 14 | "language_info": { 15 | "name": "python" 16 | } 17 | }, 18 | "cells": [ 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "id": "view-in-github", 23 | "colab_type": "text" 24 | }, 25 | "source": [ 26 | "\"Open" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "id": "wONp_EGeVMLq" 34 | }, 35 | "outputs": [], 36 | "source": [ 37 | "!pip install langchain openai chromadb tiktoken" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "source": [ 43 | "from langchain.document_loaders import NotionDBLoader\n", 44 | "\n", 45 | "loader = NotionDBLoader(\n", 46 | " integration_token=\"notion-key\",\n", 47 | " database_id=\"database-id\",\n", 48 | " request_timeout_sec=30, # optional, defaults to 10\n", 49 | ")\n", 50 | "\n", 51 | "docs = loader.load()" 52 | ], 53 | "metadata": { 54 | "id": "f6PzpRWvVRQQ" 55 | }, 56 | "execution_count": 7, 57 | "outputs": [] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "source": [ 62 | "from langchain.chains import RetrievalQA\n", 63 | "from langchain.embeddings.openai import OpenAIEmbeddings\n", 64 | "from langchain.llms import OpenAI\n", 65 | "from langchain.text_splitter import CharacterTextSplitter\n", 66 | "from langchain.vectorstores import Chroma\n", 67 | "import os\n", 68 | "from langchain.docstore.document import Document\n", 69 | "os.environ[\"OPENAI_API_KEY\"] = \"openai-key\"\n", 70 | "\n", 71 | "text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)\n", 72 | "texts = text_splitter.split_documents(docs)\n", 73 | "texts = [Document(page_content=x.page_content) for x in texts]" 74 | ], 75 | "metadata": { 76 | "id": "rv08JkYDWJNc" 77 | }, 78 | "execution_count": 23, 79 | "outputs": [] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "source": [ 84 | "embeddings = OpenAIEmbeddings()\n", 85 | "docsearch = Chroma.from_documents(texts, embeddings)\n", 86 | "\n", 87 | "qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type=\"stuff\", retriever=docsearch.as_retriever())" 88 | ], 89 | "metadata": { 90 | "id": "VxO11rqVW7nO" 91 | }, 92 | "execution_count": 25, 93 | "outputs": [] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "source": [ 98 | "qa.run(\"What is UUKI ?\")" 99 | ], 100 | "metadata": { 101 | "colab": { 102 | "base_uri": "https://localhost:8080/", 103 | "height": 53 104 | }, 105 | "id": "ccvyvCc_YbwK", 106 | "outputId": "70e70327-5fbd-4b68-de9e-65be2d45e97d" 107 | }, 108 | "execution_count": 27, 109 | "outputs": [ 110 | { 111 | "output_type": "stream", 112 | "name": "stderr", 113 | "text": [ 114 | "WARNING:chromadb.db.index.hnswlib:Number of requested results 4 is greater than number of elements in index 1, updating n_results = 1\n" 115 | ] 116 | }, 117 | { 118 | "output_type": "execute_result", 119 | "data": { 120 | "text/plain": [ 121 | "' UUKI is a community platform for creators.'" 122 | ], 123 | "application/vnd.google.colaboratory.intrinsic+json": { 124 | "type": "string" 125 | } 126 | }, 127 | "metadata": {}, 128 | "execution_count": 27 129 | } 130 | ] 131 | } 132 | ] 133 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notion to Chatbot 2 | 3 | Chat with any Notion document. 4 | 5 | Easily input the document content you'd like to chat with. Instant answers. Ask questions, extract information, and summarize documents with AI. Sources included. 6 | 7 | ### Getting Started 8 | 9 | Code is up now, ⭐ (Star) the repo to receive updates 10 | 11 | Replit and streamlit version coming soon 12 | 13 | Follow [Anil Chandra Naidu Matcha](https://twitter.com/matchaman11) on twitter for updates 14 | 15 | Subscribe to https://www.youtube.com/@AnilChandraNaiduMatcha for more such video tutorials 16 | 17 | ### Also check 18 | 19 | [Chat with PDF code](https://github.com/Anil-matcha/ChatPDF) 20 | 21 | [Chat with Website code](https://github.com/Anil-matcha/Website-to-Chatbot) 22 | 23 | [Chat with CSV code](https://github.com/Anil-matcha/Chat-With-Excel) 24 | 25 | [ChatGPT in Discord code](https://github.com/Anil-matcha/DiscordGPT) 26 | --------------------------------------------------------------------------------