diff --git a/samples/RAG-chatbot/.devcontainer/Dockerfile b/samples/RAG-chatbot/.devcontainer/Dockerfile new file mode 100644 index 00000000..ec4e707f --- /dev/null +++ b/samples/RAG-chatbot/.devcontainer/Dockerfile @@ -0,0 +1 @@ +FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm diff --git a/samples/RAG-chatbot/.devcontainer/devcontainer.json b/samples/RAG-chatbot/.devcontainer/devcontainer.json new file mode 100644 index 00000000..5fb2471c --- /dev/null +++ b/samples/RAG-chatbot/.devcontainer/devcontainer.json @@ -0,0 +1,10 @@ +{ + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "features": { + "ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {} + } +} \ No newline at end of file diff --git a/samples/RAG-chatbot/.dockerignore b/samples/RAG-chatbot/.dockerignore new file mode 100644 index 00000000..c3cb9b24 --- /dev/null +++ b/samples/RAG-chatbot/.dockerignore @@ -0,0 +1 @@ +myenv diff --git a/samples/RAG-chatbot/.github/workflows/deploy.yaml b/samples/RAG-chatbot/.github/workflows/deploy.yaml new file mode 100644 index 00000000..5e78ad52 --- /dev/null +++ b/samples/RAG-chatbot/.github/workflows/deploy.yaml @@ -0,0 +1,24 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Deploy + uses: DefangLabs/defang-github-action@v1.0.4 + with: + config-env-vars: OPENAI_API_KEY + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} \ No newline at end of file diff --git a/samples/RAG-chatbot/.gitignore b/samples/RAG-chatbot/.gitignore new file mode 100644 index 00000000..43513b10 --- /dev/null +++ b/samples/RAG-chatbot/.gitignore @@ -0,0 +1 @@ +myenv/ \ No newline at end of file diff --git a/samples/RAG-chatbot/README.md b/samples/RAG-chatbot/README.md new file mode 100644 index 00000000..b5d144bc --- /dev/null +++ b/samples/RAG-chatbot/README.md @@ -0,0 +1,38 @@ +# Scikit RAG + OpenAI + +This sample demonstrates how to deploy a Flask-based Retrieval-Augmented Generation (RAG) chatbot using OpenAI's GPT model. The chatbot retrieves relevant documents from a knowledge base using scikit-learn and Sentence Transformers and then generates responses using OpenAI's GPT model. There is an LRU caching scheme of 128 queries. + +## Prerequisites + +1. Download [Defang CLI](https://github.com/DefangLabs/defang) +2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account +3. (Optional - for local development) [Docker CLI](https://docs.docker.com/engine/install/) + +## Deploying + +1. Open the terminal and type `defang login` +2. Type `defang compose up` in the CLI. +3. Your app will be running within a few minutes. + +## Local Development + +1. Clone the repository. +2. Create a `.env` file in the root directory and set your OpenAI API key or add the OPENAI_API_KEY into your .zshrc or .bashrc file: +3. Run the command `docker compose up --build` to spin up a docker container for this RAG chatbot + +## Configuration + +- The knowledge base is acquired via parsing an sitemap located at "https://docs.defang.io/sitemap.xml". +- The file `scrape_sitemap.py` parses every webpage as specified into paragraphs and writes to `knowledge_base.json` for the RAG retrieval. +- To obtain your own knowledge base, either use another sitemap or write your own parsing scheme to parse into knowledge_base.json. +- A least recently used (LRU) caching scheme is also in place as can be seen in `rag_system.py`. This caches common queries to have a faster response time. Feel free to adjust as needed. + +--- + +Title: Scikit RAG + OpenAI + +Short Description: A short hello world application demonstrating how to deploy a Flask-based Retrieval-Augmented Generation (RAG) chatbot using OpenAI's GPT model onto Defang. + +Tags: Flask, Scikit, Python, RAG, OpenAI, GPT, Machine Learning + +Languages: python diff --git a/samples/RAG-chatbot/app/Dockerfile b/samples/RAG-chatbot/app/Dockerfile new file mode 100644 index 00000000..dba2dcaa --- /dev/null +++ b/samples/RAG-chatbot/app/Dockerfile @@ -0,0 +1,28 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements file first to leverage Docker's cache +COPY requirements.txt /app/ + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +RUN pip install gunicorn + +# Install additional packages +RUN pip install sentence-transformers openai + +# Copy the current directory contents into the container at /app +COPY . /app + +# Make port 5000 available to the world outside this container +EXPOSE 5000 + +# Define environment variable +ENV FLASK_APP=app.py + +# Run app.py when the container launches +CMD ["flask", "run", "--host=0.0.0.0"] diff --git a/samples/RAG-chatbot/app/app.py b/samples/RAG-chatbot/app/app.py new file mode 100644 index 00000000..e98764b2 --- /dev/null +++ b/samples/RAG-chatbot/app/app.py @@ -0,0 +1,36 @@ +from flask import Flask, request, jsonify, render_template +from rag_system import rag_system + +app = Flask(__name__) + +@app.route('/', methods=['GET', 'POST']) +def index(): + if request.method == 'POST': + query = request.form.get('query') + if not query: + return render_template('index.html', query=None, response="No query provided") + + try: + response = rag_system.answer_query(query) + return render_template('index.html', query=query, response=response) + except Exception as e: + print(f"Error in /ask endpoint: {e}") + return render_template('index.html', query=query, response="Internal Server Error") + return render_template('index.html', query=None, response=None) + +@app.route('/ask', methods=['POST']) +def ask(): + data = request.get_json() + query = data.get('query') + if not query: + return jsonify({"error": "No query provided"}), 400 + + try: + response = rag_system.answer_query(query) + return jsonify({"response": response}) + except Exception as e: + print(f"Error in /ask endpoint: {e}") + return jsonify({"error": "Internal Server Error"}), 500 + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) diff --git a/samples/RAG-chatbot/app/knowledge_base.json b/samples/RAG-chatbot/app/knowledge_base.json new file mode 100644 index 00000000..b6f6b692 --- /dev/null +++ b/samples/RAG-chatbot/app/knowledge_base.json @@ -0,0 +1,442 @@ +[ + { + "id": 1, + "about": "Samples", + "text": "Check out our sample projects here to get some inspiration and get a sense of how defang works. import Samples from \"../src/components/Samples\"; " + }, + { + "id": 2, + "about": "What is Defang?, Features", + "text": "Defang is a radically simpler way for developers to build, deploy their apps to the cloud. Defang enables you to easily author cloud application in any language, build and deploy to the cloud with a single command, and iterate quickly. - The [Defang CLI](./getting-started/installing.md) includes an AI-driven assistant that translates natural language prompts to an outline for your project that you can then refine. - Defang can automatically build and deploy your project with a single command. - If you’re new to Defang, you can try deploying to the [Defang Playground](./concepts/defang-playground.md), a hosted environment to learn to use Defang with non-production workloads. - Once you’re ready, you can [deploy](./concepts/deployments.md) it to your own cloud account - we call this [Defang BYOC](./concepts/defang-byoc.md). Defang takes care of all the heavy lifting such as configuring networking, security, [observability](./concepts/observability.md) and all the other details that usually slow down the average cloud developer. - You can also use Defang to easily [publish updates](./concepts/deployments.md#deploying-updates) to your deployed application with zero downtime. ud applications. Defang includes the following features: - Support for [various types of applications](./use-cases/use-cases.md): Web services and APIs, mobile app backends, ML services, hosting LLMs, etc. - Support for your programming [language of choice](./samples.md): Node.js, Python, Golang, or anything else you can package in a Dockerfile. - Built-in [AI assistant](./concepts/ai.md) to go from natural language prompt to an outline project - Automated [Dockerfile builds](./concepts/deployments.md) - Support for [pre-built Docker containers](./tutorials/deploy-container-using-the-cli.mdx), from public or private image registries - Ability to express your project configuration using a [Docker Compose YAML](./concepts/compose.md) file - Ability to manage [encrypted configuration values](./concepts/configuration.md) - Pre-configured environments with built-in [security](./concepts/security.md), [networking](./concepts/networking.mdx), and [observability](./concepts/observability.md) - [One-command deployments](./getting-started/installing.md) - Support for [GPUs](./concepts/resources.md) - Support for Infra-as-Code via the [Defang Pulumi provider](./concepts/pulumi.md)" + }, + { + "id": 3, + "about": "FAQ, Which cloud/region is the app being deployed to?, Can I bring my own AWS or other cloud account?, On AWS, can I deploy to services such as EC2, EKS, or Lambda?, Can I access AWS storage services such as S3 or database services such as RDS? How?, Do you plan to support other clouds?, Can I run production apps with Defang?, I'm having trouble running the binary on my Mac. What should I do?, Warnings, \"The folder is not empty. Files may be overwritten.\", \"environment variable not found\", \"Unsupported platform\", \"not logged in\", \"No port mode was specified; assuming 'host'\", \"Published ports are not supported in ingress mode; assuming 'host'\", \"TCP ingress is not supported; assuming HTTP\", \"unsupported compose directive\", \"no reservations specified; using limits as reservations\", \"ingress port without healthcheck defaults to GET / HTTP/1.1\", \"missing memory reservation; specify deploy.resources.reservations.memory to avoid out-of-memory errors\", \"The build context contains more than 10 files\", \"AWS provider was selected, but AWS environment variables are not set\", \"Using Defang provider, but AWS environment variables were detected\", \"secret … is not defined in the top-level secrets section\", \"unsupported secret …: not marked external:true\", Errors, \"Stack:… is in UPDATE_COMPLETE_CLEANUP_IN_PROGRESS state and cannot be updated\"", + "text": "- In the [Defang Playground](./concepts/defang-playground.md) the app is deployed to AWS `us-west-2`. In the [Defang BYOC](./concepts/defang-byoc.md) model, the region is determined by your [Defang BYOC Provider](/docs/category/providers) settings. - Yes! Please check out the [Defang BYOC](./concepts/defang-byoc.md) documentation for more information. - The current release includes support for containers only, deployed to ECS. We are still exploring how to support additional execution models such as VMs and functions-as-a-service. However, using our Pulumi provider, it is possible to combine Defang services with other native AWS resources. - Yes, you can access whatever other resources exist in the cloud account you are using as a [Defang BYOC](./concepts/defang-byoc.md) Provider. - While we currently support AWS as a [Defang BYOC](./concepts/defang-byoc.md) Provider, we plan to support other clouds in future releases, such as [Azure](./providers/azure.md) and [GCP](./providers/gcp.md). - The [Defang Playground](./concepts/defang-playground.md) is meant for testing and trial purposes only. Deployment of productions apps with [Defang BYOC](./concepts/defang-byoc.md) is not yet supported and disallowed by the [Terms of Service](https://defang.io/terms-service.html). If you are interested in running production apps, please [contact us](https://defang.io/#Contact-us). - MacOS users will need to allow the binary to run due to security settings: 1. Attempt to run the binary. You'll see a security prompt preventing you from running it. 2. Go to System Preferences > Privacy & Security > General. 3. In the 'Allow applications downloaded from:' section, you should see a message about Defang being blocked. Click 'Open Anyway'. 4. Alternatively, select the option \"App Store and identified developers\" to allow all applications from the App Store and identified developers to run. - This message is displayed when you run `defang generate` and the target folder is not empty. If you proceed, Defang will overwrite any existing files with the same name. If you want to keep the existing files, you should move them to a different folder before running `defang generate` or pick a different target folder. - This message is displayed when you run `defang compose up` and the Compose file references an environment variable that is not set. If you proceed, the environment variable will be empty in the container. If you want to set the environment variable, you should set it in the environment where you run `defang compose up`. - This message is displayed when you run `defang compose up` and the Compose file references a platform that is not supported by Defang. Defang Beta only supports Linux operating systems. - This message is displayed when you run `defang compose config` but you are not logged in. The displayed configuration will be incomplete. If you want to see the complete configuration, you should log in first using `defang login`. - This message is displayed when you run `defang compose up` and the Compose file declares a `port` that does not specify a port `mode`. By default, Defang will keep the port private. If you want to expose the port to the public internet, you should specify the `mode` as `ingress`: ``` services: service1: … ports: - target: 80 mode: ingress ``` - This message is displayed when you run `defang compose up` and the Compose file declares a `port` with `mode` set to `ingress` and `published` set to a port number. Defang does not support published ports in ingress mode. If you want to expose the port to the public internet, you should specify the `mode` as `ingress` and remove the `published` setting. - This message is displayed when you run `defang compose up` and the Compose file declares a `port` with `mode` set to `ingress` and `protocol` set to `tcp`. Defang does not support arbitrary TCP ingress and will assume the port is used for HTTP traffic. To silence the warning, remove the `protocol` setting. - This message is displayed when you run `defang compose up` and the Compose file declares a directive that is not supported by Defang. The deployment will continue, but the unsupported directive will be ignored, which may cause unexpected behavior. - This message is displayed when you run `defang compose up` and the Compose file declares a `resource` with `limits` but no `reservations`. Defang will use the `limits` as `reservations` to ensure the container has enough resources. Specify `reservations` if you want to silence the warning or reserve a different amount of resources: ``` services: service1: … deploy: resources: reservations: cpus: 0.5 memory: 512MB ``` - This message is displayed when you run `defang compose up` and the Compose file declares an `ingress` with a `port` but no `healthcheck`. Defang will assume the default healthcheck of `GET / HTTP/1.1` to ensure the port is healthy. Specify a `healthcheck` if you want to silence the warning or use a different healthcheck: ``` services: service1: … deploy: healthcheck: test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:80/health\"] ``` - This message is displayed when you run `defang compose up` and the Compose file doesn't specify a `memory` reservation. If available, Defang will use the `memory` limit as the `memory` reservation. Specify a `memory` reservation if you want to silence the warning or reserve a different amount of memory: ``` services: service1: … deploy: resources: reservations: memory: 512MB ``` - This message is displayed when you run `defang compose up` and the Compose file declares a `build` with a `context` that contains more than 10 files. Ensure the context refers to the correct folder. Defang will use the `context` as is, but you may experience slow build times. If you want to speed up the build, you should reduce the number of files in the `context`. - This message is displayed when you run `defang compose up` with the `--provider=aws` but none of the AWS environment variables were not set. If you proceed, the deployment might fail. - This message is displayed when you run `defang compose up` with the `--provider=defang` but AWS environment variables were detected. The AWS environment variables will be ignored. - This message is displayed when you run `defang compose up` and the Compose file declares a `secret` that is not defined in the top-level `secrets` section. To silence the warning, define the secret in the top-level `secrets` section: ``` services: service1: … secrets: - my_secret secrets: my_secret: external: true ``` - This message is displayed when you run `defang compose up` and the Compose file declares a `secret` that is not marked `external:true`. Defang only supports external secrets, managed by the `defang config` command. To silence the warning, mark the secret as `external:true` in the top-level `secrets` section: ``` … secrets: my_secret: external: true ``` - This happens if different version of the Defang CLI are used with the same AWS account. Each version one will try to update the CD stack to its version, back and forth. Make sure that all users have the same version of the CLI. Check the CLI version using `defang version`." + }, + { + "id": 4, + "about": "GCP", + "text": ":::info We will be working on GCP support in the future. If you are interested in GCP support, please vote on [this issue](https://github.com/DefangLabs/defang/issues/58). :::" + }, + { + "id": 5, + "about": "AWS, Getting Started, Region, Architecture, Secrets, Deployment, Runtime", + "text": ":::info Public Beta of the v1 Defang BYOC AWS Provider is released as of Feb 1 2024. ::: Why should you use Defang with AWS? Defang allows you to easily create and manage full, scalable applications with AWS. Defang aims to make it easier to deploy your services to the cloud. Don't waste your time learning the ins and outs of AWS, deciding which of the 200+ services to use, and then writing the infrastructure code to deploy your services, and making sure they are properly secured. Defang does all of that for you. Getting started with the Defang BYOC AWS Provider is easy. First, make sure you [install the latest version of the Defang CLI](../getting-started#authenticate-with-defang). Then, make sure you have properly [authenticated your AWS account](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). The Defang CLI will automatically check for environment variables like `AWS_PROFILE`, `AWS_REGION`, `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. If they are set, the CLI will automatically use the Defang BYOC AWS Provider using the appropriate credentials. If you have credentials in the `~/.aws/credentials` file, but nothing configured in environment variables, you can use the `--provider=aws` flag to tell the Defang CLI to use the AWS Provider. :::tip If you have the aws CLI installed, you should be able to successfully run `aws sts get-caller-identity` and see your account ID. ::: :::warning The Defang CLI does not depend on the AWS CLI. It uses the [AWS SDK for Go](https://aws.amazon.com/sdk-for-go/) to interact with your AWS account. In most cases, if you can run the `aws sts get-caller-identity` from the tip above, you should be good to go. However, due to a difference between the AWS CLI and the AWS SDK for Go, there is at least one case where they behave differently: if you are using `aws sso login` and have clashing profiles in your `.aws/config` and `.aws/credentials` files, the AWS CLI will prioritize SSO profiles and caches over regular profiles, but the AWS SDK for Go will prioritize the credentials file, and it may fail. ::: The Defang BYOC AWS Provider will use the region specified in the `AWS_REGION` environment variable, or a profile in the `~/.aws/config` file exactly as the AWS CLI would. Defang uses resources that are native to the cloud provider you are using. The following describes the current state of Defang's support for AWS, the specific resources that Defang uses, and the roadmap for future support. Defang allows you to configure your services with sensitive config values. Sensitive values are stored in AWS Systems Manager Parameter Store, and are encrypted. To deploy your services, the Defang CLI packages your code and uploads it to an S3 bucket in your account. The CLI then deploys an ECS task that uses Pulumi to build your container image and run your service. The provider runs your workloads using ECS using Fargate. It provisions a VPC with public and private subnets, and deploys your services to the private subnets. It then provisions an Application Load Balancer (ALB) and routes traffic to your services." + }, + { + "id": 6, + "about": "Azure", + "text": ":::info We will be working on Azure support in the future. If you are interested in Azure support, please vote on [this issue](https://github.com/DefangLabs/defang/issues/57). :::" + }, + { + "id": 7, + "about": "Manage personal access tokens", + "text": "```\ndefang token [flags]\n```\n\n### Options\n\n```\n --expires duration validity duration of the token (default 24h0m0s)\n -h, --help help for token\n --scope string scope of the token; one of [admin read tail] (required)\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 8, + "about": "Cancel the current CD operation", + "text": "```\ndefang cd cancel [flags]\n```\n\n### Options\n\n```\n -h, --help help for cancel\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n- [defang cd](defang_cd.md) - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 9, + "about": "Like 'start' but immediately tracks the progress of the deployment", + "text": "```\ndefang compose up [flags]\n```\n\n### Options\n\n```\n -d, --detach run in detached mode\n --force force a build of the image even if nothing has changed\n -h, --help help for up\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 10, + "about": "List all the projects and stacks in the CD cluster", + "text": "```\ndefang cd ls [flags]\n```\n\n### Options\n\n```\n -h, --help help for ls\n --remote invoke the command on the remote cluster\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 11, + "about": "Reads a Compose file and shows the generated config", + "text": "```\ndefang compose config [flags]\n```\n\n### Options\n\n```\n -h, --help help for config\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 12, + "about": "Read and/or agree the Defang terms of service", + "text": "```\ndefang terms [flags]\n```\n\n### Options\n\n```\n --agree-tos agree to the Defang terms of service\n -h, --help help for terms\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 13, + "about": "Generate a TLS certificate", + "text": "```\ndefang cert generate [flags]\n```\n\n### Options\n\n```\n -h, --help help for generate\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cert](defang_cert.md)\t - Manage certificates\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 14, + "about": "Work with local Compose files", + "text": "### Options\n\n```\n -h, --help help for compose\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n* [defang compose config](defang_compose_config.md)\t - Reads a Compose file and shows the generated config\n* [defang compose down](defang_compose_down.md)\t - Like 'stop' but also deprovisions the services from the cluster\n* [defang compose restart](defang_compose_restart.md)\t - Reads a Compose file and restarts its services\n* [defang compose start](defang_compose_start.md)\t - Reads a Compose file and deploys services to the cluster\n* [defang compose stop](defang_compose_stop.md)\t - Reads a Compose file and stops its services\n* [defang compose up](defang_compose_up.md)\t - Like 'start' but immediately tracks the progress of the deployment\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 15, + "about": "Add, update, or delete service config", + "text": "### Options\n\n```\n -h, --help help for config\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n* [defang config create](defang_config_create.md)\t - Adds or updates a sensitive config value\n* [defang config ls](defang_config_ls.md)\t - List configs\n* [defang config rm](defang_config_rm.md)\t - Removes one or more config values\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 16, + "about": "Adds or updates a sensitive config value", + "text": "```\ndefang config create CONFIG [file] [flags]\n```\n\n### Options\n\n```\n -h, --help help for create\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang config](defang_config.md)\t - Add, update, or delete service config\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 17, + "about": "Destroy the service stack", + "text": "```\ndefang cd destroy [flags]\n```\n\n### Options\n\n```\n -h, --help help for destroy\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 18, + "about": "Get version information for the CLI and Fabric service", + "text": "```\ndefang version [flags]\n```\n\n### Options\n\n```\n -h, --help help for version\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 19, + "about": "Tail logs from one or more services", + "text": "```\ndefang tail [flags]\n```\n\n### Options\n\n```\n --etag string deployment ID (ETag) of the service\n -h, --help help for tail\n -n, --name string name of the service\n -r, --raw show raw (unparsed) logs\n -S, --since string show logs since duration/time\n --utc show logs in UTC timezone (ie. TZ=UTC)\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 20, + "about": "Log out", + "text": "```\ndefang logout [flags]\n```\n\n### Options\n\n```\n -h, --help help for logout\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 21, + "about": "Reads a Compose file and deploys services to the cluster", + "text": "```\ndefang compose start [flags]\n```\n\n### Options\n\n```\n --force force a build of the image even if nothing has changed\n -h, --help help for start\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 22, + "about": "Generate a sample Defang project in the current folder", + "text": "```\ndefang generate [SAMPLE] [flags]\n```\n\n### Options\n\n```\n -h, --help help for generate\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 23, + "about": "Destroy the CD cluster without destroying the services", + "text": "```\ndefang cd teardown [flags]\n```\n\n### Options\n\n```\n --force force the teardown of the CD stack\n -h, --help help for teardown\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 24, + "about": "Get list of services on the cluster", + "text": "```\ndefang services [flags]\n```\n\n### Options\n\n```\n -h, --help help for services\n -l, --long show more details\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 25, + "about": "Defang CLI manages services on the Defang cluster", + "text": "### Options\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -h, --help help for defang\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n* [defang cert](defang_cert.md)\t - Manage certificates\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n* [defang config](defang_config.md)\t - Add, update, or delete service config\n* [defang generate](defang_generate.md)\t - Generate a sample Defang project in the current folder\n* [defang login](defang_login.md)\t - Authenticate to the Defang cluster\n* [defang logout](defang_logout.md)\t - Log out\n* [defang restart](defang_restart.md)\t - Restart one or more services\n* [defang services](defang_services.md)\t - Get list of services on the cluster\n* [defang tail](defang_tail.md)\t - Tail logs from one or more services\n* [defang terms](defang_terms.md)\t - Read and/or agree the Defang terms of service\n* [defang token](defang_token.md)\t - Manage personal access tokens\n* [defang version](defang_version.md)\t - Get version information for the CLI and Fabric service\n* [defang whoami](defang_whoami.md)\t - Show the current user\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 26, + "about": "Manually run a command with the CD task (for BYOC only)", + "text": "### Options\n\n```\n -h, --help help for cd\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n* [defang cd cancel](defang_cd_cancel.md)\t - Cancel the current CD operation\n* [defang cd destroy](defang_cd_destroy.md)\t - Destroy the service stack\n* [defang cd down](defang_cd_down.md)\t - Refresh and then destroy the service stack\n* [defang cd ls](defang_cd_ls.md)\t - List all the projects and stacks in the CD cluster\n* [defang cd refresh](defang_cd_refresh.md)\t - Refresh the service stack\n* [defang cd teardown](defang_cd_teardown.md)\t - Destroy the CD cluster without destroying the services\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 27, + "about": "Refresh the service stack", + "text": "```\ndefang cd refresh [flags]\n```\n\n### Options\n\n```\n -h, --help help for refresh\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 28, + "about": "Refresh and then destroy the service stack", + "text": "```\ndefang cd down [flags]\n```\n\n### Options\n\n```\n -h, --help help for down\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang cd](defang_cd.md)\t - Manually run a command with the CD task (for BYOC only)\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 29, + "about": "Reads a Compose file and restarts its services", + "text": "```\ndefang compose restart [flags]\n```\n\n### Options\n\n```\n -h, --help help for restart\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 30, + "about": "Restart one or more services", + "text": "```\ndefang restart SERVICE... [flags]\n```\n\n### Options\n\n```\n -h, --help help for restart\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 31, + "about": "Like 'stop' but also deprovisions the services from the cluster", + "text": "```\ndefang compose down [flags]\n```\n\n### Options\n\n```\n -d, --detach run in detached mode\n -h, --help help for down\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 32, + "about": "Authenticate to the Defang cluster", + "text": "```\ndefang login [flags]\n```\n\n### Options\n\n```\n -h, --help help for login\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 33, + "about": "Reads a Compose file and stops its services", + "text": "```\ndefang compose stop [flags]\n```\n\n### Options\n\n```\n -h, --help help for stop\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang compose](defang_compose.md)\t - Work with local Compose files\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 34, + "about": "Show the current user", + "text": "```\ndefang whoami [flags]\n```\n\n### Options\n\n```\n -h, --help help for whoami\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 35, + "about": "List configs", + "text": "```\ndefang config ls [flags]\n```\n\n### Options\n\n```\n -h, --help help for ls\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang config](defang_config.md)\t - Add, update, or delete service config\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 36, + "about": "Manage certificates", + "text": "### Options\n\n```\n -h, --help help for cert\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang](defang.md)\t - Defang CLI manages services on the Defang cluster\n* [defang cert generate](defang_cert_generate.md)\t - Generate a TLS certificate\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 37, + "about": "Removes one or more config values", + "text": "```\ndefang config rm CONFIG... [flags]\n```\n\n### Options\n\n```\n -h, --help help for rm\n```\n\n### Options inherited from parent commands\n\n```\n -s, --cluster string Defang cluster to connect to (default \"fabric-prod1.defang.dev\")\n --color color-mode colorize output; \"auto\", \"always\" or \"never\" (default auto)\n -C, --cwd string change directory before running the command\n --debug debug logging for troubleshooting the CLI\n --dry-run dry run (don't actually change anything)\n -f, --file string compose file path\n -T, --non-interactive disable interactive prompts / no TTY\n -P, --provider provider cloud provider to use; use \"aws\" for bring-your-own-cloud (default auto)\n -v, --verbose verbose logging\n```\n\n### SEE ALSO\n\n* [defang config](defang_config.md)\t - Add, update, or delete service config\n\n###### Auto generated by spf13/cobra on 12-Aug-2024" + }, + { + "id": 38, + "about": "Use Cases, Web Services and APIs, Mobile App Backends, Hosting LLMs", + "text": "Defang can be used for a wide variety of use cases, generally in line with the [12 Factor architecture](https://12factor.net/). In this section we'll document some examples. At the end of this section we will also cover use cases that are not supported by Defang. Defang can be used to deploy web services and APIs. You can use any programming language you like, and you can use the built-in AI assistant to help you get started. Defang is a great choice for stateless web services and APIs because it takes care of all the heavy lifting such as configuring [networking](../concepts/networking.mdx), [security](../concepts/security.md), and [observability](../concepts/observability.md), and will give you a nice, [horizontally scalable](https://12factor.net/concurrency) deployment. If you are using [Defang BYOC](../concepts/defang-byoc.md), you can easily connect to databases, storage, and other services that you have running in your cloud account. A mobile app backend is a web service or API that is used by a mobile app. Defang is a great choice for mobile app backends because it helps you deploy horizontally scalable web services and APIs. It's also particularly useful for mobile app developers who aren't familiar with cloud infrastructure: you don't need to be a cloud expert, or even a web expert to use Defang and properly provision all the necessary infrastructure for your app's backend. LLMs (Large Language Models) are a type of AI model that can be used for a wide variety of tasks such as text generation, translation, summarization, and more. Defang can be used to host LLMs and provide an API for them. Configuring cloud providers like AWS to easily run containerized workloads that depend on GPUs can be quite challenging, but Defang makes it easy." + }, + { + "id": 39, + "about": "Anti-patterns, Stateful Services, Data Stores", + "text": "While Defang is great for a wide variety of use cases, there are some use cases that are not a good fit for Defang. Generally, the use-cases that are Defang anti-patterns are the same as the ones that are [12 Factor](https://12factor.net/) anti-patterns. Here are some examples: Some applications are designed to run in stateful environments. For example, a CMS like WordPress can be coerced to work in a stateless environment, but most of the tooling for it expects to have a long-lived filesystem and a database. Defang is not a good fit for these types of applications, because [containers are ephemeral and can be replaced at any time](https://12factor.net/processes). Defang is not a good fit for data stores like databases, caches, and message queues. These types of services are designed to be long-lived and to store data. Defang is primarily designed for stateless workloads, and it's not a good fit for stateful workloads: if a container is replaced, all the data in it is lost. You could probably coerce a data store to work in a stateless environment with certain replication strategies, but it's not a good fit." + }, + { + "id": 40, + "about": "Installing, Using Homebrew, Using a Bash Script, Using Winget, Direct Download", + "text": "Defang doesn't require installing anything in your cloud, but you will need to install the [open source](https://github.com/DefangLabs/defang) Defang command line interface (CLI) to interact with your Defang resources and account. We offer a few different ways to install the Defang CLI. You can use Homebrew, a bash script, Winget, or download the binary directly. You can easily install the Defang CLI using [Homebrew](https://brew.sh/). Run the following command in your terminal: ```bash brew install DefangLabs/defang/defang ``` You can install the Defang CLI using a bash script. Run the following command in your terminal: ```bash . <(curl -Ls s.defang.io/install) ``` The script will try to download the appropriate binary for your operating system and architecture, add it to `~/.local/bin`, and add `~/.local/bin` to your `PATH` if it's not already there, with your permission. If you do not provide permission it will print an appropriate instruction for you to follow to add it manually. You can also customize the installation directory by setting the `INSTALL_DIR` environment variable before running the script. On Windows, you can install the Defang CLI using `winget`. Run the following command in your terminal: ```powershell winget install defang ``` You can find the latest version of the Defang CLI on the [releases page](https://github.com/DefangLabs/defang/releases). Just download the appropriate binary for your operating system and architecture, and put it somewhere in your `PATH`." + }, + { + "id": 41, + "about": "Getting Started, Install the CLI, Authenticate with Defang, Agree to the terms of service, Build and Deploy Services, Monitor Services, Update Services", + "text": "First, you'll need to install the Defang CLI. The CLI is the primary way to interact with Defang. It allows you to create, deploy, and manage your services. You can find the [different installation methods here](./installing.md). To do pretty much anything with Defang, you'll need to authenticate with the platform. You can do this by running the following command: ```bash defang login ``` :::info To learn more about how authentication works in defang, check out the [authenticating page](./authenticating.md). ::: Before you can deploy code you should read and agree to our the terms of service. You can do this by running: ```bash defang terms ``` Defang supports various ways of creating and deploying services to the cloud. The following tutorials dive into each one in more detail: 1. [Deploy an outline using AI](../tutorials/generate-new-code-using-ai.mdx) 2. [Build and deploy your code](../tutorials/deploy-code-compose.mdx) 3. [Deploy existing containers](../tutorials/deploy-container-using-the-cli.mdx) 4. [Deploy using Pulumi](../tutorials/deploy-using-pulumi.mdx) By default, all the output (stdout and stderr) from your app is logged. You can view these logs in real-time. You can view logs for all your services, one service, or even one specific deployment of a service. - From the CLI: ```tsx defang tail --name service1 ``` - From the Defang Portal: [https://portal.defang.dev/](https://portal.defang.dev/) :::info * To learn more about observability in Defang, check out the [observability page](../concepts/observability.md). * Note that the Defang Portal only displays services deployed to Defang Playground. ::: To update your app (for example, updating the base image of your container, or making changes to your code) you can run the `defang compose up` command and it will build and deploy a new version with zero downtime. Your current version of the service will keep running and handling traffic while the new version is being built and deployed. Only after the new version passes the health checks and accepts traffic will the older version be stopped. :::info If you are using [compose files](../concepts/compose.md) to define your services, you can add/remove services, make changes to code, etc. When you run `defang compose up`, the update will be diffed against the current state and any necessary changes will be applied to make the current state match the desired state. :::" + }, + { + "id": 42, + "about": "Monitor a Service", + "text": "By default, all the output (stdout and stderr) from your app is logged. You can view these logs in real-time. You can view logs for all your services, one service, or even one specific deployment of a service. - From the CLI: ```tsx defang tail --name service1 ``` - From the Defang Portal: [https://portal.defang.dev/](https://portal.defang.dev/) :::info * To learn more about observability in Defang, check out the [observability page](../concepts/observability.md). * Note that the Defang Portal only displays services deployed to Defang Playground. :::" + }, + { + "id": 43, + "about": "Authenticating", + "text": "To do pretty much anything with Defang, you'll need to authenticate with the platform. You can do this by running the following command: ```bash defang login ``` This will prompt you to open a browser and log into your Defang account. For now, the only way to login is with GitHub, though we will offer other providers to authenticate in the future. Once you've logged in, you can close the browser and return to the terminal. You should see a message that you've successfully logged in. :::warning Keep in mind that your Defang account is separate from your [cloud provider account](../concepts/defang-byoc.md). You will need to authenticate with your cloud provider account separately to deploy services to your own cloud account. :::" + }, + { + "id": 44, + "about": "Update Services", + "text": "To update your app (for example, updating the base image of your container, or making changes to your code) you can run the `defang compose up` command and it will build and deploy a new version with zero downtime. Your current version of the service will keep running and handling traffic while the new version is being built and deployed. Only after the new version passes the health checks and accepts traffic will the older version be stopped. :::info If you are using [compose files](../concepts/compose.md) to define your services, you can add/remove services, make changes to code, etc. When you run `defang compose up`, the update will be diffed against the current state and any necessary changes will be applied to make the current state match the desired state. :::" + }, + { + "id": 45, + "about": "Build and Deploy Services", + "text": "Defang supports various ways of creating and deploying services to the cloud. The following tutorials dive into each one in more detail: 1. [Create an outline using AI](../tutorials/generate-new-code-using-ai.mdx) 2. [Build and deploy your code](../tutorials/deploy-code-compose.mdx) 3. [Deploy an existing container](../tutorials/deploy-container-using-the-cli.mdx) 4. [Deploy using Pulumi](../tutorials/deploy-using-pulumi.mdx)" + }, + { + "id": 46, + "about": "Resources, Examples, Docker Compose, Pulumi", + "text": "You can configure the resources available to your Defang services as required. You can configure the CPU, memory, and disk space allocated to your services as well as the number of replicas and whether or not your services requires access to GPUs. ```yaml services: gpu-service: deploy: replicas: 3 resources: reservations: cpus: '1.0' memory: 2048M devices: - capabilities: [\"gpu\"] ``` ```typescript const service = new defang.DefangService(\"gpu-service\", { deploy: { replicas: 3, resources: { reservations: { cpu: 1.0, memory: 2048, devices: [{capabilities: ['gpu']}] } } } }); ``` :::info GPUs If you require access to GPUs, you can specify this in the `deploy.resources.reservations.devices[0].capabilities` section of your service as in the examples above. You can learn more about this in the [docker-compose documentation](https://docs.docker.com/compose/gpu-support/). This is the only supported value in the `deploy.resources.reservations.devices` section. :::" + }, + { + "id": 47, + "about": "Deployment, Deploying Updates, Instance Types", + "text": "When you deploy using Defang, whether it's with `defang compose up` with a [compose file](./compose.md) or using a [Pulumi program](./pulumi.md), Defang will build your services in the cloud and manage the deployment process for you. If you provide a Dockerfile and build context, Defang will upload the files found within the build context to the cloud (either yours in [Defang BYOC](./defang-byoc.md) or ours in [Defang Playground](./defang-playground.md)), build the image, and store it in the cloud provider's container registry. When you run a deployment to update one or more services, Defang will also make sure to get your new services up and running before deprovisioning any old services so you don't have to worry about downtime. :::info In [Defang BYOC](./defang-byoc.md), Defang will use your cloud provider account to build and store your images. In [Defang Playground](./defang-playground.md) we will build and store your images for you. ::: :::warning Workloads with GPUs do not support zero downtime deployments. If you have a workload with a GPU, you will experience downtime during updates. ::: Defang defaults to \"spot\" instances. This is a cost-effective way to run your workloads, but it does mean that your workloads can be interrupted at any time. This is consistent with the [12 Factor](https://12factor.net/) principle of [disposability](https://12factor.net/disposability). :::info In the future, we may provide a way to use \"on-demand\" instances for workloads that require more stability. :::" + }, + { + "id": 48, + "about": "Pulumi, Defang Pulumi Provider, Sample", + "text": ":::warning Pulumi support is currently only available for Defang Playground. We are working on support for Defang BYOC. ::: You can use Pulumi to define your Defang services. This allows you to integrate your Defang services with other cloud resources. For example, you might define an Aiven PostgreSQL database in your Pulumi code and then use the outputs of that resource to configure the secrets to connect to the database in your Defang service. It also allows you to manage configuration for different environments using Pulumi's config system. To get started with Pulumi and Defang you will need to install the Defang provider in [your Pulumi project](https://www.pulumi.com/learn/pulumi-fundamentals/create-a-pulumi-project/): ```bash npm i @defang-io/pulumi-defang ``` ```bash pnpm i @defang-io/pulumi-defang ``` ```bash yarn add @defang-io/pulumi-defang ``` The following is a minimal example of a Pulumi program that defines a Defang service: ```typescript import * as defang from \"@defang-io/pulumi-defang/lib\"; const service = new defang.DefangService(\"my-service\", { image: \"strm/helloworld-http:latest\", ports: [ { target: 80, mode: \"ingress\", protocol: \"http\", }, ], }); ```" + }, + { + "id": 49, + "about": "Portal", + "text": "You can log into the Defang portal at [portal.defang.dev](https://portal.defang.dev) using your [Defang account](./accounts.md) to view the state of your Defang services running in the Defang Playground for non-production applications. You can use the portal to get an overview of your services, view the logs for each service, quickly access exposed ports, view environment variables, and more. :::info We will make sure you have access to the tools required to debug your services in production. At the moment we're not entirely sure what that will look like, beyond `defang tail` to view logs, but we're working on it! :::" + }, + { + "id": 50, + "about": "Accounts, Creating an Account, Structure", + "text": "In this section, we'll be talking about a couple different topics related to accounts in Defang. First we'll cover authentication and how to create an account, and then we'll talk about how resources are organized within a cloud environment using your account info. :::tip Why do I need an account? Defang requires an account so we can organize your resources and provide you with a way to manage them. We also use your account to authenticate you when you interact with [Defang Playground](./defang-playground.md) and the [Defang Portal](./portal.md). Eventually, billing and payment information will be associated with your account. ::: To create an account, simply login to Defang and accept the [terms of service](https://defang.io/terms-service.html) using the [CLI](../getting-started/authenticating.md). At the moment, the only way to authenticate with Defang is through GitHub. We plan to offer other authentication providers in the future. Your GitHub username will be used as your Defang username and your Defang username is used to group all your services and to generate domains for your services with the following structure: ``` ---.prod1.defang.dev ``` :::warning Keep in mind that your Defang account is separate from your [cloud provider account](./defang-byoc.md). You will need to authenticate with your cloud provider account separately to deploy services to your own cloud account. ::: :::info We plan to introduce a more robust system for managing accounts, permissions, service groups, etc. in the future. :::" + }, + { + "id": 51, + "about": "Compose, How it works, Service Name Resolution, Configuration", + "text": "You might be familiar with `docker-compose.yml` files, now known as the [Compose specification](https://docs.docker.com/compose/compose-file/) and `compose.yaml` files. It's a simple way to define and run multi-container Docker applications. Defang allows you to use `compose.yaml` files to deploy your application to the cloud. You can define your [services](./services.md) using a `compose.yaml` file in the root of your project, or use the [`defang generate` command](../tutorials/generate-new-code-using-ai.mdx) to generate one (along with other resources). This file is used to define your application's services and how they run. You can edit this file to add more services or change the configuration of existing services. When you run `defang up`, Defang will read your `compose.yaml` file and [deploy](./deployments.md) the services named in that file to the cloud. One thing to keep in mind is that, at the time of this writing, Defang identifies services by the [user/account name](./accounts.md) and the service name (as defined in the `compose.yaml` file). This means that if you have multiple Defang projects with the same service name, they will conflict with each other. We plan to provide a more robust system for managing service names and protecting against conflicts in the future. If you have a service that depends on a secret like an api key, you can set that [secret](./configuration.md) using the CLI: ``` defang config set --name MY_API_KEY ``` and then connect it to the service by specifying it in the `compose.yaml`: ```yaml services: my-service: secrets: - MY_API_KEY secrets: MY_API_KEY: external: true ``` :::info Configuration & Secrets Read more about configuration in the [configuration page](./configuration.md) and about secrets in the [secrets page](./configuration.md). :::" + }, + { + "id": 52, + "about": "Configuration", + "text": "Defang allows you to configure your application using environment variables. You can set environment variables in your [`compose.yaml` file](./compose.md), or in your [Pulumi program](./pulumi.md). Using Pulumi gives you the advantage of being able to manage your environment variables across different environments using Pulumi stacks. :::tip Sample You can find a sample of how to set environment variables with Pulumi [here](https://github.com/DefangLabs/defang/tree/main/samples/nodejs/remix-aiven-postgres). :::" + }, + { + "id": 53, + "about": "Sensitive Config aka Secrets, Connecting Services, Providers", + "text": "The Defang CLI allows you to securely store sensitive information such as API keys, passwords, and other credentials. You can use sensitive config by specifying them in the `environment` section of a service in a `compose.yaml` file without any value, or by specifying an environment key with a `null` value in your Pulumi code. ```ts services: service1: image: image1: latest; environment: -API_KEY; ``` Use the `defang config` command of the Defang CLI to manage the values. If you have created a service before a secret you can connect it by running the `defang compose start` command if using the [`defang compose` workflow](./compose.md). If you are using the [Pulumi-based workflow](./pulumi.md) you will need to redeploy using Pulumi. :::tip Sample You can find a sample of how to set sensitive config values [here](https://github.com/DefangLabs/defang/tree/main/samples/nodejs/ChatGPT%20API). ::: Here are the different ways sensitive config values are stored depending on the provider you are using: * [AWS](../providers/aws.md#secrets)" + }, + { + "id": 54, + "about": "Defang Playground, Limitations, No Custom Domain Support, Max Resources", + "text": "Defang aims to make it easier to deploy your services to the cloud. Specifically, Defang's goal is to make it easier to deploy your workloads to your _own_ cloud accounts. We refer to this as bring-your-own-cloud (BYOC) which you can read about in more depth [here](./defang-byoc). We also provide Defang Playground, but it is only intended for non-production workloads so you can get a feel for how Defang works. Defang Playground is a free tier that allows you to deploy services to a Defang-hosted cloud account without needing to manage your own. It is intended for non-production workloads only. :::warning Please note that the Defang Playground is intended for testing/learning purposes only. The environment may be reset at any time. Do not run production workloads in Defang Playground. ::: There are a few limitations to Defang Playground. These limitations are in place to ensure that Defang Playground is only used for non-production workloads. If you are interested in running production workloads, you should use Defang BYOC. When you deploy a service to Defang Playground, it will be assigned a domain under the `defang.dev` domain. We do not support pointing your own domains to Defang Playground services. - Services: 5 - CPUs: 2 - Memory: 8GB - Replicas: 2" + }, + { + "id": 55, + "about": "Services", + "text": "Defang allows you deploy services defined as containers. You can define your services using a [compose file](./compose.md) or a [Pulumi program](./pulumi.md). Services can be exposed to the internet or kept private, and can communicate between themselves using the following conventions for hostnames: `-` You can learn more about accounts and usernames in the [accounts page](./accounts.md). :::tip Service Names Service names are defined in your compose file or your Pulumi program. ::: You can learn more about about how to define [services with compose files here](./compose.md) and [services with Pulumi here](./pulumi.md). You can learn more about how services are deployed in the [deployment page](./deployments.md). :::info While this is the current state of the Defang model, we plan to add support for other types of services in the future, including serverless functions. :::" + }, + { + "id": 56, + "about": "Defang BYOC, AWS, Azure, GCP", + "text": "Defang aims to make it easier to deploy your services to the cloud. Specifically, Defang's goal is to make it easier to deploy your workloads to your *own* cloud accounts. We refer to this as bring-your-own-cloud (BYOC). We also provide Defang Playground, but it is only intended for non-production workloads so you can get a feel for how Defang works. Defang provisions and configures the necessary native managed services from your cloud provider to get your services up and running. For example, on AWS, Defang will configure an [ALB](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/), setup [ECR](https://aws.amazon.com/ecr/), configure [CloudWatch](https://aws.amazon.com/cloudwatch/?nc2=type_a), and run your service on [ECS](https://aws.amazon.com/ecs/?nc2=type_a) and more. The following lists the existing and planned support for cloud providers. :::info Defang does not install or run any Defang or third party services at runtime. Defang does run the Defang build service to build your container images, which terminates after every build. ::: :::info Public Beta of the v1 Defang BYOC AWS Provider is released as of Feb 1 2024. ::: Please read the [AWS Provider](../providers/aws.md) documentation for more details about how the AWS provider works and how to get started. :::info We will be working on Azure support in the future. If you are interested in Azure support, please vote on [this issue](https://github.com/DefangLabs/defang/issues/57). ::: :::info We will be working on GCP support in the future. If you are interested in GCP support, please vote on [this issue](https://github.com/DefangLabs/defang/issues/58). :::" + }, + { + "id": 57, + "about": "Observability, Tail, Architecture", + "text": "You can easily monitor and debug your Defang services at build and runtime using the Defang CLI and portal. When you deploy a service using the `defang up` the CLI will automatically start tailing the build and runtime logs for your service. You can also view the logs for your service in the portal, or by using the `defang tail` command. :::warning Keep in mind that the Defang Portal only displays services deployed to Defang Playground. ::: The `defang tail` command will tail the logs for all your services by default. You can also specify a service `--name` to tail the logs for a specific service. If you specify the `--etag` the CLI will only tail the logs for a specific build of a service. ``` defang tail --name my-service defang tail --etag ua119053ehi2 ``` In [BYOC](./defang-byoc.md), output is logged to the native logging tools within your cloud provider. The CLI then tails the output as needed." + }, + { + "id": 58, + "about": "Security, Roles & Permissions, Networking, TLS, Secrets", + "text": "Defang's philosophy is to operate on a principle of \"least-privilege\". This means that we only give your services the permissions they need to operate. Because Defang creates roles, you need to have the appropriate permissions to create roles in your cloud provider account, typically the `AdministratorAccess` policy in AWS. :::tip Best practice is to run the Defang CLI in a CI/CD environment and to restrict deployment permissions at that level. ::: Defang creates roles for your services to use, and attaches policies to those roles. This means that your services only have the permissions they need to operate, and nothing more. Defang configures Security Groups, deploys applictions to a private subnet and uses an Application Load Balancer to route traffic to your services from the public internet only when required. Defang automates the process of obtaining and renewing TLS certificates for your services using AWS Certificate Manager. Secrets are stored in AWS Systems Manager Parameter Store, and are encrypted using a key stored in AWS Key Management Service (KMS)." + }, + { + "id": 59, + "about": "AI, Example Prompts", + "text": "Defang includes an AI-driven assistant that translates natural language prompts to an outline for your project that you can then refine. The AI assistant is available through the [Defang CLI](../getting-started/installing.md). :::info The AI assistant is currently in beta and only supports a limited set of prompts. We plan to expand the capabilities of the AI assistant in the future. ::: We are working on expanding the range of supported prompts and improving the accuracy of the AI assistant. If you have any feedback or suggestions, please let us know by [opening an issue](https://github.com/DefangLabs/defang/issues/new). Here are some example prompts that the AI assistant can help you with: ``` A basic service with 2 REST endpoints. The default endpoint will be for health check and should return a JSON object like this: { \"status\": \"OK\" }. The /echo endpoint will echo back all request parameters in the response. ``` ``` A simple service that runs in the cloud and serves a web page ``` ``` A simple flask app with one route that responds with a json object ``` ``` A simple next.js app that serves a static page ``` ``` A simple api with a single route built on express ```" + }, + { + "id": 60, + "about": "Defang with Codespaces and GitPod, Getting Started with Github Codespaces and Defang, Step 1: Clone the Defang Codespace Project, Step 2: Create a Codespace, Step 3: Open in VS Code Desktop, Step 4: Run Defang Login, Step 5: Verify Running Services, Getting Started with GitPod Workspace with Defang, Step 1: Clone the Defang GitPod Workspace Project, Step 2: Initialize GitPod Workspace, Step 3: Lauch VS Code from GitPod, Step 4: Run Defang Login, Step 5: Verify Running Services", + "text": " This tutorial will guide you to set up Defang in both Codespaces and Gitpod. Start by cloning the [Defang Github-Codespace](https://github.com/DefangLabs/github-codespace) repo and pushing it to your own account. This repository is configured with a Codespace that has Defang pre-installed. Once you've pushed to your own GitHub repo, you'll be able to create a Codespace by clicking the Code button, selecting the Codespaces tab, and clicking the + icon. This will set up a development environment with Defang already installed, which might take a few minutes. ![Create Codespace button screenshot](/img/codespace-tutorial/new-codespace.png) For the `defang login` command to work correctly, you must open the Codespace in VS Code desktop. This is required because the login process is designed to run on localhost. ![Open in vs code desktop button screenshot](/img/codespace-tutorial/desktop.png) Within a VS Code desktop terminal, execute the following command. ```bash defang login ``` Although it may initially refuse to connect on your localhost, going back will show a \"successfully logged in\" message, confirming that you're logged into Defang. Now that you're logged in, you can use Defang commands. You can test that everything is working properly by running `defang ls` to list your running services. Start by cloning the [Defang Gitpod-Workspace](https://github.com/DefangLabs/gitpod-workspace) repo and pushing it to your own GitHub, GitLab, or BitBucket account. This repository includes a Workspace configuration that pre-installs Defang. Navigate `https://gitpod.io/#` to create your new workspace. In the repository, we have a yaml file indicating that we are using a pre-built dockerfile which installs Defang CLI for you. Open VS Code from GitPod, you will likely need to have the GitPod VS Code extension installed. ![Open in vs code desktop button screenshot](/img/codespace-tutorial/gitpod-desktop.png) ![Screenshot of GitPod extension](/img/codespace-tutorial/gitpod-ext.png) Within a VS Code desktop terminal, execute the following command. ```bash defang login ``` Now that you're logged in, you can use Defang commands. You can test that everything is working properly by running `defang ls` to list your running services." + }, + { + "id": 61, + "about": "Windows Experience Improvements", + "text": "For our Windows users out there, we've made some changes to make your Defang experience even smoother: * You can now install Defang using `winget`, the Windows Package Manager, for a streamlined setup * We've introduced a signed binary for added security and peace of mind Deploying your apps from Windows just got a little bit nicer." + }, + { + "id": 62, + "about": "One-click Deploy", + "text": "We've added a new feature that will make it even easier to get started with Defang. We've created a flow where each sample provides a button that allows you to immediately deploy a template with a GitHub action which will automatically deploy the sample to the Defang Playground. That means you can easily make changes by committing them to your brand new repo, and everything automatically updates in the Playground. It's a great way to get started with Defang and start experimenting with your own projects. Try it now [from our portal](https://portal.defang.dev/sample)! ![screenshot of 1-click deploy UI in portal](/img/july-update/1-click-deploy.png)" + }, + { + "id": 63, + "about": "Managed redis and redis Updates", + "text": "We first introduced this last month, but we've since rolled it out to everyone. We also added a sample that showcases the power of managed redis and redis: [BullMQ with Redis](https://github.com/DefangSamples/sample-bullmq-bullboard-redis-template). It demonstrates how you can use BullMQ and BullBoard with a managed redis and redis instance to create a powerful job queue system so you can easily build robust, scalable applications in AWS with Defang." + }, + { + "id": 64, + "about": "Updated Samples", + "text": "We've updated our sample projects to showcase how to use them with Defang, including: * [ASP.NET Core](https://github.com/DefangSamples/sample-csharp-dotnet-template) * [Feathers.js](https://github.com/DefangSamples/sample-feathersjs-template) * [Flask & LangChain](https://github.com/DefangSamples/sample-langchain-template) * [BullMQ with Redis](https://github.com/DefangSamples/sample-bullmq-bullboard-redis-template) Check them out if you're looking for some inspiration or a starting point for your own projects." + }, + { + "id": 65, + "about": "CLI Updates", + "text": "We're always looking for ways to enhance the CLI experience. Here's what's new: * `npx defang` automatically checks to always have the latest version of the CLI * The output during `defang compose up` has been streamlined to focus on the most important information * `defang tail` now supports listening to specific services, making it easier to troubleshoot issues * We've improved hints and error messages to better guide you when something goes wrong * The CLI now has improved color support for light theme terminals, making it easier on the eyes It's the small refinements that can make a big difference in your workflow." + }, + { + "id": 66, + "about": "Other Updates", + "text": "Here are a few more things that didn't quite fit with the rest: * Visibility into ECS deployment events in BYOC tail logs * Improvements to ACME certificate generation Keep an eye out for these updates in the near future. --- As always, we'd love your help shaping the future of Defang, so let us know what you'd like to see next. Happy deploying! 🚀" + }, + { + "id": 67, + "about": "Samples, samples, samples!, Start from a sample in seconds, Sample templates", + "text": "We've been cranking out samples like there's no tomorrow. We've published samples to get you up and running with FastAPI, Elysia, Angular, React, Svelte, Sveltekit, Sails.js, Phoenix, and more. You can filter through them on the [Defang homepage](https://defang.io/#deploy). Check out our video about all the [new samples and functionality](https://www.youtube.com/watch?v=8wIU_af-sX8). With all this work we've been putting into samples, we realized it would be pretty awesome if you could clone a sample faster. So we updated the CLI. Now, if you run `defang generate` you'll be able to filter through the samples and choose one. You can also filter through the samples on the [Defang homepage](https://defang.io/#deploy) and clone any of them with a simple command like `defang new sveltekit`. If you look through our [GitHub organization](https://github.com/DefangLabs), you'll start seeing loads of repos with the structure `sample--template`. If you open them, you can create a new repo by clicking this button: ![screenshot of github UI pointing towards template button](https://github.com/DefangLabs/defang-docs/assets/910895/97d33d90-43b9-499a-b139-e114b701adcb) Not only will that create a new repo based on the sample in your account, but if you've used Defang before (and accepted the Terms and Conditions) it will automatically deploy it to the playground so you can start playing with Defang immediately." + }, + { + "id": 68, + "about": "ACME for BYOD", + "text": "We’re excited to announce that ACME support is now available for Bring Your Own Domain (BYOD) in both Bring Your Own Cloud (BYOC) and Playground. This means you can easily add Let's Encrypt certificates to your custom domains, regardless of where your DNS is hosted. Defang will handle the certificate generation and automatic renewal for you. Nice and easy." + }, + { + "id": 70, + "about": "Managed redis and redis!", + "text": "Redis is such a versatile tool that can help with so many different use cases. So we've introduced Managed redis and redis! You can now specify the Redis image in your `compose.yaml` file and indicate that you want it managed by your cloud provider using `x-defang-redis: true` in your service definition." + }, + { + "id": 71, + "about": "Load Testing", + "text": "To make sure Defang is ready for loads of new users, we've been doing a lot of load testing. This is going to help us identify and address potential bottlenecks so we can make sure that Defang scales efficiently and handles all you new users smoothly." + }, + { + "id": 72, + "about": "Upgraded Kaniko", + "text": "We’ve upgraded our Kaniko integration to version 1.23.0 to improve your container build experience. The new version comes with several bug fixes that enhance stability and performance. This means faster and more reliable builds for your applications." + }, + { + "id": 73, + "about": "Upcoming Features, Managed Postgres, BYOC ECS Lifecycle Events", + "text": "We’re not stopping here! Here’s a sneak peek at what’s coming soon: Building on the momentum of Managed redis and redis, we’re introducing Managed Postgres. Soon you’ll be able to easily integrate a managed Postgres database into your deployment! Defang runs your services with ECS, and we're working on making it clearer what's happening under the hood. --- Stay tuned for more updates and improvements. As always, we appreciate your feedback and are committed to making Defang the easiest way to deploy your applications to the cloud. Go deploy something awesome! 🚀" + }, + { + "id": 74, + "about": "Announcing the Defang Public Beta**", + "text": "" + }, + { + "id": 75, + "about": "A radically simpler way for developers to create, deploy, and manage cloud applications.**", + "text": "Ever since we shipped our Private Beta in the summer of 2023, we have been working with early adopters and listening to their feedback. While these early customers loved the ease with which they could create, deploy, and manage a cloud application, they had one big request - to deploy their applications to their own cloud (e.g. AWS) account. This was important to them for a number of reasons - to leverage their cloud credits, to enforce their IAM roles and security settings, to integrate new application components with their existing deployments, and more. And so, today with our Public Beta, we are addressing this request. With today’s release of [Defang BYOC](https://docs.defang.io/docs/concepts/defang-byoc) (Bring-your-own-Cloud), you can now enjoy all the benefits of Defang ** and** deploy applications to your own AWS account! Our Private Beta experience is still available as [Defang Playground](https://docs.defang.io/docs/concepts/defang-playground) for you to quickly and easily prototype applications and deploy them to our hosted environment. You can learn more about Defang [here](https://docs.defang.io/docs/intro). Also check out our [tutorials](https://docs.defang.io/docs/category/tutorials), [samples](https://docs.defang.io/docs/samples), and [FAQ](https://docs.defang.io/docs/faq) to know more." + }, + { + "id": 76, + "about": "Try the Public Beta!**", + "text": "To try the Public Beta, please go to [defang.io](http://defang.io) and click on [Download](https://github.com/DefangLabs/defang/releases/latest) to download the CLI and [get started](https://docs.defang.io/docs/getting-started). We would love to have you kick the tires and give us your feedback! Once you sign up you’ll receive an invitation to our Slack support channel in email. You are also welcome to file [Github issues here](https://github.com/DefangLabs/defang/issues)." + }, + { + "id": 77, + "about": "Stay Tuned for More**", + "text": "While the Public Beta is an important step forward, we have already heard requests for additional features - from support for additional cloud platforms such as Azure and GCP, to the ability to easily write cloud-agnostic applications while leveraging the best of each cloud platform. We are already working on these items and shall have more to share in the coming months - stay tuned!" + }, + { + "id": 78, + "about": "Announcing the Private Beta for the Defang Opinionated Platform: Radically Simplifying and Cloud Application Development, Deployment, and Optimization**", + "text": "We're thrilled to announce the release of our Private Beta for the Defang Opinionated Platform (DOP). We started Defang because, as practitioners with experience in both building cloud apps and building cloud platforms, we were unhappy with the state of the art. It was, and remains, too difficult to develop, deploy, and optimize cloud applications. In architecting and building a cloud app, developers need to consider a variety of factors such as performance, scalability, cost, security, flexibility, simplicity, etc. At the same time, they face a bewildering array of choices - from app architecture to choice of cloud platforms and services, to configuration and deployment, CI-CD, security setting, etc. - in topics that they are not experts in. Clearly, we need a better way. We realize that improving on this state of affairs is a long journey. Today, we are taking an initial step with the release of the Private Beta of the DOP. The DOP enables ** AI-assisted development** , with the ability to specify a high-level prompt and get back an initial version of your cloud service code, which can then be refined further. The DOP ** simplifies CI-CD** by automatically building and deploying new artifacts to your target environments when you push new code to your source repository, taking care of all dependency management and build tasks. And the ** DOP pre-provisions properly secured and configured staging and production environments** for your application, optimized for security, scaling, and cost." + }, + { + "id": 79, + "about": "Try the Private Beta!**", + "text": "To try the Private Beta, please go to [portal.defang.dev](https://portal.defang.dev) and register. We would love to have you kick the tires and give us your feedback! You can also check out our [documentation](https://docs.defang.io/docs/intro), [samples](https://docs.defang.io/docs/intro), and our [Github repository](https://github.com/DefangLabs)." + }, + { + "id": 80, + "about": "Stay Tuned for More**", + "text": "While the Private Beta is a start, we have already heard requests for additional features from some of our early adopters and have a lot more in the pipeline! Top of the list is the ability to bring your own cloud accounts (AWS, Azure, GCP). Another frequent request is the ability to access a variety of compute and storage services native to the underlying platform while still maintaining app portability. And we also hear about the need to be able to monitor and optimize an app once deployed. We are already working on all these items and hope to have more to share in the coming months - stay tuned!" + }, + { + "id": 81, + "about": "npx defang", + "text": "We know a lot of you are using Defang for the first time. To make it easier to get started, we've added a new way to install the Defang CLI. Now you can use npx to run the CLI without installing it globally. Just run: ```bash npx defang@latest ``` This will download the latest version of the Defang CLI and run it for you. No need to worry about installing or updating the CLI manually!" + }, + { + "id": 82, + "about": "(coming soon) Bring Your Own Domain with Let's Encrypt", + "text": "Previously you could bring your own domain with Defang BYOC... but you had to host the DNS records with AWS Route 53 in the AWS account you were deploying to. Now you can point domains hosted anywhere to your Defang deployment and we'll take care of the rest. We'll help generate a Let's Encrypt certificate for your domain and automatically renew it for you." + }, + { + "id": 83, + "about": "Windows Support", + "text": "Some of you use Defang from a Windows PC and previously a few features didn't work correctly on Windows. Some stuff we've fixed: * ansi color codes in logs * handle ctrl-c when tailing logs" + }, + { + "id": 84, + "about": "Improved CLI", + "text": "We've made a variety of small tweaks and improvements to the CLI which should make things a little bit cleaner and more stable. * log messages have been made more clear * adding more progress information during compose up" + }, + { + "id": 85, + "about": "Stability and Reliability", + "text": "Defang is still in Beta and we know we've got to be rock solid by the time we release V1, so we've been working hard to improve the stability and reliability of the Defang architecture. We've been battle-testing different technologies to see how they hold up and have mad a few changes that should make things even better: * capacity improvements in build queues * improvements in log availability" + }, + { + "id": 86, + "about": "Prerequisites", + "text": "Before we dive into the details, let's make sure you have everything you need to get started: 1. ** Install Defang CLI:** Simplify your deployment process by installing the Defang CLI tool. Follow the instructions [here](https://docs.defang.io/docs/getting-started/installing) to get it up and running quickly. 2. ** Slack API Token:** Create a Slack App at https://api.slack.com/apps, granting it the necessary permissions, including the bot `chat:write` scope. ![screenshot of the slack admin UI showing the bot scopes](/img/slackbot-sample/scopes.png) 3. ** Install the app in your workspace:** You'll need to install the app in your workspace for it to work. Click the \"Install to Workspace\" button in the Slack admin UI to do this. Mine says \"Reinstall\" because I've already installed it. ![screenshot of the slack admin UI showing the install button](/img/slackbot-sample/install-app.png) 4. ** Copy the Bot User OAuth Access Token:** This token will authenticate your Slackbot with the Slack API. ![screenshot of the slack admin UI showing the auth token field](/img/slackbot-sample/token.png) 5. ** Invite the Bot to a Channel:** To enable your Slackbot, invite it to the desired channel using the `@` command. In the screenshot below, my bot's name actually starts with the word invite, but if your bot is called `mycoolbot` you would invite it with `@mycoolbot`. This ensures your Slackbot has the required permissions to interact with the channel. ![screenshot of the slack chat UI showing me inviting my bot](/img/slackbot-sample/invite.png) 6. ** Clone the Sample Code:** Clone the Defang repository and navigate to the `samples/golang/slackbot` directory. This directory contains the sample code for the Slackbot. ```bash git clone https://github.com/DefangLabs/defang cd defang/samples/golang/slackbot ```" + }, + { + "id": 87, + "about": "Deployment Steps", + "text": "Now that we have everything set up, let's dive into the deployment process. Follow these steps to deploy your Slackbot effortlessly: 1. ** Set Up Secrets:** Prioritize security by configuring environment variables as sensitive config. Use the Defang CLI's `defang config set` command to set the `SLACK_TOKEN` and `SLACK_CHANNEL_ID` configs. Replace `your_slack_token` and `your_slack_channel_id` with the respective values: ```bash defang config set --name SLACK_TOKEN --value your_slack_token defang config set --name SLACK_CHANNEL_ID --value your_slack_channel_id ``` 2. ** Deploy the Slackbot:** Use the Defang CLI's `defang compose up` command to deploy." + }, + { + "id": 88, + "about": "Usage", + "text": "With your Slackbot up and running, let's explore how to make the most of it. Simply send a POST request to the `/` endpoint with a JSON body containing the message you want to post to the Slack channel. Popular tools like cURL or Postman can help you send the request: ```bash curl 'https://raphaeltm-bot--8080.prod1.defang.dev/' \\ -H 'content-type: application/json' \\ --data-raw $'{\"message\":\"This is your bot speaking. We\\'ll be landing in 10 minutes. Please fasten your seatbelts.\"}' ```" + }, + { + "id": 89, + "about": "Takeaways", + "text": "Congratulations! You've successfully deployed a Slackbot using Defang. If you deployed this as an internal service, you could use it to send status updates, alerts, or other important messages to your team. The possibilities are endless!" + } +] diff --git a/samples/RAG-chatbot/app/parse_basic.py b/samples/RAG-chatbot/app/parse_basic.py new file mode 100644 index 00000000..435c44f3 --- /dev/null +++ b/samples/RAG-chatbot/app/parse_basic.py @@ -0,0 +1,128 @@ +import re +import json +import os + +# Function to reset knowledge_base.json +def reset_knowledge_base(): + with open('knowledge_base.json', 'w') as output_file: + json.dump([], output_file) + +def parse_markdown_file_to_json(file_path): + try: + # Load existing content if the file exists + with open('knowledge_base.json', 'r') as existing_file: + json_output = json.load(existing_file) + current_id = len(json_output) + 1 # Start ID from the next available number + except (FileNotFoundError, json.JSONDecodeError): + # If the file doesn't exist or is empty, start fresh + json_output = [] + current_id = 1 + + with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + + # Skip the first 5 lines + markdown_content = "".join(lines[5:]) + + # First pass: Determine headers for 'about' section + sections = [] + current_section = {"about": [], "text": []} + has_main_header = False + + for line in markdown_content.split('\n'): + header_match = re.match(r'^(#{1,6}|\*\*+)\s+(.*)', line) # Match `#`, `##`, ..., `######` and `**` + if header_match: + header_level = len(header_match.group(1).strip()) + header_text = header_match.group(2).strip() + + if header_level == 1 or header_match.group(1).startswith('**'): # Treat `**` as a main header + if current_section["about"] or current_section["text"]: + sections.append(current_section) + current_section = {"about": [header_text], "text": []} + has_main_header = True + else: + if has_main_header: + current_section["about"].append(header_text) + else: + if header_level == 2: + if current_section["about"] or current_section["text"]: + sections.append(current_section) + current_section = {"about": [header_text], "text": []} + else: + current_section["about"].append(header_text) + else: + current_section["text"].append(line.strip()) + + if current_section["about"] or current_section["text"]: + sections.append(current_section) + + # Second pass: Combine text while ignoring headers and discard entries with empty 'about' or 'text' + for section in sections: + about = ", ".join(section["about"]) + text = " ".join(line for line in section["text"] if line) + + if about and text: # Only insert if both 'about' and 'text' are not empty + json_output.append({ + "id": current_id, + "about": about, + "text": text + }) + current_id += 1 + + # Write the augmented JSON output to knowledge_base.json + with open('knowledge_base.json', 'w', encoding='utf-8') as output_file: + json.dump(json_output, output_file, indent=2, ensure_ascii=False) + +def parse_cli_markdown(file_path): + try: + # Load existing content if the file exists + with open('knowledge_base.json', 'r') as existing_file: + json_output = json.load(existing_file) + current_id = len(json_output) + 1 # Start ID from the next available number + except (FileNotFoundError, json.JSONDecodeError): + # If the file doesn't exist or is empty, start fresh + json_output = [] + current_id = 1 + + with open(file_path, 'r', encoding='utf-8') as file: + lines = file.readlines() + + if len(lines) < 5: + print(f"File {file_path} does not have enough lines to parse.") + return + + # Extract 'about' from the 5th line (index 4) + about = lines[4].strip() + + # Combine all remaining lines after the first 5 lines into 'text' + text_lines = lines[5:] + text = "".join(text_lines).strip() + + # Only append if both 'about' and 'text' are not empty + if about and text: + json_output.append({ + "id": current_id, + "about": about, + "text": text + }) + current_id += 1 + + # Write the augmented JSON output to knowledge_base.json + with open('knowledge_base.json', 'w', encoding='utf-8') as output_file: + json.dump(json_output, output_file, indent=2, ensure_ascii=False) + +def recursive_parse_directory(root_dir): + for dirpath, dirnames, filenames in os.walk(root_dir): + for filename in filenames: + file_path = os.path.join(dirpath, filename) + if filename.lower().endswith('.md'): + if 'cli' in dirpath.lower() or 'cli' in filename.lower(): + parse_cli_markdown(file_path) + else: + parse_markdown_file_to_json(file_path) + +# Example usage: +if __name__ == "__main__": + reset_knowledge_base() # Reset knowledge_base.json to empty at the start + recursive_parse_directory('/Users/chris/Desktop/tmp') # Parse the entire directory + print("Parsing completed successfully.") diff --git a/samples/RAG-chatbot/app/rag_system.py b/samples/RAG-chatbot/app/rag_system.py new file mode 100644 index 00000000..98400528 --- /dev/null +++ b/samples/RAG-chatbot/app/rag_system.py @@ -0,0 +1,133 @@ +import openai +import json +import os +from sentence_transformers import SentenceTransformer +import numpy as np +from sklearn.metrics.pairwise import cosine_similarity +import re + +# Ensure you have set the OPENAI_API_KEY in your environment variables +openai.api_key = os.getenv("OPENAI_API_KEY") + +class RAGSystem: + def __init__(self, knowledge_base): + self.knowledge_base = knowledge_base + self.model = SentenceTransformer('all-MiniLM-L6-v2') + self.doc_embeddings = self.embed_knowledge_base() + + def embed_knowledge_base(self): + # Combine the 'about' and 'text' fields for embedding + docs = [f'{doc["about"]}. {doc["text"]}' for doc in self.knowledge_base] + return self.model.encode(docs, convert_to_tensor=True) + + def normalize_query(self, query): + """ + Normalize the query by converting it to lowercase and stripping whitespace. + """ + return query.lower().strip() + + def retrieve(self, query, similarity_threshold=0.7, high_match_threshold=0.8, max_docs=5): + # Normalize query + normalized_query = self.normalize_query(query) + print(f"Retrieving context for query: '{normalized_query}'") + + # Query embedding + query_embedding = self.model.encode([normalized_query], convert_to_tensor=True) + + # Calculate similarities + similarities = cosine_similarity(query_embedding, self.doc_embeddings)[0] + + # Initialize relevance scores + relevance_scores = [] + + for i, doc in enumerate(self.knowledge_base): + # Calculate about and text similarities separately + about_similarity = cosine_similarity(query_embedding, self.model.encode([doc["about"]]))[0][0] + text_similarity = similarities[i] # Already calculated + + # Give more weight to text similarity + combined_score = (0.3 * about_similarity) + (0.7 * text_similarity) + + # If either about or text similarity is above the high match threshold, prioritize it + if about_similarity >= high_match_threshold or text_similarity >= high_match_threshold: + combined_score = max(about_similarity, text_similarity) + + relevance_scores.append((i, combined_score)) + + # Sort by combined score in descending order + sorted_indices = sorted(relevance_scores, key=lambda x: x[1], reverse=True) + top_indices = [i for i, score in sorted_indices[:max_docs] if score >= similarity_threshold] + + # Retrieve the most relevant documents, including both 'about' and 'text' fields + retrieved_docs = [f'{self.knowledge_base[i]["about"]}. {self.knowledge_base[i]["text"]}' for i in top_indices] + + if not retrieved_docs: + max_index = np.argmax(similarities) + retrieved_docs.append(f'{self.knowledge_base[max_index]["about"]}. {self.knowledge_base[max_index]["text"]}') + + context = "\n\n".join(retrieved_docs) + print("Retrieved Context:\n", context) + + return context + + def generate_response(self, query, context): + # Normalize query + normalized_query = self.normalize_query(query) + print(f"Generating response for query: '{normalized_query}'") + + try: + prompt = ( + "You are a dedicated assistant designed to provide positive answers about Defang. " + "When the user says 'you', 'your', or any pronoun, interpret it as referring to Defang with context of Defang also. " + "If the user's question involves comparisons with or references to other services, you may use external knowledge. " + "However, if the question is strictly about Defang, you must ignore all external knowledge and only utilize the given context. " + "When generating the answer, please put the answer first and the justification later. " + "Any mentions of BYOD means BRING YOUR OWN DOMAIN and NOT BRING YOUR OWN DEVICE." + "Your objective is to remain strictly within the confines of the given context unless comparisons to other services are explicitly mentioned. " + "Although this rarely happens, if the prompt is not related to defang reply with prompt out of scope. If the prompt contains the word `defang` proceed with answering" + "\n\nContext:\n" + context + "\n\n" + "User Question: " + query + "\n\n" + "Answer:" + ) + + response = openai.ChatCompletion.create( + model="gpt-4-turbo", + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "system", "content": prompt}, + {"role": "user", "content": normalized_query} + ], + temperature=0.05, + max_tokens=2048, + top_p=1, + frequency_penalty=0, + presence_penalty=0 + ) + + # Print the response generated by the model + generated_response = response['choices'][0]['message']['content'].strip() + + print("Generated Response:\n", generated_response) + + return generated_response + + except openai.error.OpenAIError as e: + print(f"Error generating response from OpenAI: {e}") + return "An error occurred while generating the response." + + def answer_query(self, query): + try: + # Normalize query before use + normalized_query = self.normalize_query(query) + context = self.retrieve(normalized_query) + response = self.generate_response(normalized_query, context) + return response + except Exception as e: + print(f"Error in answer_query: {e}") + return "An error occurred while generating the response." + +# Load knowledge base from a JSON file +with open('knowledge_base.json', 'r') as kb_file: + knowledge_base = json.load(kb_file) + +rag_system = RAGSystem(knowledge_base) diff --git a/samples/RAG-chatbot/app/requirements.txt b/samples/RAG-chatbot/app/requirements.txt new file mode 100644 index 00000000..b11608d4 --- /dev/null +++ b/samples/RAG-chatbot/app/requirements.txt @@ -0,0 +1,8 @@ +Flask==2.0.1 +Werkzeug==2.0.3 +scikit-learn==0.24.2 +numpy==1.21.0 +sentence-transformers==2.1.0 +torch==1.10.0 +huggingface_hub==0.8.1 +openai==0.28 \ No newline at end of file diff --git a/samples/RAG-chatbot/app/templates/index.html b/samples/RAG-chatbot/app/templates/index.html new file mode 100644 index 00000000..bee00a14 --- /dev/null +++ b/samples/RAG-chatbot/app/templates/index.html @@ -0,0 +1,173 @@ + + + + + + + RAG Chatbot + + + + +
+

RAG Chatbot

+
+ +
+
+ + +
+
+
+ + + + + + + diff --git a/samples/RAG-chatbot/compose.dev.yaml b/samples/RAG-chatbot/compose.dev.yaml new file mode 100644 index 00000000..1d2a6734 --- /dev/null +++ b/samples/RAG-chatbot/compose.dev.yaml @@ -0,0 +1,18 @@ +services: + rag-chatbot-2: + build: + context: ./app + shm_size: "16gb" + ports: + - target: 5000 + published: 5000 + protocol: tcp + mode: ingress + environment: + FLASK_APP: app.py + OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file + command: flask run --host=0.0.0.0 + deploy: + resources: + reservations: + memory: 4G diff --git a/samples/RAG-chatbot/compose.yaml b/samples/RAG-chatbot/compose.yaml new file mode 100644 index 00000000..af93e232 --- /dev/null +++ b/samples/RAG-chatbot/compose.yaml @@ -0,0 +1,24 @@ +services: + rag-chatbot: + build: + context: ./app + shm_size: "16gb" + ports: + - target: 5000 + published: 5000 + protocol: tcp + mode: ingress + environment: + FLASK_APP: app.py + OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file + command: gunicorn --bind 0.0.0.0:5000 app:app + deploy: + resources: + reservations: + memory: 4G + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5000/"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s