-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_readme.py
executable file
·59 lines (46 loc) · 1.47 KB
/
generate_readme.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
#!/usr/bin/env python3
import openai
import os
import sys
# OpenAI API key from the system environment variable
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_readme(project_name):
"""
Generate a README file for a project using the OpenAI API.
"""
prompt = f"""
Write a detailed README file for a project named "{project_name}".
Include the following sections:
Explain "{project_name}" in a few sentences.
1. Project Description
2. Installation Instructions
3. Usage Instructions
4. Contributing Guidelines
5. License Information
"""
res = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
],
max_tokens=1000
)
return res.choices[0].message['content'].strip()
def main():
"""
Main function to generate the README file for a project.
"""
if len(sys.argv) == 1:
print("Usage: Add the Project Name as an argument.")
sys.exit(1)
elif len(sys.argv) != 2:
print("Usage: Add the Project Name as a single argument.")
sys.exit(1)
project_name = sys.argv[1]
readme_content = generate_readme(project_name)
with open("README.md", "w") as readme_file:
readme_file.write(readme_content)
print("README.md file has been generated successfully!")
if __name__ == "__main__":
main()