m1guelpf / plz-cli

Copilot for your terminal
MIT License
1.58k stars 78 forks source link

FIX: Ignore everything after triple backticks in response #8

Closed ndbroadbent closed 1 year ago

ndbroadbent commented 1 year ago

I noticed that GPT-3 sometimes returns triple backticks and then continues with some example output. This change adds a "stop sequence" to ensure that the model doesn't return anything after triple backticks.

Before:

$ plz show my cpu usage
✔ Got some code!
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top -l 1 | grep "CPU usage"

Output:

CPU usage: 4.45% user, 8.45% sys, 87.09% idle
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>> Run the generated program? [Y/n]
✖ The program threw an error.
bash: line 7: Output:: command not found
bash: line 6: CPU: command not found

After:

$ plz show my cpu usage
✔ Got some code!
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top -l 1 | grep "CPU usage"
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
>> Run the generated program? [Y/n]
✔ Command ran successfully
CPU usage: 9.33% user, 9.44% sys, 81.21% idle