Skip to content

Commit 4f736d3

Browse files
author
Liav Yona
authored
Add loader and texts inputs for a better UX (#1)
1 parent 278c7e6 commit 4f736d3

File tree

8 files changed

+442
-172
lines changed

8 files changed

+442
-172
lines changed

README.md

+21-59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# aiac
1+
# ![AIAC](logo-header.svg#gh-light-mode-only) ![AIAC](logo-header-inverted.svg#gh-dark-mode-only)
22

3-
**AI-generated IaC templates via ChatGPT.**
3+
Artificial Intelligence
4+
Infrastructure-as-Code
5+
Generator.
6+
7+
<kbd>[<img src="demo.gif" style="width: 100%; border: 1px solid silver;" border="1" alt="demo">](demo.gif)</kbd>
48

59
<!-- vim-markdown-toc GFM -->
610

@@ -18,15 +22,11 @@
1822
## Description
1923

2024
`aiac` is a command line tool to generate IaC (Infrastructure as Code) templates
21-
via [OpenAI](https://openai.com/)'s API or via ChatGPT. The CLI allows you to ask the model to generate templates
22-
for different scenarios (e.g. "generate terraform for AWS EC2"). It will make the
25+
via [OpenAI](https://openai.com/)'s API. The CLI allows you to ask the model to generate templates
26+
for different scenarios (e.g. "get terraform for AWS EC2"). It will make the
2327
request, and store the resulting code to a file, or simply print it to standard
2428
output.
2529

26-
When using ChatGPT, the server returns a Markdown file with code and explanations.
27-
The CLI will extract the code in this case, and optionally store the entire
28-
Markdown of explanations to a separate file.
29-
3030
## Quick Start
3131

3232
First, install `aiac`:
@@ -38,64 +38,31 @@ Alternatively, clone the repository and build from source:
3838
git clone https://github.com/gofireflyio/aiac.git
3939
go build
4040

41-
### Usage via OpenAI API
41+
### Instructions
4242

43-
You will need to provide `aiac` with an API key. Create your API key [here](https://beta.openai.com/account/api-keys).
44-
You can either provide the API key via the `--api-key` command line flag, or via
45-
the `OPENAI_API_KEY` environment variable.
43+
1. Create your OpenAI API key [here](https://beta.openai.com/account/api-keys).
44+
1. Click “Create new secret key” and copy it.
45+
1. Provide the API key via the `OPENAI_API_KEY` environment variable or via the `--api-key` command line flag.
4646

47-
By default, `aiac` simply prints the extracted code to standard output
47+
By default, aiac prints the extracted code to standard output and asks if it should save or re-generate the code
4848

49-
aiac --api-key=API_KEY generate terraform for AWS EC2
49+
aiac get terraform for AWS EC2
5050

5151
To store the resulting code to a file:
5252

53-
aiac --api-key=API_KEY \
54-
--output-file="aws_ec2.tf" \
55-
get terraform for AWS EC2
56-
57-
### Usage via ChatGPT
58-
59-
There are several caveats to using `aiac` in ChatGPT mode:
60-
61-
- ChatGPT's API is not public, and is likely to change frequently, which
62-
may break this program. Please inform us via the [issues page](https://github.com/gofireflyio/aiac/issues) if this happens.
63-
- ChatGPT may rate limit your requests, and is prone to answer slowly or not at
64-
all when under heavy load.
65-
- You will currently have to manually copy a session token from an actual browser
66-
session in order to authenticate (instructions follow).
67-
68-
You will need to provide `aiac` with a session token. Since ChatGPT doesn't
69-
currently support programmatic usage, you will need to do this via your browser
70-
(this is hopefully temporary until we can implement OpenAI authentication).
71-
To get a token, follow these steps:
72-
73-
1. Login to [ChatGPT](https://chat.openai.com/) via your web browser.
74-
2. Open the Web Developer Tools (usually Ctrl+Shift+I).
75-
3. Go to the "Storage" tab, and move to the list of "Cookies".
76-
4. Find the cookie called "__Secure-next-auth.session-token".
77-
5. Copy its value. This is the session token. You can store it in the
78-
`CHATGPT_SESSION_TOKEN` environment variable, or provide it via the
79-
`--session-token` command line flag.
80-
81-
![](/authentication.jpg)
82-
83-
Then run:
84-
85-
aiac --chat-gpt \
86-
--session-token=TOKEN \
87-
--output-file="ec2.tf" \
88-
--readme-file="README.md" \
53+
aiac -o="aws_ec2.tf" \
8954
get terraform for AWS EC2
9055

9156
## Example Prompts
9257

9358
The following prompts are known to work:
9459

95-
- get Terraform for AWS EC2
96-
- get Dockerfile for NodeJS with comments
97-
- get GitHub action for deploying Terraform
98-
- get Python code for Pulumi that deploys Azure VPC
60+
- `aiac get terraform for a highly available eks`
61+
- `aiac get pulumi golang for an s3 with sns notification`
62+
- `aiac get dockerfile for a secured nginx`
63+
- `aiac get cloudformaion for a neptondb`
64+
- `aiac get k8s manifest for a mongodb deployment`
65+
- `aiac get github action which plan and apply terraform and send slack notification`
9966

10067
## Example Output
10168

@@ -127,11 +94,6 @@ EXPOSE 8080
12794
CMD [ "node", "index.js" ]
12895
```
12996

130-
## Acknowledgements
131-
132-
Thanks to [acheong08/ChatGPT](https://github.com/acheong08/ChatGPT) for helping with reverse engineering the ChatGPI
133-
API.
134-
13597
## License
13698

13799
This code is published under the terms of the [Apache License 2.0](/LICENSE).

demo.gif

234 KB
Loading

go.mod

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ go 1.19
55
require (
66
github.com/adrg/xdg v0.4.0
77
github.com/alecthomas/kong v0.7.1
8+
github.com/briandowns/spinner v1.19.0
89
github.com/google/uuid v1.1.2
910
github.com/ido50/requests v1.5.0
11+
github.com/manifoldco/promptui v0.9.0
1012
)
1113

1214
require (
15+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
16+
github.com/fatih/color v1.7.0 // indirect
17+
github.com/mattn/go-colorable v0.1.2 // indirect
18+
github.com/mattn/go-isatty v0.0.16 // indirect
1319
go.uber.org/atomic v1.10.0 // indirect
1420
go.uber.org/multierr v1.8.0 // indirect
1521
go.uber.org/zap v1.24.0 // indirect
16-
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect
22+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
23+
golang.org/x/text v0.3.7 // indirect
1724
)

go.sum

+20-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4
4545
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
4646
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
4747
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
48+
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=
49+
github.com/briandowns/spinner v1.19.0/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
4850
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
51+
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
4952
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
53+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
5054
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
55+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
5156
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
5257
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5358
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
@@ -62,6 +67,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
6267
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
6368
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
6469
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
70+
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
71+
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
6572
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
6673
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
6774
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -138,6 +145,13 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
138145
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
139146
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
140147
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
148+
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
149+
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
150+
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
151+
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
152+
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
153+
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
154+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
141155
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
142156
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
143157
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -267,7 +281,9 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
267281
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
268282
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
269283
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
284+
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
270285
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
286+
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
271287
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
272288
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
273289
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -300,16 +316,18 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
300316
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
301317
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
302318
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
303-
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
304319
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
320+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
321+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
305322
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
306323
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
307324
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
308325
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
309326
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
310327
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
311-
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
312328
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
329+
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
330+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
313331
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
314332
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
315333
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=

0 commit comments

Comments
 (0)