-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcreate_page.py
105 lines (87 loc) · 3.1 KB
/
create_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import logging
import os
from typing import Tuple
from atlassian import Confluence
from revChatGPT.V1 import Chatbot
def get_confluence_connection() -> Confluence:
confluence_connection = Confluence(
url=os.environ.get("JIRA_URL", None),
username=os.environ.get("JIRA_USER", None),
password=os.environ.get("JIRA_API_TOKEN", None),
cloud=True,
)
return confluence_connection
def get_openai_connection() -> Chatbot:
access_token = os.environ.get("OPENAI_ACCESS_TOKEN", None)
chatbot = Chatbot({"access_token": access_token})
return chatbot
def get_user_inputs() -> Tuple[str, str, str, str, str, str]:
# get the page title
page_title = input("Enter the page title: ")
# get the page space
page_space = input("Enter the space name for the page: ")
# get the page parent
page_parent = input(
"Enter the parent page id for the page, leave empty if you want to put the page in the root space: "
)
# get the page content
page_topic = input("Write the main topic of the page: ")
# get the page paragraphs
page_structure = input("Write a list of the paragraphs you want in the page: ")
# get the page requirements
page_requirements = input("Write any additional requirements for the page: ")
page_parent = None if page_parent.strip() == "" else page_parent
return (
page_title,
page_space,
page_parent,
page_topic,
page_structure,
page_requirements,
)
def main():
# set up logging for print on console - this is optional
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.DEBUG,
)
logging.info("Initializing Confluence client")
confluence = get_confluence_connection()
logging.info("Initializing OpenAI client")
chatbot = get_openai_connection()
logging.info("Getting page constraints from user")
(
page_title,
page_space,
page_parent,
page_topic,
page_structure,
page_requirements,
) = get_user_inputs()
logging.info("Generating page content with GPT-3")
chat_message_content = (
f"Write a well formatted Confluence page using the markdown syntax.\n"
f"The main topic of the page is {page_topic}.\nThese are the paragraphs that have to be in the page:\n"
f"{page_structure}\n\nIn addition, i want you to apply these constraints for writing the page: "
f"\n\n'{page_requirements}'"
)
chat_response = ""
for data in chatbot.ask(chat_message_content):
chat_response = data["message"]
logging.info("Creating page in Confluence")
# create a confluence page with the title and content
confluence.create_page(
space=page_space,
title=page_title,
body=chat_response,
parent_id=page_parent,
type="page",
representation="wiki",
editor="v2",
full_width=False,
)
logging.info(
f"Page created successfully in space: {page_space}, with title: {page_title}"
)
if __name__ == "__main__":
main()