-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
29 lines (22 loc) · 879 Bytes
/
Copy pathindex.py
File metadata and controls
29 lines (22 loc) · 879 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
25
26
27
28
29
import openai
from dotenv import load_dotenv
from os import environ
import utils
def main():
load_dotenv()
openai.api_key = environ.get('OPENAI_API_KEY')
topic = utils.read_first_line('react_topics.md')
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": f"Resume this React topic in less than 750 words, show me the problem it solves, and show me an example in code: {topic}"}],
max_tokens=1000
)
index = utils.get_highest_number_in_folder("./topics")
file_path = f'./topics/{index + 1}. {topic}.md'
content = response.choices[0]["message"]["content"]
print(f'ChatGPT response:\n{content}')
utils.write_to_md_file(file_path, content)
utils.erase_first_line('react_topics.md')
return f"Created tutorial: {topic}"
if __name__ == '__main__':
main()