-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_doc.py
More file actions
24 lines (19 loc) · 805 Bytes
/
Copy pathcreate_doc.py
File metadata and controls
24 lines (19 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os
import openai
openai.api_key=os.environ['OPENAI_API_KEY']
def create_doc():
system_message = "You are a professional technical documentation writer. The user will provide text from which you should create a documentation"
model = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": system_message}, {"role": "user", "content": _read_text()}])
response = model['choices'][0]['message']['content']
_write(response)
def _write(text):
with open("doc.txt", "w") as file:
file.write(text)
def _read_text():
current_path = os.getcwd()
file_name = "text.txt"
file_path = os.path.join(current_path, file_name)
with open(file_path, "r") as file:
return file.read()
if __name__ == "__main__":
create_doc()