-
Notifications
You must be signed in to change notification settings - Fork 6
update docs to include model mapping #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,164 @@ | ||||||
--- | ||||||
title: Deploying your OpenAI Application to AWS Bedrock | ||||||
sidebar_position: 50 | ||||||
--- | ||||||
|
||||||
# Deploying Your OpenAI Application to AWS Bedrock | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Let's assume you have an app that uses an OpenAI client library and you want to deploy it to the cloud on **AWS Bedrock**. | ||||||
|
||||||
This tutorial shows you how **Defang** makes it easy. | ||||||
|
||||||
Suppose you start with a compose file like this: | ||||||
|
||||||
```yaml | ||||||
services: | ||||||
app: | ||||||
build: | ||||||
context: . | ||||||
ports: | ||||||
- 3000:3000 | ||||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
``` | ||||||
--- | ||||||
## Add an LLM Service to Your Compose File | ||||||
You need to add a new service that acts as a proxy between your app and the backend LLM provider (Bedrock). | ||||||
Add **Defang's [openai-access-gateway](https://github.com/DefangLabs/openai-access-gateway)** service: | ||||||
```diff | ||||||
+ llm: | ||||||
+ image: defangio/openai-access-gateway | ||||||
+ x-defang-llm: true | ||||||
+ ports: | ||||||
+ - target: 80 | ||||||
+ published: 80 | ||||||
+ mode: host | ||||||
+ environment: | ||||||
+ - OPENAI_API_KEY | ||||||
+ - REGION | ||||||
``` | ||||||
|
||||||
### Notes: | ||||||
|
||||||
- The container image is based on [aws-samples/bedrock-access-gateway](https://github.com/aws-samples/bedrock-access-gateway), with enhancements. | ||||||
- `x-defang-llm: true` signals to **Defang** that this service should be configured to use target platform AI services. | ||||||
- New environment variables: | ||||||
- `REGION` is the zone where the services runs (for AWS this is the equvilent of AWS_REGION) | ||||||
|
||||||
:::tip | ||||||
**OpenAI Key** | ||||||
|
||||||
You no longer need your original OpenAI API Key. | ||||||
We recommend generating a random secret for authentication with the gateway: | ||||||
|
||||||
```bash | ||||||
defang config set OPENAI_API_KEY --random | ||||||
``` | ||||||
::: | ||||||
|
||||||
--- | ||||||
|
||||||
## Redirect Application Traffic | ||||||
|
||||||
Modify your `app` service to send API calls to the `openai-access-gateway`: | ||||||
|
||||||
```diff | ||||||
services: | ||||||
app: | ||||||
ports: | ||||||
- 3000:3000 | ||||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
+ OPENAI_BASE_URL: "http://llm/api/v1" | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
``` | ||||||
|
||||||
Now, all OpenAI traffic will be routed through your gateway service and onto AWS Bedrock. | ||||||
|
||||||
--- | ||||||
|
||||||
## Selecting a Model | ||||||
|
||||||
You should configure your application to specify the model you want to use. | ||||||
|
||||||
```diff | ||||||
services: | ||||||
app: | ||||||
ports: | ||||||
- 3000:3000 | ||||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
OPENAI_BASE_URL: "http://llm/api/v1" | ||||||
+ MODEL: "anthropic.claude-3-sonnet-20240229-v1:0" | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
``` | ||||||
|
||||||
Choose the correct `MODEL` depending on which cloud provider you are using. | ||||||
|
||||||
:::info | ||||||
**Choosing the Right Model** | ||||||
|
||||||
- For **AWS Bedrock**, use a Bedrock model ID (e.g., `anthropic.claude-3-sonnet-20240229-v1:0`) [See available Bedrock models](https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html). | ||||||
::: | ||||||
|
||||||
Alternatively, Defang supports model mapping through the openai-access-gateway. This takes a model with a Docker naming convention (e.g. ai/lama3.3) and maps it to | ||||||
the closest equilavent on the target platform. If no such match can be found a fallback can be defined to use a known existing model (e.g. ai/mistral). These environment | ||||||
variables are USE_MODEL_MAPPING (default to true) and FALLBACK_MODEL (no default), respectively. | ||||||
|
||||||
|
||||||
:::info | ||||||
# Complete Example Compose File | ||||||
|
||||||
```yaml | ||||||
services: | ||||||
app: | ||||||
build: | ||||||
context: . | ||||||
ports: | ||||||
- 3000:3000 | ||||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
OPENAI_BASE_URL: "http://llm/api/v1" | ||||||
MODEL: "anthropic.claude-3-sonnet-20240229-v1:0" | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
|
||||||
llm: | ||||||
image: defangio/openai-access-gateway | ||||||
x-defang-llm: true | ||||||
ports: | ||||||
- target: 80 | ||||||
published: 80 | ||||||
mode: host | ||||||
environment: | ||||||
- OPENAI_API_KEY | ||||||
- REGION | ||||||
``` | ||||||
--- | ||||||
# Environment Variable Matrix | ||||||
| Variable | AWS Bedrock | | ||||||
|--------------------|-------------| | ||||||
| `REGION` | Required| | ||||||
| `MODEL` | Bedrock model ID / Docker model name | | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
--- | ||||||
|
||||||
You now have a single app that can: | ||||||
|
||||||
- Talk to **GCP Vertex AI** | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- Use the same OpenAI-compatible client code | ||||||
- Easily switch cloud providers by changing a few environment variables | ||||||
::: | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,11 +1,11 @@ | ||||||
--- | ||||||
title: Deploying your OpenAI Application to AWS Bedrock or GCP Vertex AI | ||||||
title: Deploying your OpenAI Application to GCP Vertex AI | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
sidebar_position: 50 | ||||||
--- | ||||||
|
||||||
# Deploying your OpenAI Application to AWS Bedrock or GCP Vertex AI | ||||||
# Deploying Your OpenAI Application to GCP Vertex AI | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Let's assume you have an app that uses an OpenAI client library and you want to deploy it to the cloud, either on **AWS Bedrock** or **GCP Vertex AI**. | ||||||
Let's assume you have an app that uses an OpenAI client library and you want to deploy it to the cloud on **GCP Vertex AI**. | ||||||
|
||||||
This tutorial shows you how **Defang** makes it easy. | ||||||
|
||||||
|
@@ -28,7 +28,7 @@ services: | |||||
|
||||||
## Add an LLM Service to Your Compose File | ||||||
|
||||||
You need to add a new service that acts as a proxy between your app and the backend LLM provider (Bedrock or Vertex). | ||||||
You need to add a new service that acts as a proxy between your app and the backend LLM provider (Vertex). | ||||||
|
||||||
Add **Defang's [openai-access-gateway](https://github.com/DefangLabs/openai-access-gateway)** service: | ||||||
|
||||||
|
@@ -42,16 +42,17 @@ Add **Defang's [openai-access-gateway](https://github.com/DefangLabs/openai-acce | |||||
+ mode: host | ||||||
+ environment: | ||||||
+ - OPENAI_API_KEY | ||||||
+ - GCP_PROJECT_ID # if using GCP Vertex AI | ||||||
+ - GCP_REGION # if using GCP Vertex AI, AWS_REGION not necessary for Bedrock | ||||||
+ - GCP_PROJECT_ID | ||||||
+ - REGION | ||||||
``` | ||||||
|
||||||
### Notes: | ||||||
|
||||||
- The container image is based on [aws-samples/bedrock-access-gateway](https://github.com/aws-samples/bedrock-access-gateway), with enhancements. | ||||||
- `x-defang-llm: true` signals to **Defang** that this service should be configured to use target platform AI services. | ||||||
- New environment variables: | ||||||
- `GCP_PROJECT_ID` and `GCP_REGION` are needed if using **Vertex AI**. (e.g.` GCP_PROJECT_ID` = my-project-456789 and `GCP_REGION` = us-central1) | ||||||
- `REGION` is the zone where the services runs (e.g. us-central1) | ||||||
- `GCP_PROJECT_ID` is your project to deploy to (e.g. my-project-456789) | ||||||
|
||||||
:::tip | ||||||
**OpenAI Key** | ||||||
|
@@ -82,7 +83,7 @@ Modify your `app` service to send API calls to the `openai-access-gateway`: | |||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
``` | ||||||
|
||||||
Now, all OpenAI traffic will be routed through your gateway service and onto AWS Bedrock or GCP Vertex. | ||||||
Now, all OpenAI traffic will be routed through your gateway service and onto GCP Vertex AI. | ||||||
|
||||||
--- | ||||||
|
||||||
|
@@ -98,8 +99,7 @@ You should configure your application to specify the model you want to use. | |||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
OPENAI_BASE_URL: "http://llm/api/v1" | ||||||
+ MODEL: "anthropic.claude-3-sonnet-20240229-v1:0" # for Bedrock | ||||||
+ # MODEL: "google/gemini-2.5-pro-preview-03-25" # for Vertex AI | ||||||
+ MODEL: "google/gemini-2.5-pro-preview-03-25" # for Vertex AI | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
``` | ||||||
|
@@ -109,9 +109,15 @@ Choose the correct `MODEL` depending on which cloud provider you are using. | |||||
:::info | ||||||
**Choosing the Right Model** | ||||||
|
||||||
- For **AWS Bedrock**, use a Bedrock model ID (e.g., `anthropic.claude-3-sonnet-20240229-v1:0`) [See available Bedrock models](https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html). | ||||||
- For **GCP Vertex AI**, use a full model path (e.g., `google/gemini-2.5-pro-preview-03-25`) [See available Vertex models](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library#client-setup) | ||||||
::: | ||||||
|
||||||
Alternatively, Defang supports model mapping through the openai-access-gateway. This takes a model with a Docker naming convention (e.g. ai/lama3.3) and maps it to | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
the closest matching one on the target platform. If no such match can be found it can fallback onto a known existing model (e.g. ai/mistral). These environment | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
variables are USE_MODEL_MAPPING (default to true) and FALLBACK_MODEL (no default), respectively. | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
:::info | ||||||
# Complete Example Compose File | ||||||
|
||||||
```yaml | ||||||
|
@@ -124,7 +130,7 @@ services: | |||||
environment: | ||||||
OPENAI_API_KEY: | ||||||
OPENAI_BASE_URL: "http://llm/api/v1" | ||||||
MODEL: "anthropic.claude-3-sonnet-20240229-v1:0" # or your Vertex AI model path | ||||||
MODEL: "google/gemini-2.5-pro-preview-03-25" | ||||||
healthcheck: | ||||||
test: ["CMD", "curl", "-f", "http://localhost:3000/"] | ||||||
|
||||||
|
@@ -137,25 +143,26 @@ services: | |||||
mode: host | ||||||
environment: | ||||||
- OPENAI_API_KEY | ||||||
- GCP_PROJECT_ID # required if using Vertex AI | ||||||
- GCP_REGION # required if using Vertex AI | ||||||
- GCP_PROJECT_ID # required if using GCP Vertex AI | ||||||
- REGION | ||||||
``` | ||||||
|
||||||
--- | ||||||
|
||||||
# Environment Variable Matrix | ||||||
|
||||||
| Variable | AWS Bedrock | GCP Vertex AI | | ||||||
|--------------------|-------------|---------------| | ||||||
| `GCP_PROJECT_ID` | _(not used)_| Required | | ||||||
| `GCP_REGION` | _(not used)_| Required | | ||||||
| `MODEL` | Bedrock model ID | Vertex model path | | ||||||
| Variable | GCP Vertex AI | | ||||||
|--------------------|---------------| | ||||||
| `GCP_PROJECT_ID` | Required | | ||||||
| `REGION` | Required | | ||||||
| `MODEL` | Vertex model / Docker model name | | ||||||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
--- | ||||||
|
||||||
You now have a single app that can: | ||||||
|
||||||
- Talk to **AWS Bedrock** or **GCP Vertex AI** | ||||||
- Talk to **GCP Vertex AI** | ||||||
- Use the same OpenAI-compatible client code | ||||||
- Easily switch cloud providers by changing a few environment variables | ||||||
::: | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Deploying your OpenAI Application | ||
sidebar_position: 50 | ||
--- | ||
|
||
# Deploying Your OpenAI application | ||
|
||
Defang currently supports LLM using AWS Bedrock and GCP Vertex AI. Follow the link below for your specific platform. | ||
|
||
- [AWS Bedrock](/docs/tutorials/deploying-openai-apps-aws-bedrock/) | ||
- [GCP Vertex AI](/docs/tutorials/deploying-openai-apps-gcp-vertex/). | ||
|
||
|
||
|
||
nullfunc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.