{"id":13423996,"url":"https://github.com/gofireflyio/aiac","last_synced_at":"2025-05-14T10:11:03.791Z","repository":{"id":64682258,"uuid":"575295397","full_name":"gofireflyio/aiac","owner":"gofireflyio","description":"Artificial Intelligence Infrastructure-as-Code Generator.","archived":false,"fork":false,"pushed_at":"2024-10-29T20:46:04.000Z","size":3133,"stargazers_count":3650,"open_issues_count":2,"forks_count":281,"subscribers_count":44,"default_branch":"main","last_synced_at":"2025-04-27T04:47:52.319Z","etag":null,"topics":["ai","amazon-bedrock","chatgpt","iac","llms","ollama","openai","pulumi","terraform"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gofireflyio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-07T07:29:50.000Z","updated_at":"2025-04-27T03:43:37.000Z","dependencies_parsed_at":"2024-01-02T13:57:21.862Z","dependency_job_id":"6fc4678e-07c9-4492-b4e0-ce4b8ab2a1f2","html_url":"https://github.com/gofireflyio/aiac","commit_stats":{"total_commits":59,"total_committers":10,"mean_commits":5.9,"dds":0.5084745762711864,"last_synced_commit":"3055cef6449180281872b8d9bc70123580281f9d"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofireflyio%2Faiac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofireflyio%2Faiac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofireflyio%2Faiac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gofireflyio%2Faiac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gofireflyio","download_url":"https://codeload.github.com/gofireflyio/aiac/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251089408,"owners_count":21534512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","amazon-bedrock","chatgpt","iac","llms","ollama","openai","pulumi","terraform"],"created_at":"2024-07-31T00:00:46.369Z","updated_at":"2025-04-27T04:48:10.595Z","avatar_url":"https://github.com/gofireflyio.png","language":"Go","funding_links":[],"categories":["HarmonyOS","Uncategorized","Go","语言资源库","CLI tools","Openai","Developer Libraries, SDKs, and APIs","A01_文本生成_文本对话","Tools","Thanks to all the contributors!","Golang","精选开源项目合集","chatgpt","twitter","UIs"],"sub_categories":["Windows Manager","Uncategorized","go","Examples","Golang","大语言对话模型及数据","Community providers","DevOps","GPT工具","Command-line(shell) interface"],"readme":"# ![AIAC](logo-header.svg#gh-light-mode-only) ![AIAC](logo-header-inverted.svg#gh-dark-mode-only)\n\nArtificial Intelligence\nInfrastructure-as-Code\nGenerator.\n\n\u003ckbd\u003e[\u003cimg src=\"demo.gif\" style=\"width: 100%; border: 1px solid silver;\" border=\"1\" alt=\"demo\"\u003e](demo.gif)\u003c/kbd\u003e\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [Description](#description)\n* [Use Cases and Example Prompts](#use-cases-and-example-prompts)\n    * [Generate IaC](#generate-iac)\n    * [Generate Configuration Files](#generate-configuration-files)\n    * [Generate CI/CD Pipelines](#generate-cicd-pipelines)\n    * [Generate Policy as Code](#generate-policy-as-code)\n    * [Generate Utilities](#generate-utilities)\n    * [Command Line Builder](#command-line-builder)\n    * [Query Builder](#query-builder)\n* [Instructions](#instructions)\n    * [Installation](#installation)\n    * [Configuration](#configuration)\n    * [Usage](#usage)\n        * [Command Line](#command-line)\n            * [Listing Models](#listing-models)\n            * [Generating Code](#generating-code)\n        * [Via Docker](#via-docker)\n        * [As a Library](#as-a-library)\n    * [Upgrading from v4 to v5](#upgrading-from-v4-to-v5)\n        * [Changes in Configuration](#changes-in-configuration)\n        * [Changes in CLI Invokation](#changes-in-cli-invokation)\n        * [Changes in Model Usage and Support](#changes-in-model-usage-and-support)\n        * [Other Changes](#other-changes)\n* [Example Output](#example-output)\n* [Troubleshooting](#troubleshooting)\n* [License](#license)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## Description\n\n`aiac` is a library and command line tool to generate IaC (Infrastructure as Code)\ntemplates, configurations, utilities, queries and more via [LLM](https://en.wikipedia.org/wiki/Large_language_model) providers such\nas [OpenAI](https://openai.com/), [Amazon Bedrock](https://aws.amazon.com/bedrock/) and [Ollama](https://ollama.ai/).\n\nThe CLI allows you to ask a model to generate templates for different scenarios\n(e.g. \"get terraform for AWS EC2\"). It composes an appropriate request to the\nselected provider, and stores the resulting code to a file, and/or prints it to\nstandard output.\n\nUsers can define multiple \"backends\" targeting different LLM providers and\nenvironments using a simple configuration file.\n\n## Use Cases and Example Prompts\n\n### Generate IaC\n\n- `aiac terraform for a highly available eks`\n- `aiac pulumi golang for an s3 with sns notification`\n- `aiac cloudformation for a neptundb`\n\n### Generate Configuration Files\n\n- `aiac dockerfile for a secured nginx`\n- `aiac k8s manifest for a mongodb deployment`\n\n### Generate CI/CD Pipelines\n\n- `aiac jenkins pipeline for building nodejs`\n- `aiac github action that plans and applies terraform and sends a slack notification`\n\n### Generate Policy as Code\n\n- `aiac opa policy that enforces readiness probe at k8s deployments`\n\n### Generate Utilities\n\n- `aiac python code that scans all open ports in my network`\n- `aiac bash script that kills all active terminal sessions`\n\n### Command Line Builder\n\n- `aiac kubectl that gets ExternalIPs of all nodes`\n- `aiac awscli that lists instances with public IP address and Name`\n\n### Query Builder\n\n- `aiac mongo query that aggregates all documents by created date`\n- `aiac elastic query that applies a condition on a value greater than some value in aggregation`\n- `aiac sql query that counts the appearances of each row in one table in another table based on an id column`\n\n## Instructions\n\nBefore installing/running `aiac`, you may need to configure your LLM providers\nor collect some information.\n\nFor **OpenAI**, you will need an API key in order for `aiac` to work. Refer to\n[OpenAI's pricing model](https://openai.com/pricing?trk=public_post-text) for more information. If you're not using the API hosted\nby OpenAI (for example, you may be using Azure OpenAI), you will also need to\nprovide the API URL endpoint.\n\nFor **Amazon Bedrock**, you will need an AWS account with Bedrock enabled, and\naccess to relevant models. Refer to the [Bedrock documentation](https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html)\nfor more information.\n\nFor **Ollama**, you only need the URL to the local Ollama API server, including\nthe /api path prefix. This defaults to http://localhost:11434/api. Ollama does\nnot provide an authentication mechanism, but one may be in place in case of a\nproxy server being used. This scenario is not currently supported by `aiac`.\n\n### Installation\n\nVia `brew`:\n\n    brew tap gofireflyio/aiac https://github.com/gofireflyio/aiac\n    brew install aiac\n\nUsing `docker`:\n\n    docker pull ghcr.io/gofireflyio/aiac\n\nUsing `go install`:\n\n    go install github.com/gofireflyio/aiac/v5@latest\n\nAlternatively, clone the repository and build from source:\n\n    git clone https://github.com/gofireflyio/aiac.git\n    go build\n\n`aiac` is also available in the Arch Linux user repository (AUR) as [aiac](https://aur.archlinux.org/packages/aiac) (which\ncompiles from source) and [aiac-bin](https://aur.archlinux.org/packages/aiac-bin) (which downloads a compiled executable).\n\n### Configuration\n\n`aiac` is configured via a TOML configuration file. Unless a specific path is\nprovided, `aiac` looks for a configuration file in the user's [XDG_CONFIG_HOME](https://en.wikipedia.org/wiki/Freedesktop.org#User_directories)\ndirectory, specifically `${XDG_CONFIG_HOME}/aiac/aiac.toml`. On Unix-like\noperating systems, this will default to \"~/.config/aiac/aiac.toml\". If you want\nto use a different path, provide the `--config` or `-c` flag with the file's path.\n\nThe configuration file defines one or more named backends. Each backend has a\ntype identifying the LLM provider (e.g. \"openai\", \"bedrock\", \"ollama\"), and\nvarious settings relevant to that provider. Multiple backends of the same LLM\nprovider can be configured, for example for \"staging\" and \"production\"\nenvironments.\n\nHere's an example configuration file:\n\n```toml\ndefault_backend = \"official_openai\"   # Default backend when one is not selected\n\n[backends.official_openai]\ntype = \"openai\"\napi_key = \"API KEY\"\n# Or \n# api_key = \"$OPENAI_API_KEY\"\ndefault_model = \"gpt-4o\"              # Default model to use for this backend\n\n[backends.azure_openai]\ntype = \"openai\"\nurl = \"https://tenant.openai.azure.com/openai/deployments/test\"\napi_key = \"API KEY\"\napi_version = \"2023-05-15\"            # Optional\nauth_header = \"api-key\"               # Default is \"Authorization\"\nextra_headers = { X-Header-1 = \"one\", X-Header-2 = \"two\" }\n\n[backends.aws_staging]\ntype = \"bedrock\"\naws_profile = \"staging\"\naws_region = \"eu-west-2\"\n\n[backends.aws_prod]\ntype = \"bedrock\"\naws_profile = \"production\"\naws_region = \"us-east-1\"\ndefault_model = \"amazon.titan-text-express-v1\"\n\n[backends.localhost]\ntype = \"ollama\"\nurl = \"http://localhost:11434/api\"     # This is the default\n```\n\nNotes:\n\n1. Every backend can have a default model (via configuration key `default_model`).\n   If not provided, calls that do not define a model will fail.\n2. Backends of type \"openai\" can change the header used for authorization by\n   providing the `auth_header` setting. This defaults to \"Authorization\", but\n   Azure OpenAI uses \"api-key\" instead. When the header is either \"Authorization\"\n   or \"Proxy-Authorization\", the header's value for requests will be \"Bearer\n   API_KEY\". If it's anything else, it'll simply be \"API_KEY\".\n3. Backends of type \"openai\" and \"ollama\" support adding extra headers to every\n   request issued by aiac, by utilizing the `extra_headers` setting.\n\n### Usage\n\nOnce a configuration file is created, you can start generating code and you only\nneed to refer to the name of the backend. You can use `aiac` from the command\nline, or as a Go library.\n\n#### Command Line\n\n##### Listing Models\n\nBefore starting to generate code, you can list all models available in a\nbackend:\n\n    aiac -b aws_prod --list-models\n\nThis will return a list of all available models. Note that depending on the LLM\nprovider, this may list models that aren't accessible or enabled for the\nspecific account.\n\n##### Generating Code\n\nBy default, aiac prints the extracted code to standard output and opens an\ninteractive shell that allows conversing with the model, retrying requests,\nsaving output to files, copying code to clipboard, and more:\n\n    aiac terraform for AWS EC2\n\nThis will use the default backend in the configuration file and the default\nmodel for that backend, assuming they are indeed defined. To use a specific\nbackend, provide the `--backend` or `-b` flag:\n\n    aiac -b aws_prod terraform for AWS EC2\n\nTo use a specific model, provide the `--model` or `-m` flag:\n\n    aiac -m gpt-4-turbo terraform for AWS EC2\n\nYou can ask `aiac` to save the resulting code to a specific file:\n\n    aiac terraform for eks --output-file=eks.tf\n\nYou can use a flag to save the full Markdown output as well:\n\n    aiac terraform for eks --output-file=eks.tf --readme-file=eks.md\n\nIf you prefer aiac to print the full Markdown output to standard output rather\nthan the extracted code, use the `-f` or `--full` flag:\n\n    aiac terraform for eks -f\n\nYou can use aiac in non-interactive mode, simply printing the generated code\nto standard output, and optionally saving it to files with the above flags,\nby providing the `-q` or `--quiet` flag:\n\n    aiac terraform for eks -q\n\nIn quiet mode, you can also send the resulting code to the clipboard by\nproviding the `--clipboard` flag:\n\n    aiac terraform for eks -q --clipboard\n\nNote that aiac will not exit in this case until the contents of the clipboard\nchanges. This is due to the mechanics of the clipboard.\n\n#### Via Docker\n\nAll the same instructions apply, except you execute a `docker` image:\n\n    docker run \\\n        -it \\\n        -v ~/.config/aiac/aiac.toml:~/.config/aiac/aiac.toml \\\n        ghcr.io/gofireflyio/aiac terraform for ec2\n\n#### As a Library\n\nYou can use `aiac` as a Go library:\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"log\"\n    \"os\"\n\n    \"github.com/gofireflyio/aiac/v5/libaiac\"\n)\n\nfunc main() {\n    aiac, err := libaiac.New() // Will load default configuration path.\n                               // You can also do libaiac.New(\"/path/to/aiac.toml\")\n    if err != nil {\n        log.Fatalf(\"Failed creating aiac object: %s\", err)\n    }\n\n    ctx := context.TODO()\n\n    models, err := aiac.ListModels(ctx, \"backend name\")\n    if err != nil {\n        log.Fatalf(\"Failed listing models: %s\", err)\n    }\n\n    chat, err := aiac.Chat(ctx, \"backend name\", \"model name\")\n    if err != nil {\n        log.Fatalf(\"Failed starting chat: %s\", err)\n    }\n\n    res, err = chat.Send(ctx, \"generate terraform for eks\")\n    res, err = chat.Send(ctx, \"region must be eu-central-1\")\n}\n```\n\n### Upgrading from v4 to v5\n\nVersion 5.0.0 introduced a significant change to the `aiac` API in both the\ncommand line and library forms, as per feedback from the community.\n\n#### Changes in Configuration\n\nBefore v5, there was no concept of a configuration file or named backends. Users\nhad to provide all the information necessary to contact a specific LLM provider\nvia command line flags or environment variables, and the library allowed\ncreating a \"client\" object that could only talk with one LLM provider.\n\nBackends are now configured only via the configuration file. Refer to the\n[Configuration](#configuration) section for instructions. Provider-specific flags such as\n`--api-key`, `--aws-profile`, etc. (and their respective environment variables,\nif any) are no longer accepted.\n\nSince v5, backends are also named. Previously, the `--backend` and `-b` flags\nreferred to the name of the LLM provider (e.g. \"openai\", \"bedrock\", \"ollama\").\nNow they refer to whatever name you've defined in the configuration file:\n\n```toml\n[backends.my_local_llm]\ntype = \"ollama\"\nurl = \"http://localhost:11434/api\"\n```\n\nHere we configure an Ollama backend named \"my_local_llm\". When you want to\ngenerate code with this backend, you will use `-b my_local_llm` rather than\n`-b ollama`, as multiple backends may exist for the same LLM provider.\n\n#### Changes in CLI Invokation\n\nBefore v5, the command line was split into three subcommands: `get`,\n`list-models` and `version`. Due to this hierarchical nature of the CLI, flags may\nnot have been accepted if they were provided in the \"wrong location\". For\nexample, the `--model` flag had to be provided after the word \"get\", otherwise\nit would not be accepted. In v5, there are no subcommands, so the position of\nthe flags no longer matters.\n\nThe `list-models` subcommand is replaced with the flag `--list-models`, and the\n`version` subcommand is replaced with the flag `--version`.\n\nBefore v5:\n\n    aiac -b ollama list-models\n\nSince v5:\n\n    aiac -b my_local_llm --list-models\n\nIn earlier versions, the word \"get\" was actually a subcommand and not truly part\nof the prompt sent to the LLM provider. Since v5, there is no \"get\" subcommand,\nso you no longer need to add this word to your prompts.\n\nBefore v5:\n\n    aiac get terraform for S3 bucket\n\nSince v5:\n\n    aiac terraform for S3 bucket\n\nThat said, adding either the word \"get\" or \"generate\" will not hurt, as v5 will\nsimply remove it if provided.\n\n#### Changes in Model Usage and Support\n\nBefore v5, the models for each LLM provider were hardcoded in each backend\nimplementation, and each provider had a hardcoded default model. This\nsignificantly limited the usability of the project, and required us to update\n`aiac` whenever new models were added or deprecated. On the other hand, we could\nprovide extra information about each model, such as its context lengths and\ntype, as we manually extracted them from the provider documentation.\n\nSince v5, `aiac` no longer hardcodes any models, including default ones. It\nwill not attempt to verify the model you select actually exists. The\n`--list-models` flag will now directly contact the chosen backend API to get a\nlist of supported models. Setting a model when generating code simply sends its\nname to the API as-is. Also, instead of hardcoding a default model for each\nbackend, users can define their own default models in the configuration file:\n\n```toml\n[backends.my_local_llm]\ntype = \"ollama\"\nurl = \"http://localhost:11434/api\"\ndefault_model = \"mistral:latest\"\n```\n\nBefore v5, `aiac` supported both completion models and chat models. Since v5,\nit only supports chat models. Since none of the LLM provider APIs actually\nnote whether a model is a completion model or a chat model (or even an image\nor video model), the `--list-models` flag may list models which are not actually\nusable, and attempting to use them will result in an error being returned from\nthe provider API. The reason we've decided to drop support for completion models\nwas that they require setting a maximum amount of tokens for the API to\ngenerate (at least in OpenAI), which we can no longer do without knowing the\ncontext length. Chat models are not only a lot more useful, but they do not have\nthis limitation.\n\n#### Other Changes\n\nMost LLM provider APIs, when returning a response to a prompt, will include a\n\"reason\" for why the response ended where it did. Generally, the response should\nend because the model finished generating a response, but sometimes the response\nmay be truncated due to the model's context length or the user's token\nutilization. When the response did not \"stop\" because it finished generation,\nthe response is said to be \"truncated\". Before v5, if the API returned that the\nresponse was truncated, `aiac` returned an error. Since v5, an error is no longer\nreturned, as it seems that some providers do not return an accurate stop reason.\nInstead, the library returns the stop reason as part of its output for users to\ndecide how to proceed.\n\n## Example Output\n\nCommand line prompt:\n\n    aiac dockerfile for nodejs with comments\n\nOutput:\n\n```Dockerfile\nFROM node:latest\n\n# Create app directory\nWORKDIR /usr/src/app\n\n# Install app dependencies\n# A wildcard is used to ensure both package.json AND package-lock.json are copied\n# where available (npm@5+)\nCOPY package*.json ./\n\nRUN npm install\n# If you are building your code for production\n# RUN npm ci --only=production\n\n# Bundle app source\nCOPY . .\n\nEXPOSE 8080\nCMD [ \"node\", \"index.js\" ]\n```\n\n## Troubleshooting\n\nMost errors that you are likely to encounter are coming from the LLM provider\nAPI, e.g. OpenAI or Amazon Bedrock. Some common errors you may encounter are:\n\n- \"[insufficient_quota] You exceeded your current quota, please check your plan and billing details\":\n  As described in the [Instructions](#instructions) section, OpenAI is a paid API with a certain\n  amount of free credits given. This error means you have exceeded your quota,\n  whether free or paid. You will need to top up to continue usage.\n\n- \"[tokens] Rate limit reached...\":\n  The OpenAI API employs rate limiting as [described here](https://platform.openai.com/docs/guides/rate-limits/request-increase). `aiac` only performs\n  individual requests and cannot workaround or prevent these rate limits. If\n  you are using `aiac` in programmatically, you will have to implement throttling\n  yourself. See [here](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_handle_rate_limits.ipynb) for tips.\n\n## License\n\nThis code is published under the terms of the [Apache License 2.0](/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgofireflyio%2Faiac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgofireflyio%2Faiac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgofireflyio%2Faiac/lists"}