Skip to content

Commit

Permalink
Remove ChatGPT support, document code, small refactor
Browse files Browse the repository at this point in the history
This commit performs the following backwards-incompatible
modifications to the codebase:

- ChatGPT support is completely removed. Since this was particularly
  fragile, undocumented, and an unsupported use case (both from our
  part and from OpenAI's part), it is better removed until/if
  ChatGPT provides an API.

- The code is documented with GoDoc-compliant comments.

- The NewClient function no longer receives an input struct, but only
  receives the OpenAI API key.

- The `Ask` method no longer accepts a `readmePath` argument, as
  this only worked with ChatGPT. Documentation also makes it clear
  that this method is meant to be used in CLI programs only.

- The `askViaAPI` method is renamed `GenerateCode` and thus
  publically exposed, allowing real library usage of the module.

Due to these breaking changes, this commit should be released as part
of version 2.0.0 of aiac:

    git tag v2.0.0
    git push origin v2.0.0
    go mod tidy
    go mod publish
  • Loading branch information
ido50 committed Feb 15, 2023
1 parent 4409dc3 commit acbe643
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 385 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ Generator.
<!-- vim-markdown-toc GFM -->

* [Description](#description)
* [Use Cases](#use-cases-and-example-prompts)
* [Use Cases and Example Prompts](#use-cases-and-example-prompts)
* [Generate IaC](#generate-iac)
* [Generate Configuration Files](#generate-configuration-files)
* [Generate CICD Pipelines](#generate-cicd-pipelines)
* [Generate Policy as Code](#generate-policy-as-code)
* [Generate Utilities](#generate-utilities)
* [Command Line Builder](#command-line-builder)
* [Query Builder](#query-builder)
* [Quick Start](#quick-start)
* [Instructions](#instructions)
* [Example Output](#example-output)
* [Support Channels](#support-channels)
* [License](#license)
Expand All @@ -28,36 +36,41 @@ output.
## Use Cases and Example Prompts

### Generate IaC

- `aiac get terraform for a highly available eks`
- `aiac get pulumi golang for an s3 with sns notification`
- `aiac get cloudformation for a neptundb`

### Generate Configuration Files

- `aiac get dockerfile for a secured nginx`
- `aiac get k8s manifest for a mongodb deployment`

### Generate CICD Pipelines

- `aiac get jenkins pipeline for building nodejs`
- `aiac get github action that plans and applies terraform and sends a slack notification`

### Generate Policy as Code

- `aiac get opa policy that enforces readiness probe at k8s deployments`

### Generate Utilities

- `aiac get python code that scans all open ports in my network`
- `aiac get bash script that kills all active terminal sessions`

### Command Line Builder

- `aiac get kubectl that gets ExternalIPs of all nodes`
- `aiac get awscli that lists instances with public IP address and Name`

### Query Builder

- `aiac get mongo query that aggregates all documents by created date`
- `aiac get elastic query that applies a condition on a value greater than some value in aggregation`
- `aiac get sql query that counts the appearances of each row in one table in another table based on an id column`



## Quick Start

First, install `aiac`:
Expand All @@ -68,34 +81,39 @@ Or using `docker`:

docker pull ghcr.io/gofireflyio/aiac

Or using `go install`:

go install github.com/gofireflyio/aiac/v2

Alternatively, clone the repository and build from source:

git clone https://github.com/gofireflyio/aiac.git
go build


### Instructions

1. Create your OpenAI API key [here](https://beta.openai.com/account/api-keys).
1. Click “Create new secret key” and copy it.
1. 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 re-generate the code
By default, aiac prints the extracted code to standard output and asks if it
should save or regenerate the code:

aiac get terraform for AWS EC2

To store the resulting code to a file:

aiac -o aws_ec2.tf get terraform for AWS EC2
To run using `docker`

To run using `docker`:

docker run \
-it \
-e OPENAI_API_KEY=[PUT YOUR KEY HERE] \
ghcr.io/gofireflyio/aiac get terraform for ec2

## Example Output

Command line prompt:

aiac get dockerfile for nodejs with comments
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
module github.com/gofireflyio/aiac
module github.com/gofireflyio/aiac/v2

go 1.19

require (
github.com/adrg/xdg v0.4.0
github.com/alecthomas/kong v0.7.1
github.com/briandowns/spinner v1.19.0
github.com/google/uuid v1.1.2
github.com/fatih/color v1.7.0
github.com/ido50/requests v1.5.0
github.com/manifoldco/promptui v0.9.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
go.uber.org/atomic v1.10.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
Expand Down Expand Up @@ -122,7 +120,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
Expand Down Expand Up @@ -316,7 +313,6 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
Loading

0 comments on commit acbe643

Please sign in to comment.