#openai #generation #chatgpt #cli #code #fibonacci-sequence

app gptrs

A cli built on top of OpenAI that can generate code and output to a file

3 releases

0.1.2 Mar 7, 2023
0.1.1 Mar 6, 2023
0.1.0 Mar 6, 2023

#5 in #fibonacci-sequence

Apache-2.0/MIT

18KB
299 lines

gptrs

A OpenAI Code generation cli.

This sends requests to the OpenAI API, parsers the output and then generates code into a file.

This is mainly a small project to help myself learn Rust and get familiar with the OpenAI API, some of the initial code was generated using the help of ChatGPT!

Code Completion with A File and Prompt

gptrs completion --prompt=<PROMPT> --input=<PATH/TO/FILE> --output=</PATH/TO/OUTPUT>

Example

Run the command to generate a Python file with a Fibonacci sequence as following

gptrs completion --prompt="generate a fibonacci sequence in Python" --output=./fibonacci.py

Which generates a file in Python:

Screenshot 2023-03-06 at 21 45 50

Then run a command to refactor the code in this file and output a new file below:

gptrs completion --prompt="Refactor this code" --input=./fibonacci.py --output=./fibonacci_refactor.py 
Screenshot 2023-03-06 at 21 46 02

You can also set different models and temperatures

gptrs completion --prompt="Write unit tests for this fibonacci function in Python" --input=./fibonacci_refactor.py --output=./fibonacci_tests.py --model=code-davinci-002 --temperature=0

Setup

This assumes you have an OpenAI Developer Account

Generate API Token

See here for instructions

After generating the token, set the env variable

export OPENAI_API_KEY={API_KEY}

Install via Cargo

cargo install gptrs

Dependencies

~8–23MB
~277K SLoC