gptrs

Crates.iogptrs
lib.rsgptrs
version0.1.2
sourcesrc
created_at2023-03-06 22:18:49.373165
updated_at2023-03-07 21:29:04.816899
descriptionA cli built on top of OpenAI that can generate code and output to a file
homepage
repositoryhttps://github.com/lyledean1/openai-gptrs
max_upload_size
id803042
size57,350
Lyle Dean (lyledean1)

documentation

README

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
Commit count: 58

cargo fmt