Skip to content

Commit

Permalink
Switch to ChatGPT API by default, allow other models (#27)
Browse files Browse the repository at this point in the history
* Switch to ChatGPT API by default, allow other models

aiac will now use the ChatGPT API (and thus the gpt-3.5-turbo
model) instead of the text-davinci-003 model by default. It also
allows selecting the model to use, with the aforementioned two
being supported, along with the code-davinci-002 model, which is
specifically designed to generate code. A model can be selected
via the `--model` flag, and a list of all supported models is
available via the `list-models` command.

Since ChatGPT usually returns a Markdown-formatted description
rather than just code, the library will extract the code from the
response. A new flag, `--full`, is added to prevent that and echo
or save the complete response from the API.

The command line prompt will now also allow users to modify the
prompt after receiving a response (using the "m" key), along with
the previous option to retry with the same prompt.

Also included are small fixes: entering Ctrl+D and Ctrl+C after
receiving a response will quit the program as expected, rather than
regenerate a response.

---------

Co-authored-by: Liav Yona <[email protected]>
  • Loading branch information
ido50 and Liav Yona authored Mar 9, 2023
1 parent 7b39661 commit f89e9b7
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ linters:
- promlinter
- testpackage
- varnamelen
- nonamedreturns
- tagliatelle
- exhaustruct
issues:
new: true
new-from-rev: HEAD
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Generator.
* [Instructions](#instructions)
* [Installation](#installation)
* [Usage](#usage)
* [Choosing a Different Model](#choosing-a-different-model)
* [Example Output](#example-output)
* [Troubleshooting](#troubleshooting)
* [Support Channels](#support-channels)
Expand All @@ -33,7 +34,8 @@ Generator.
via [OpenAI](https://openai.com/)'s API. The CLI allows you to ask the model to generate templates
for different scenarios (e.g. "get terraform for AWS EC2"). It will make the
request, and store the resulting code to a file, or simply print it to standard
output.
output. By default, `aiac` uses the same model used by ChatGPT, but allows using
different models.

## Use Cases and Example Prompts

Expand Down Expand Up @@ -92,7 +94,7 @@ Using `docker`:

Using `go install`:

go install github.com/gofireflyio/aiac/v2
go install github.com/gofireflyio/aiac/v2@latest

Alternatively, clone the repository and build from source:

Expand All @@ -101,12 +103,12 @@ Alternatively, clone the repository and build from source:

### Usage

1. Create your OpenAI API key [here](https://beta.openai.com/account/api-keys).
1. Create your OpenAI API key [here](platform.openai.com/account/api-keys).
2. Click “Create new secret key” and copy it.
3. Provide the API key via the `OPENAI_API_KEY` environment variable or via the `--api-key` command line flag.

By default, aiac prints the extracted code to standard output and asks if it
should save or regenerate the code:
should save the code, regenerate it, or modify the prompt:

aiac get terraform for AWS EC2

Expand All @@ -121,6 +123,15 @@ To run using `docker`:
-e OPENAI_API_KEY=[PUT YOUR KEY HERE] \
ghcr.io/gofireflyio/aiac get terraform for ec2

If you want to receive and/or store the complete Markdown output from OpenAI,
including explanations (if any), use the `--full` flag.

### Choosing a Different Model

Use the `--model` flag to select a different model than the default (currently
"gpt-3.5-turbo"). Not all OpenAI models are supported, use `aiac list-models`
to get a list of all supported models.

## Example Output

Command line prompt:
Expand Down
Loading

0 comments on commit f89e9b7

Please sign in to comment.