├── requirements.txt ├── LICENSE ├── README.md ├── .gitignore └── create_page.py /requirements.txt: -------------------------------------------------------------------------------- 1 | atlassian-python-api==3.34.* 2 | revChatGPT==4.* 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 silviopavanetto 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Confluence GPT 2 | This repository contains a Python script that uses ChatGPT to generate Confluence pages automatically. You can use this script to quickly create new pages by providing input text and customizing page elements such as the title, formatting, and content. The generated content can be published promptly to Confluence using the python APIs. 3 | 4 | 5 | # Disclaimer 6 | I am not affiliated with OpenAI or the ChatGPT product. 7 | This repository is not endorsed by or affiliated with OpenAI or ChatGPT. 8 | This is a personal project just for research purposes, to discover the capabilities of the new ChatGPT model released recently by OpenAI. 9 | 10 | 11 | # Usage 12 | 13 | To use the `create_page.py` script, you will need to have the `atlassian-python-api` and `revChatGPT` libraries installed. 14 | You can install this library using `pip install -r requirements.txt`. 15 | 16 | Once you have installed the required libraries and set the environment variables, use `python create_page.py` by providing the following informations when asked: 17 | 18 | - Your Confluence URL, username, and password: these will be used to authenticate to Confluence. 19 | - The input text that will be used as the basis for the Confluence page. This input text will be provided to ChatGPT to generate the page content. 20 | The desired title for the Confluence page. 21 | Any additional page elements, such as formatting or attachments, that you want to include in the page. 22 | 23 | The script will use this input to authenticate to Confluence, generate the page content using ChatGPT, and create a new Confluence page with the provided title and additional elements. The newly created page will be published to Confluence and can be accessed from your Confluence dashboard. 24 | 25 | To use the `create_page.py` script, you will need to set the following environment variables: 26 | 27 | - `JIRA_URL`: The URL for your JIRA instance. 28 | - `JIRA_USER`: Your JIRA username. 29 | - `JIRA_API_TOKEN`: Your JIRA API token. You can generate an API token by following the instructions [here](https://confluence.atlassian.com/cloud/api-tokens-938839638.html). 30 | - `OPENAI_ACCESS_TOKEN`: OpenAI access token used to authenticate to ChatGPT. In order to retrieve the access token, go to https://chat.openai.com/api/auth/session and get the value of "accessToken" variable. 31 | -------------------------------------------------------------------------------- /.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 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 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 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | .vscode/ 132 | 133 | .idea/ 134 | -------------------------------------------------------------------------------- /create_page.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import os 3 | from typing import Tuple 4 | 5 | from atlassian import Confluence 6 | from revChatGPT.V1 import Chatbot 7 | 8 | 9 | def get_confluence_connection() -> Confluence: 10 | confluence_connection = Confluence( 11 | url=os.environ.get("JIRA_URL", None), 12 | username=os.environ.get("JIRA_USER", None), 13 | password=os.environ.get("JIRA_API_TOKEN", None), 14 | cloud=True, 15 | ) 16 | return confluence_connection 17 | 18 | 19 | def get_openai_connection() -> Chatbot: 20 | access_token = os.environ.get("OPENAI_ACCESS_TOKEN", None) 21 | chatbot = Chatbot({"access_token": access_token}) 22 | return chatbot 23 | 24 | 25 | def get_user_inputs() -> Tuple[str, str, str, str, str, str]: 26 | # get the page title 27 | page_title = input("Enter the page title: ") 28 | # get the page space 29 | page_space = input("Enter the space name for the page: ") 30 | # get the page parent 31 | page_parent = input( 32 | "Enter the parent page id for the page, leave empty if you want to put the page in the root space: " 33 | ) 34 | # get the page content 35 | page_topic = input("Write the main topic of the page: ") 36 | # get the page paragraphs 37 | page_structure = input("Write a list of the paragraphs you want in the page: ") 38 | # get the page requirements 39 | page_requirements = input("Write any additional requirements for the page: ") 40 | 41 | page_parent = None if page_parent.strip() == "" else page_parent 42 | return ( 43 | page_title, 44 | page_space, 45 | page_parent, 46 | page_topic, 47 | page_structure, 48 | page_requirements, 49 | ) 50 | 51 | 52 | def main(): 53 | # set up logging for print on console - this is optional 54 | logging.basicConfig( 55 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", 56 | level=logging.DEBUG, 57 | ) 58 | 59 | logging.info("Initializing Confluence client") 60 | confluence = get_confluence_connection() 61 | 62 | logging.info("Initializing OpenAI client") 63 | chatbot = get_openai_connection() 64 | 65 | logging.info("Getting page constraints from user") 66 | ( 67 | page_title, 68 | page_space, 69 | page_parent, 70 | page_topic, 71 | page_structure, 72 | page_requirements, 73 | ) = get_user_inputs() 74 | 75 | logging.info("Generating page content with GPT-3") 76 | chat_message_content = ( 77 | f"Write a well formatted Confluence page using the markdown syntax.\n" 78 | f"The main topic of the page is {page_topic}.\nThese are the paragraphs that have to be in the page:\n" 79 | f"{page_structure}\n\nIn addition, i want you to apply these constraints for writing the page: " 80 | f"\n\n'{page_requirements}'" 81 | ) 82 | 83 | chat_response = "" 84 | for data in chatbot.ask(chat_message_content): 85 | chat_response = data["message"] 86 | 87 | logging.info("Creating page in Confluence") 88 | # create a confluence page with the title and content 89 | confluence.create_page( 90 | space=page_space, 91 | title=page_title, 92 | body=chat_response, 93 | parent_id=page_parent, 94 | type="page", 95 | representation="wiki", 96 | editor="v2", 97 | full_width=False, 98 | ) 99 | logging.info( 100 | f"Page created successfully in space: {page_space}, with title: {page_title}" 101 | ) 102 | 103 | 104 | if __name__ == "__main__": 105 | main() 106 | --------------------------------------------------------------------------------