Skip to content

Commit 0e6753d

Browse files
committed
Fix most of the big bugs finally, v0.2.7 release
1 parent 832e1b4 commit 0e6753d

File tree

5 files changed

+23
-30
lines changed

5 files changed

+23
-30
lines changed

codegpt/gpt_interface.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
try:
99
nltk.data.find('tokenizers/punkt')
1010
except LookupError:
11+
typer.secho("Downloading punkt for nltk... Only once!", fg=typer.colors.GREEN, bold=True)
1112
nltk.download('punkt', quiet=True)
1213

1314
def confirm_send(prompt, max_tokens=4000, yes=False):
@@ -27,7 +28,7 @@ def confirm_send(prompt, max_tokens=4000, yes=False):
2728

2829
return max_tokens
2930

30-
def send_iffy_edit(prompt: str, code: Dict[str, str], clipboard: bool = False) -> str:
31+
def send_iffy_edit(prompt: str, code: Dict[str, str], clipboard: bool = False, yes=False) -> str:
3132
full_prompt = "You are an expert developer. Given the following code:\n\n"
3233

3334
for filename, code_string in code.items():
@@ -39,19 +40,18 @@ def send_iffy_edit(prompt: str, code: Dict[str, str], clipboard: bool = False) -
3940

4041
if not clipboard:
4142
full_prompt += dedent("""
43+
You MUST output complete files.
4244
43-
Answer in this exact format:
45+
For each file you wish to output (only if you modified it or made a new one),
46+
answer in this exact format:
4447
4548
filename:
4649
> <the filename to be output>
4750
explanation:
4851
> <The changes that you made>
4952
code:
5053
> <code line 1>
51-
> <code line 2...>
52-
53-
You should return one entry like above for each file you want to output, separated by '==='
54-
""")
54+
> <code line 2...>""")
5555
else:
5656
full_prompt += dedent("""
5757
@@ -64,14 +64,14 @@ def send_iffy_edit(prompt: str, code: Dict[str, str], clipboard: bool = False) -
6464
> <the code to be output line 2>
6565
> <the code to be output, line n...>""")
6666

67-
max_tokens = confirm_send(full_prompt, yes=True)
67+
max_tokens = confirm_send(full_prompt, yes=yes)
6868

6969
response = openai.Completion.create(
7070
engine="text-davinci-003",
7171
prompt=full_prompt,
7272
max_tokens=max_tokens,
7373
n=1,
74-
temperature=0.6,
74+
temperature=0.5,
7575
)
7676

7777
parsed = parse_resp(response)

codegpt/main.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import typer
33

44
from codegpt import prompts
5-
from codegpt.prompts import PromptKeys
65

76
from codegpt import gpt_interface as gpt
87
from codegpt import files
@@ -18,15 +17,16 @@
1817

1918
@app.command("do")
2019
def edit_file(
21-
filenames: List[Path] = typer.Argument(
22-
None, help="List of filenames to edit. If not provided, will prompt for input.",
20+
instruction: str = typer.Argument(
21+
..., help="Instruction to edit the file(s). Keep it short! Wrap with quotes.",
2322
),
24-
instruction: str = typer.Option(
25-
None, '--instruction', '-i', help="Instruction to edit the file(s). Keep it short!",
23+
filenames: List[Path] = typer.Argument(
24+
..., help="List of filenames to edit. If not provided, will prompt for input.",
2625
),
2726
backup: bool = typer.Option(
2827
False, "--backup", "-b", help="Whether to create a backup of the original file(s).",
2928
),
29+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation.",),
3030
):
3131
"""
3232
Edit one or more files using codegpt.
@@ -37,22 +37,24 @@ def edit_file(
3737
if not filenames:
3838
filenames = typer.prompt("Enter the filenames to edit, separated by spaces").split()
3939
code = files.load_text(filenames)
40-
result = gpt.send_iffy_edit(instruction, code)
40+
result = gpt.send_iffy_edit(instruction, code, yes=yes)
4141
files.write_text(result, backup)
4242
typer.secho("Done!", color=typer.colors.BRIGHT_BLUE)
4343

4444

4545
@app.command("quick")
4646
def quick_edit_file(
47-
filenames: List[str],
48-
option: PromptKeys = typer.Option(PromptKeys.COMMENT, "--option", "-o", case_sensitive=False),
49-
backup=False,
47+
option: str = typer.Argument(..., help=f"{{{'|'.join(prompts.prompts.keys())}}}"),
48+
filenames: List[str] = typer.Argument(..., help="Enter the filenames to edit, separated by spaces"),
49+
backup: bool = typer.Option(False, '--backup', '-b', help="Whether to create a backup of the original file(s)."),
5050
):
5151
"""
5252
Edit a file using codegpt's built in prompts
5353
"""
54+
if option not in prompts.prompts:
55+
raise typer.BadParameter(f"{option} is not a valid option. Must be one of {list(prompts.prompts.keys())}")
5456
code = files.load_text(filenames)
55-
result = gpt.send_iffy_edit(prompts.prompts[option.value], code)
57+
result = gpt.send_iffy_edit(prompts.prompts[option], code)
5658
files.write_text(result, backup)
5759
typer.secho("done", color=typer.colors.BRIGHT_BLUE)
5860

codegpt/prompts.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
from enum import Enum
2-
3-
class PromptKeys(str, Enum):
4-
COMMENT = 'comment'
5-
VARNAMES = 'varnames'
6-
UGH = 'ugh'
7-
BUGS = 'bugs'
8-
VULNS = 'vulns'
9-
101
prompts = {
11-
"comment": "Add or update comments according to the language's standards. Add or update function, module, or class level comments if they're appropriate.",
2+
"comment": "Add or update comments according to the given language's standards. Add or update function, module, or class level comments if they're appropriate.",
123
"varnames": "Change variable names, but nothing else, to make the code more readable. For example, instead of using 'x' and 'y', use 'width' and 'height'.",
134
"ugh": "Do anything you can to make this code more readable. Add comments, change variable and function names, add whitespace, whatever. Add a readme to explain what the code does and where it could be improved.",
145
"bugs": """Find any bugs you can, note them in comments prefixed with BUG:

codegpt/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pip install codegpt
1616
To use the CLI, simply run the following command:
1717

1818
```
19-
codegpt <command> <options
19+
codegpt <command> <instruction|choice> <filenames>
2020
```
2121

2222
## Contributing

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "codegpt"
3-
version = "0.2.5"
3+
version = "0.2.7"
44
license = "GPL-3.0-or-later"
55
description = "A CLI tool for refactoring code using OpenAI's models"
66
authors = ["John Partee"]

0 commit comments

Comments
 (0)