Skip to content

Commit 33f05e3

Browse files
committed
Add basic project setup
0 parents  commit 33f05e3

10 files changed

+1230
-0
lines changed

.gitignore

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/python
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
3+
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# poetry
102+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103+
# This is especially recommended for binary packages to ensure reproducibility, and is more
104+
# commonly ignored for libraries.
105+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106+
#poetry.lock
107+
108+
# pdm
109+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110+
#pdm.lock
111+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112+
# in version control.
113+
# https://pdm.fming.dev/#use-with-ide
114+
.pdm.toml
115+
116+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117+
__pypackages__/
118+
119+
# Celery stuff
120+
celerybeat-schedule
121+
celerybeat.pid
122+
123+
# SageMath parsed files
124+
*.sage.py
125+
126+
# Environments
127+
.env
128+
.venv
129+
env/
130+
venv/
131+
ENV/
132+
env.bak/
133+
venv.bak/
134+
135+
# Spyder project settings
136+
.spyderproject
137+
.spyproject
138+
139+
# Rope project settings
140+
.ropeproject
141+
142+
# mkdocs documentation
143+
/site
144+
145+
# mypy
146+
.mypy_cache/
147+
.dmypy.json
148+
dmypy.json
149+
150+
# Pyre type checker
151+
.pyre/
152+
153+
# pytype static type analyzer
154+
.pytype/
155+
156+
# Cython debug symbols
157+
cython_debug/
158+
159+
# PyCharm
160+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162+
# and can be added to the global gitignore or merged into this file. For a more nuclear
163+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164+
#.idea/
165+
166+
### Python Patch ###
167+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
168+
poetry.toml
169+
170+
# ruff
171+
.ruff_cache/
172+
173+
# LSP config files
174+
pyrightconfig.json
175+
176+
# End of https://www.toptal.com/developers/gitignore/api/python
177+

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# create-readme
2+
3+
create-readme is a tool that allows users to quickly and easily create README files with ChatGPT. By asking users a set of questions, create-readme generates a README based on the answers, eliminating the need to manually open OpenAI's website and type the prompt.
4+
5+
## Key Features
6+
7+
- Simple command-based interface for generating README files
8+
- Efficient and time-saving solution compared to manually typing prompts
9+
- Effortless use - the tool asks you questions, you don't have to worry about describing everything in detail to it
10+
11+
## Installation
12+
13+
To install create-readme, run the following command:
14+
15+
```shell
16+
pipx install create-readme
17+
```
18+
19+
## Usage
20+
21+
To use create-readme, follow these steps:
22+
23+
1. Open your terminal.
24+
2. Run the command:
25+
26+
```shell
27+
create-readme my-awesome-project
28+
```
29+
30+
3. Answer the prompted questions to provide the necessary information for the README file generation.
31+
4. Once you have answered all the questions, create-readme will generate a README file based on your inputs.
32+
33+
## Example
34+
35+
An example of a generated README is the file you're reading right now - it was manually cleaned up, but most of it is generated.
36+

create_readme/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""Generate READMEs."""
2+
from .generator import Generator
3+
4+
__all__ = ["Generator"]

create_readme/generator.py

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
"""Generate READMEs."""
2+
import contextlib
3+
import json
4+
import os
5+
6+
import openai
7+
8+
from .multiline_input import multiline_input
9+
from .prompts import Question, questions_prompt, readme_prompt
10+
11+
12+
class Generator:
13+
"""README generator."""
14+
15+
def __init__(
16+
self,
17+
project_name: str,
18+
config_path: str | None = None,
19+
model: str = "gpt-3.5-turbo-0613",
20+
):
21+
"""Initialize the generator.
22+
23+
Args:
24+
project_name: The name of the project.
25+
"""
26+
self.project_name = project_name
27+
self.questions: list[Question] = []
28+
self.config_path = config_path
29+
self.model = model
30+
31+
@property
32+
def config_file_path(self) -> str | None:
33+
"""Get the path to the configuration file.
34+
35+
Returns:
36+
The path to the configuration file.
37+
"""
38+
if not self.config_path:
39+
return None
40+
return self.config_path + f"/{self.project_name}.json"
41+
42+
def load_config(self):
43+
"""Load the configuration."""
44+
if not self.config_file_path:
45+
return
46+
with contextlib.suppress(FileNotFoundError):
47+
with open(self.config_file_path, "r", encoding="utf-8") as config_file:
48+
config = json.load(config_file)
49+
self.questions = [
50+
Question(question=question["question"], answer=question["answer"])
51+
for question in config["questions"]
52+
]
53+
54+
def save_config(self):
55+
"""Save the configuration."""
56+
if not self.config_file_path:
57+
return
58+
with open(self.config_file_path, "w", encoding="utf-8") as config_file:
59+
json.dump(
60+
{"questions": [question.dict() for question in self.questions]},
61+
config_file,
62+
)
63+
64+
def ask_load(self):
65+
"""Ask the user if they want to load the configuration."""
66+
if not self.config_file_path:
67+
return
68+
if not os.path.exists(self.config_file_path):
69+
return
70+
load = input(
71+
"Would you like to load the configuration from a previous session? [Y/n] "
72+
)
73+
if load.lower() == "y":
74+
self.load_config()
75+
76+
def generate_next_question(self) -> str:
77+
"""Generate the next question for the user to answer.
78+
79+
Returns:
80+
A prompt for the user to answer.
81+
"""
82+
prompt = questions_prompt(self.project_name, self.questions)
83+
response = openai.ChatCompletion.create(
84+
model=self.model,
85+
messages=[
86+
{
87+
"role": "system",
88+
"content": (
89+
"You are a README generator. "
90+
"You are helping a user write a README for "
91+
"their project. Your task is to ask the user "
92+
"questions about their project to help them "
93+
"write a comprehensive README. As a reminder, "
94+
"a README should not prioritize the technical "
95+
"details of my project. Instead, it should focus on "
96+
"the motivation for the project, the problem it "
97+
"solves, and how to use it."
98+
),
99+
},
100+
{
101+
"role": "user",
102+
"content": prompt,
103+
},
104+
],
105+
functions=[
106+
{
107+
"name": "ask_next_question",
108+
"description": "Ask the user the next question.",
109+
"parameters": {
110+
"type": "object",
111+
"properties": {
112+
"question": {
113+
"type": "string",
114+
"description": "The question to ask the user, "
115+
"for example, 'What is your project called?'",
116+
}
117+
},
118+
"required": ["question"],
119+
},
120+
}
121+
],
122+
function_call={"name": "ask_next_question"},
123+
)
124+
return json.loads(
125+
response["choices"][0]["message"]["function_call"]["arguments"]
126+
)["question"]
127+
128+
def ask_next_question(self) -> Question | None:
129+
"""Ask the user the next question.
130+
131+
Returns:
132+
The question and answer.
133+
"""
134+
question = self.generate_next_question()
135+
answer = multiline_input(
136+
question + " Leave empty to generate the README"
137+
).strip()
138+
if not answer:
139+
return None
140+
return Question(question=question, answer=answer)
141+
142+
def generate_readme(self) -> str:
143+
"""Generate the README.
144+
145+
Returns:
146+
The README.
147+
"""
148+
prompt = readme_prompt(self.project_name, self.questions)
149+
return openai.ChatCompletion.create(
150+
model=self.model,
151+
messages=[
152+
{
153+
"role": "system",
154+
"content": (
155+
"You are a README generator. "
156+
"You are helping a user write a comprehensive "
157+
"README for their project. You shouldn't output "
158+
"any text other than the README itself, in Markdown."
159+
),
160+
},
161+
{
162+
"role": "user",
163+
"content": prompt,
164+
},
165+
],
166+
)["choices"][0]["message"]["content"]
167+
168+
def run(self) -> str:
169+
"""Run the generator."""
170+
self.ask_load()
171+
while True:
172+
question = self.ask_next_question()
173+
if not question:
174+
break
175+
self.questions.append(question)
176+
self.save_config()
177+
return self.generate_readme()

0 commit comments

Comments
 (0)