├── .github └── workflows │ └── pylint.yml ├── .gitignore ├── .well-known └── ai-plugin.json ├── API-langchain.ipynb ├── LICENSE ├── LiteratureClient.py ├── README.md ├── logo.jpg ├── main.py ├── openapi.yaml ├── requirements.txt ├── resource ├── data_all.json ├── pres.json └── video.json └── test.py /.github/workflows/pylint.yml: -------------------------------------------------------------------------------- 1 | name: Pylint 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: ["3.10"] 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Set up Python ${{ matrix.python-version }} 14 | uses: actions/setup-python@v3 15 | with: 16 | python-version: ${{ matrix.python-version }} 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install -r requirements.txt 21 | - name: Run 22 | run: | 23 | python main.py 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /.well-known/ai-plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "schema_version": "v1", 3 | "name_for_human": "Ukr-School-Books", 4 | "name_for_model": "books", 5 | "description_for_human": "Interact with a books database. List, get content, and find books.", 6 | "description_for_model": "Plugin for interacting with a books database. You can list all books, get presentation, get biography of an author, get content of a book, get a random book, and get books that match a certain command.", 7 | "auth": { 8 | "type": "none" 9 | }, 10 | "api": { 11 | "type": "openapi", 12 | "url": "https://ukr-books-chat-gpt-plugin.vercel.app/openapi.yaml" 13 | }, 14 | "logo_url": "https://ukr-books-chat-gpt-plugin.vercel.app/logo.jpg", 15 | "contact_email": "I.Ludogovskyi@gmail.com", 16 | "legal_info_url": "https://butter-tangerine-f7b.notion.site/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=4" 17 | } 18 | -------------------------------------------------------------------------------- /API-langchain.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from langchain.chat_models import ChatOpenAI\n", 10 | "from langchain.agents import load_tools, initialize_agent\n", 11 | "from langchain.agents import AgentType\n", 12 | "from langchain.tools import AIPluginTool\n", 13 | "import os" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": null, 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "tool = AIPluginTool.from_plugin_url(\"https://ukr-books-chatgpt-plugin.illia56.repl.co/.well-known/ai-plugin.json\")\n" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": {}, 29 | "outputs": [], 30 | "source": [ 31 | "os.environ['OPENAI_API_KEY']=\"\"" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "model_name = 'gpt-4' # or gpt-3.5-turbo\n", 41 | "llm = ChatOpenAI(temperature=0, model_name=model_name)\n", 42 | "tools = load_tools([\"requests_all\"])\n", 43 | "tools += [tool]\n", 44 | "\n", 45 | "agent_chain = initialize_agent(\n", 46 | " tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True\n", 47 | ")" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "query = \"Give list of authors for 9 grade ukraian books\"\n", 57 | "agent_chain.run(query)" 58 | ] 59 | } 60 | ], 61 | "metadata": { 62 | "kernelspec": { 63 | "display_name": "Python 3", 64 | "language": "python", 65 | "name": "python3" 66 | }, 67 | "language_info": { 68 | "codemirror_mode": { 69 | "name": "ipython", 70 | "version": 3 71 | }, 72 | "file_extension": ".py", 73 | "mimetype": "text/x-python", 74 | "name": "python", 75 | "nbconvert_exporter": "python", 76 | "pygments_lexer": "ipython3", 77 | "version": "3.11.3" 78 | }, 79 | "orig_nbformat": 4 80 | }, 81 | "nbformat": 4, 82 | "nbformat_minor": 2 83 | } 84 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 OpenAI 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 | -------------------------------------------------------------------------------- /LiteratureClient.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import random as rnd 3 | import json 4 | 5 | 6 | class DB: 7 | def __init__(self, grade,type): 8 | type= 'Ukrainian' if 'ukr' in type.lower() else 'World`s' 9 | main_DB=json.load(open(f"resource/data_all.json"))[f'_{grade} grade {type}'] 10 | self.data_ = pd.DataFrame(main_DB[f'books']) 11 | self.pres_data = main_DB['pres'] 12 | self.authors =list(self.data_.columns) 13 | 14 | def list_all(self): 15 | 16 | text='' 17 | for item in self.authors: 18 | text+=f'📑{item}\n' 19 | for book in self.data_[item]['books'].keys(): 20 | # read_all=self.data_[item]['books'][book]['Читати повністю'].split('\n')[1] 21 | text+=f"--> {book}\n" #{read_all}\n 22 | return text 23 | 24 | def get_presentation(self): 25 | data={} 26 | for author in self.authors: 27 | PA=self.data_[self.data_[0].str.contains(author.lower())] 28 | if len(PA): 29 | data[f'🔖{author}']={} 30 | for name,link in zip(PA[1],PA[2]): 31 | data[f'🔖{author}'][name] = link 32 | return data 33 | def get_books(self, author): 34 | return list(self.data_[author]['books'].keys()) 35 | 36 | def get_bio(self, author): 37 | return dict(self.data_[author][:2]) 38 | 39 | def get_content(self, author, name): 40 | return self.data_[author]['books'].get(name) 41 | 42 | def get_rnd(self): 43 | self.rnd_auth=rnd.choice(self.authors) 44 | self.rnd_book=rnd.choice(self.get_books(self.rnd_auth)) 45 | BIO =self.get_bio(self.rnd_auth) 46 | BIO.update({'book':self.get_content(self.rnd_auth,self.rnd_book)}) 47 | return BIO 48 | 49 | def get_adding(self,command): 50 | modes = {'📔Shortly croped':'Shortly', '📗Review':'Review', '🔉Audiobooks':'Audiobook'} 51 | data={} 52 | for author in self.authors: 53 | data_={} 54 | for book in self.get_books(author): 55 | for key in self.get_content(author, book): 56 | if modes[command] == key: 57 | data_[f"{command[0]}{book}"] = f'{book}\n{self.get_content(author, book)[key]}' 58 | break 59 | if len(data_.keys()): 60 | data[f'{command[0]}{author}']=data_ 61 | return data 62 | # DF=DB('9 клас World`s') 63 | # for i in DF.authors: 64 | # print(DF.get_bio(i)) 65 | # # DF=DF[DF[0].str.contains('Свіфт')] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ukr-Books-ChatGPT-Plugin 2 | https://github.com/Illia-the-coder/Ukr-Books-ChatGPT-Plugin 3 | 4 | The Ukr-Books-ChatGPT-Plugin is a Python-based plugin designed to enhance the capabilities of OpenAI's ChatGPT model by integrating it with Ukrainian literature. The plugin fetches, processes, and formats Ukrainian literature data, allowing ChatGPT to generate responses based on this data. 5 | 6 | 7 | # [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)Overview 8 | 9 | ## Join us in spreading the rich Ukrainian literary tradition around the globe! 🌍💪 10 | 11 | https://github.com/Illia-the-coder/Ukr-Books-ChatGPT-Plugin/assets/101904816/2fdd6c97-fb8f-4cd0-80ad-ef0ea3624020 12 | 13 | 🔗 See our plugin in action [here](https://chat.openai.com/share/f2d7dcea-c965-4ad6-9e84-12334bc93120). 14 | 15 | No developer access to plugins yet? No worries! You can join the waiting list [here](https://openai.com/waitlist/plugins) 🕐. 16 | 17 | # [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)Free Access 18 | 19 | ## [Open Assistant Chat](https://open-assistant.io/chat) 20 | 21 | https://github.com/Illia-the-coder/Ukr-Books-ChatGPT-Plugin/assets/101904816/80c13592-3fae-4d06-8bde-4624b2d7a30e 22 | 23 | And guess what? You can access our plugin (Ukr-School-Books) absolutely FREE of charge! 💥 Follow this [link](https://ukr-books-chatgpt-plugin.illia56.repl.co/) or access it anytime via [Open Assistant Chat](https://open-assistant.io/chat) 📲 24 | 25 | ## [plugin.surf](https://plugin.surf/plugin/ukr-school-books) 26 | 27 | Get ready to level up your game with GPT-4! Now you can access our plugin for free. Check it out here: https://plugin.surf/plugin/ukr-school-books 28 | 29 | ## [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)Prerequisites 30 | 31 | Before you begin, ensure you have met the following requirements: 32 | 33 | - You have installed the latest version of Python. 34 | - You have a basic understanding of Python and Quart. 35 | 36 | ## [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)Installation 37 | 38 | To install the necessary dependencies, run the following command: 39 | 40 | ```python 41 | 42 | pip install -r requirements.txt 43 | 44 | ``` 45 | 46 | ## [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)Usage 47 | 48 | To start the server, run the following command: 49 | 50 | ``` 51 | python main.py 52 | 53 | ``` 54 | 55 | ## [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)API Endpoints 56 | 57 | - `/list_all//`: List all books for a specific grade and type. 58 | - `/get_books////`: Get books by a specific author for a specific grade and type. 59 | - `/get_presentation//`: Get presentation for a specific grade and type. 60 | - `/get_bio///`: Get biography of a specific author for a specific grade and type. 61 | 62 | ## [←](https://www.notion.so/Ukr-Books-ChatGPT-ad1258cbc91b40e5ad78fa89f414dc09?pvs=21)License 63 | 64 | This project is licensed under the MIT License. 65 | 66 | ``` 67 | 68 | This README file includes badges at the top for visual appeal, a table of contents for easy navigation, and sections for prerequisites, installation, and usage. It also includes the same API endpoints as before. 69 | ``` 70 | -------------------------------------------------------------------------------- /logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Illia-the-coder/Ukr-Books-ChatGPT-Plugin/8a262c45460aa643cb744c8b0347a8543e3f0a12/logo.jpg -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import quart 4 | import quart_cors 5 | from LiteratureClient import DB 6 | from quart import request 7 | from quart import redirect 8 | import csv 9 | import datetime 10 | 11 | app = quart_cors.cors( 12 | quart.Quart(__name__), allow_origin="https://chat.openai.com" 13 | ) 14 | 15 | # Define the CSV file path 16 | CSV_FILE_PATH = "requests_log.csv" 17 | 18 | def create_csv_file(): 19 | header = ["Timestamp", "Request Type", "Parameters"] 20 | with open(CSV_FILE_PATH, mode='w', newline='') as file: 21 | writer = csv.writer(file) 22 | writer.writerow(header) 23 | 24 | def save_request_to_csv(request_type, params): 25 | now = datetime.datetime.now().isoformat() 26 | with open(CSV_FILE_PATH, mode='a', newline='') as file: 27 | writer = csv.writer(file) 28 | writer.writerow([now, request_type, json.dumps(params)]) 29 | 30 | # Check if the CSV file exists, and create it if not 31 | if not os.path.exists(CSV_FILE_PATH): 32 | create_csv_file() 33 | 34 | @app.route("/list_all//", methods=["POST"]) 35 | async def list_all(grade, type): 36 | db = DB(grade, type) 37 | all_books = {'list all': db.list_all()} 38 | all_books['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade' 39 | all_books['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade' 40 | 41 | # Log the request to CSV 42 | save_request_to_csv("list_all", {"grade": grade, "type": type}) 43 | 44 | return quart.Response(response=json.dumps(all_books), status=200) 45 | 46 | @app.route("/get_books////", methods=["POST"]) 47 | async def get_books(grade, type, author): 48 | db = DB(grade, type) 49 | books = {'books': db.get_books(author)} 50 | index = db.authors.index(author) 51 | books['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}' 52 | books['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}' 53 | 54 | # Log the request to CSV 55 | save_request_to_csv("get_books", {"grade": grade, "type": type, "author": author}) 56 | 57 | return quart.Response(response=json.dumps(books), status=200) 58 | 59 | @app.route("/get_presentation//", methods=["POST"]) 60 | async def get_presentation(grade, type): 61 | db = DB(grade, type) 62 | presentation = db.get_presentation() 63 | presentation['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/pres' 64 | presentation['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/pres' 65 | 66 | # Log the request to CSV 67 | save_request_to_csv("get_presentation", {"grade": grade, "type": type}) 68 | 69 | return quart.Response(response=json.dumps(presentation), status=200) 70 | 71 | @app.route("/get_bio///", methods=["POST"]) 72 | async def get_bio(grade, type, author): 73 | db = DB(grade, type) 74 | bio = db.get_bio(author) 75 | index = db.authors.index(author) 76 | bio['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}' 77 | bio['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}' 78 | 79 | # Log the request to CSV 80 | save_request_to_csv("get_bio", {"grade": grade, "type": type, "author": author}) 81 | 82 | return quart.Response(response=json.dumps(bio), status=200) 83 | 84 | @app.route("/get_content////", methods=["POST"]) 85 | async def get_content(grade, type, author, name): 86 | db = DB(grade, type) 87 | content = db.get_content(author, name) 88 | index = db.authors.index(author) 89 | book_index = db.get_books(author).index(name) 90 | content['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}/book_ind={book_index}' 91 | content['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}/book_ind={book_index}' 92 | 93 | # Log the request to CSV 94 | save_request_to_csv("get_content", {"grade": grade, "type": type, "author": author, "name": name}) 95 | 96 | return quart.Response(response=json.dumps(content), status=200) 97 | 98 | @app.route("/get_rnd//", methods=["POST"]) 99 | async def get_rnd(grade, type): 100 | db = DB(grade, type) 101 | rnd = db.get_rnd() 102 | index = db.authors.index(db.rnd_auth) 103 | book_index = db.get_books(db.rnd_auth).index(db.rnd_book) 104 | rnd['Main web-site view eng'] = f'https://translate.google.com/translate?sl=uk&tl=en&u=https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}/book_ind={book_index}' 105 | rnd['Main web-site view ukr'] = f'https://literature2.illia56.repl.co/{("ukr" if "ukr" in type else "for")}/{grade}_grade/auth_ind={index}/book_ind={book_index}' 106 | 107 | # Log the request to CSV 108 | save_request_to_csv("get_rnd", {"grade": grade, "type": type}) 109 | 110 | return quart.Response(response=json.dumps(rnd), status=200) 111 | 112 | @app.route("/logo.jpg", methods=["GET"]) 113 | async def plugin_logo(): 114 | return redirect('https://res.cloudinary.com/dw8hy0djm/image/upload/v1689848999/zssvobkk1ziqj81fme3x.jpg') 115 | 116 | @app.get("/.well-known/ai-plugin.json") 117 | async def plugin_manifest(): 118 | host = request.headers['Host'] 119 | with open("./.well-known/ai-plugin.json") as f: 120 | text = f.read() 121 | return quart.Response(text, mimetype="text/json") 122 | 123 | @app.get("/openapi.yaml") 124 | async def openapi_spec(): 125 | host = request.headers['Host'] 126 | with open("openapi.yaml") as f: 127 | text = f.read() 128 | return quart.Response(text, mimetype="text/yaml") 129 | 130 | def main(): 131 | app.run(debug=True, host="0.0.0.0", port=5003) 132 | 133 | if __name__ == "__main__": 134 | main() 135 | -------------------------------------------------------------------------------- /openapi.yaml: -------------------------------------------------------------------------------- 1 | openapi: 3.0.1 2 | info: 3 | title: Ukr-School-Books 4 | description: A plugin that allows the user to interact with a books database. 5 | version: 'v1' 6 | servers: 7 | - url: https://ukr-books-chat-gpt-plugin.vercel.app 8 | paths: 9 | 10 | /list_all/{grade}/{type}: 11 | post: 12 | operationId: listAll 13 | parameters: 14 | - in: path 15 | name: grade 16 | schema: 17 | type: string 18 | required: true 19 | - in: path 20 | name: type 21 | schema: 22 | type: string 23 | required: true 24 | responses: 25 | '200': 26 | description: Returns a list of all books. 27 | 28 | /get_rnd/{grade}/{type}: 29 | post: 30 | operationId: getRnd 31 | parameters: 32 | - in: path 33 | name: grade 34 | schema: 35 | type: string 36 | required: true 37 | - in: path 38 | name: type 39 | schema: 40 | type: string 41 | required: true 42 | responses: 43 | '200': 44 | description: Returns a random book. 45 | 46 | /get_books/{grade}/{type}/{author}: 47 | post: 48 | operationId: getBooks 49 | parameters: 50 | - in: path 51 | name: grade 52 | schema: 53 | type: string 54 | required: true 55 | - in: path 56 | name: bookType 57 | schema: 58 | type: string 59 | required: true 60 | - in: path 61 | name: author 62 | schema: 63 | type: string 64 | required: true 65 | responses: 66 | '200': 67 | description: Returns a list of all books for this author. 68 | 69 | /get_bio/{grade}/{type}/{author}: 70 | post: 71 | operationId: getBio 72 | parameters: 73 | - in: path 74 | name: grade 75 | schema: 76 | type: string 77 | required: true 78 | - in: path 79 | name: type 80 | schema: 81 | type: string 82 | required: true 83 | - in: path 84 | name: author 85 | schema: 86 | type: string 87 | required: true 88 | responses: 89 | '200': 90 | description: Returns the biography of the author. 91 | 92 | /get_content/{grade}/{type}/{author}: 93 | post: 94 | operationId: getContent 95 | parameters: 96 | - in: path 97 | name: grade 98 | schema: 99 | type: string 100 | required: true 101 | - in: path 102 | name: type 103 | schema: 104 | type: string 105 | required: true 106 | - in: path 107 | name: author 108 | schema: 109 | type: string 110 | required: true 111 | responses: 112 | '200': 113 | description: Returns the content of the book. 114 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | quart 2 | quart-cors 3 | pandas -------------------------------------------------------------------------------- /test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from quart import Quart 3 | from main import app 4 | 5 | class LiteratureAppTestCase(unittest.IsolatedAsyncioTestCase): 6 | async def setUp(self): 7 | self.app = app.test_client() 8 | 9 | async def test_list_all(self): 10 | response = await self.app.post("/list_all/5/ukr") 11 | self.assertEqual(response.status_code, 200) 12 | data = await response.get_json() 13 | self.assertIn("list all", data) 14 | self.assertIn("Main web-site view eng", data) 15 | self.assertIn("Main web-site view ukr", data) 16 | 17 | async def test_get_books(self): 18 | response = await self.app.post("/get_books/5/ukr/John Doe/") 19 | self.assertEqual(response.status_code, 200) 20 | data = await response.get_json() 21 | self.assertIn("books", data) 22 | self.assertIn("Main web-site view eng", data) 23 | self.assertIn("Main web-site view ukr", data) 24 | 25 | async def test_get_presentation(self): 26 | response = await self.app.post("/get_presentation/5/ukr") 27 | self.assertEqual(response.status_code, 200) 28 | data = await response.get_json() 29 | self.assertIn("Main web-site view eng", data) 30 | self.assertIn("Main web-site view ukr", data) 31 | 32 | async def test_get_bio(self): 33 | response = await self.app.post("/get_bio/5/ukr/John Doe") 34 | self.assertEqual(response.status_code, 200) 35 | data = await response.get_json() 36 | self.assertIn("Main web-site view eng", data) 37 | self.assertIn("Main web-site view ukr", data) 38 | 39 | async def test_get_content(self): 40 | response = await self.app.post("/get_content/5/ukr/John Doe/Book Title") 41 | self.assertEqual(response.status_code, 200) 42 | data = await response.get_json() 43 | self.assertIn("Main web-site view eng", data) 44 | self.assertIn("Main web-site view ukr", data) 45 | 46 | async def test_get_rnd(self): 47 | response = await self.app.post("/get_rnd/5/ukr") 48 | self.assertEqual(response.status_code, 200) 49 | data = await response.get_json() 50 | self.assertIn("Main web-site view eng", data) 51 | self.assertIn("Main web-site view ukr", data) 52 | 53 | async def test_plugin_logo(self): 54 | response = await self.app.get("/logo.jpg") 55 | self.assertEqual(response.status_code, 200) 56 | self.assertEqual(response.content_type, "image/png") 57 | 58 | async def test_plugin_manifest(self): 59 | response = await self.app.get("/.well-known/ai-plugin.json") 60 | self.assertEqual(response.status_code, 200) 61 | self.assertEqual(response.content_type, "application/json") 62 | 63 | async def test_openapi_spec(self): 64 | response = await self.app.get("/openapi.yaml") 65 | self.assertEqual(response.status_code, 200) 66 | self.assertEqual(response.content_type, "text/yaml") 67 | 68 | if __name__ == "__main__": 69 | unittest.main() 70 | --------------------------------------------------------------------------------