Skip to content

Commit 2cc1742

Browse files
rough draft documenting x-defang-llm
1 parent 730d110 commit 2cc1742

File tree

8 files changed

+209
-1
lines changed

8 files changed

+209
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "Managed LLMs",
3+
"position": 425,
4+
"collapsible": true
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Leveraging Managed Language Models with Defang
3+
description: Defang makes it easy to leverage cloud-native managed language models.
4+
sidebar_position: 3000
5+
---
6+
7+
# Managed Language Models
8+
9+
Each cloud provider offers their own managed Large Language Model services. AWS offers Bedrock, GCP offers Vertex, and Digital Ocean offers their GenAI platform. Defang makes it easy to leverage these services in your projects.
10+
11+
## Usage
12+
13+
In order to leverage cloud-native managed language models from your Defang services, all you need to do is add the `x-defang-llm` extension to the service config and Defang will configure the approprate roles and permissions for you.
14+
15+
## Example
16+
17+
Assume you have a web service like the following, which uses the cloud native SDK, for example:
18+
19+
```diff
20+
services:
21+
app:
22+
build:
23+
context: .
24+
+ x-defang-llm: true
25+
```
26+
27+
## Deploying OpenAI-compatible apps
28+
29+
If you already have an OpenAI-compatible application, Defang makes it easy to deploy on your favourite cloud's managed LLM service. See our [OpenAI Access Gateway](/docs/concepts/openai-access-gateway.md)
30+
31+
## Current Support
32+
33+
| Provider | Managed Language Models |
34+
| --- | --- |
35+
| [Playground](/docs/providers/playground#managed-large-language-models) ||
36+
| [AWS Bedrock](/docs/providers/aws#managed-large-language-models) ||
37+
| [DigitalOcean GenAI](/docs/providers/digitalocean#future-improvements) ||
38+
| [GCP Vertex](/docs/providers/gcp#managed-large-language-models) ||
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Deploying OpenAI-compatible apps with Defang
3+
description: Defang makes it easy to leverage cloud-native managed language models for your OpenAI-compatible application.
4+
sidebar_position: 3000
5+
---
6+
7+
# Deploying OpenAI-compatible applications to cloud-native managed language models with Defang
8+
9+
Defang makes it easy to deploy on your favourite cloud's managed LLM service with our [OpenAI Access Gateway](https://github.com/DefangLabs/openai-access-gateway). This service sits between your application and the cloud service and acts as a compatibility layer. It handles incoming OpenAI requests, translates those requests to the appropriate cloud-native API, handles the native response, and re-constructs an OpenAI-compatible response.
10+
11+
See [our tutorial](/docs/tutorials/deploying-openai-apps-aws-bedrock.mdx/) which describes how to configure the OpenAI Access Gateway for your application
12+
13+
## Current Support
14+
15+
| Provider | Managed Language Models |
16+
| --- | --- |
17+
| [Playground](/docs/providers/playground#managed-services) ||
18+
| [AWS Bedrock](/docs/providers/aws#managed-storage) ||
19+
| [DigitalOcean GenAI](/docs/providers/digitalocean#future-improvements) ||
20+
| [GCP Vertex](/docs/providers/gcp#future-improvements) ||

docs/providers/aws/aws.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ When using [Managed Postgres](/docs/concepts/managed-storage/managed-postgres.md
7272

7373
When using [Managed Redis](/docs/concepts/managed-storage/managed-redis.md), the Defang CLI provisions an ElastiCache Redis cluster in your account.
7474

75+
### Managed large language models
76+
77+
Defang offers integration with managed, cloud-native large language model services with the `x-defang-llm` service extension. Add this extension to any services which use the Bedrock SDKs.
78+
79+
When using [Managed LLMs](/docs/concepts/managed-llms/managed-language-models.md), the Defang CLI provisions an ElastiCache Redis cluster in your account.
80+
7581
### Managed Resources
7682

7783
Defang will create and manage the following resources in your AWS account from its bootstrap CloudFormation template:

docs/providers/digitalocean/digitalocean.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar_position: 010
77
# DigitalOcean
88

99
:::info
10-
The Defang DigitalOcean Provider is available for Public Preview as of October 2024.
10+
The Defang DigitalOcean Provider is available for Public Preview as of October 2024.
1111
:::
1212

1313
:::success DigitalOcean Credits
@@ -76,5 +76,6 @@ The following features are still in development for DigitalOcean:
7676
- [Custom Domains](/docs/concepts//domains.mdx)
7777
- [Managed Redis](/docs/concepts//managed-storage/managed-redis.md)
7878
- [Managed Postgres](/docs/concepts/managed-storage/managed-postgres.md)
79+
- [Managed Language Models](/docs/concepts/managed-llms/managed-language-models.md)
7980

8081
Stay tuned for future updates!

docs/providers/gcp.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ The Provider builds and deploys your services using [Google Cloud Run](https://c
5959

6060
The GCP provider does not currently support storing sensitive config values.
6161

62+
### Managed large language models
63+
64+
Defang offers integration with managed, cloud-native large language model services with the `x-defang-llm` service extension. Add this extension to any services which use the Bedrock SDKs.
65+
66+
When using [Managed LLMs](/docs/concepts/managed-llms/managed-language-models.md), the Defang CLI provisions an ElastiCache Redis cluster in your account.
67+
6268
### Future Improvements
6369

6470
The following features are in active development for GCP:

docs/providers/playground.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Overall, the Defang Playground is very similar to deploying to your own cloud ac
1919
### Managed services
2020

2121
In essence, the Playground does not support any [managed storage](../concepts/managed-storage) services, ie. `x-defang-postgres` and `x-defang-redis` are ignored when deploying to the Playground. You can however run both Postgres and Redis as regular container services for testing purposes.
22+
23+
### Managed large language models
24+
25+
Defang offers integration with managed, cloud-native large language model services with the `x-defang-llm` service extension when deploying to your own cloud account with BYOC. This extension is not supported in the Defang Playground.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Deploying your OpenAI application to AWS and using Bedrock
3+
sidebar_position: 50
4+
---
5+
6+
# Deploying your OpenAI application to AWS and using Bedrock
7+
8+
Let's assume you have an app which is using one of the OpenAI client libraries and you want to deploy your app to AWS so you can leverage Bedrock. This tutorial will show you how Defang makes it easy.
9+
10+
Assume you have a compose file like this:
11+
12+
```yaml
13+
services:
14+
app:
15+
build:
16+
context: .
17+
ports:
18+
- target: 3000
19+
published: 3000
20+
protocol: tcp
21+
mode: ingress
22+
environment:
23+
OPENAI_API_KEY:
24+
healthcheck:
25+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
26+
```
27+
28+
## Add an llm service to your compose file
29+
30+
The first step is to add a new service to your compose file. The `defangio/openai-access-gateway`. This service provides an OpenAI compatible interface to AWS Bedrock. It's easy to configure, first you need to add it to your compose file:
31+
32+
```diff
33+
+ llm:
34+
+ image: defangio/openai-access-gateway
35+
+ x-defang-llm: true
36+
+ ports:
37+
+ - target: 80
38+
+ published: 80
39+
+ protocol: tcp
40+
+ mode: host
41+
+ environment:
42+
+ - OPENAI_API_KEY
43+
+ healthcheck:
44+
+ test: ["CMD", "curl", "-f", "http://localhost/health"]
45+
```
46+
47+
A few things to note here. First the image is a fork of [aws-samples/bedrock-access-gateway](https://github.com/aws-samples/bedrock-access-gateway), which a few modifications to make it easier to use. The source code is available [here](https://github.com/DefangLabs/openai-access-gateway). Second: the `x-defang-llm` property. Defang uses extensions like this to signal special handling of certain kinds of services. In this case, it signals to Defang that we need to configure the appropriate IAM Roles and Policies to support your application.
48+
49+
## Redirecting application traffic
50+
51+
Then you need to configure your application to redirect traffic to the openai-access-gateway, like this:
52+
53+
```diff
54+
services:
55+
app:
56+
ports:
57+
- target: 3000
58+
published: 3000
59+
protocol: tcp
60+
mode: ingress
61+
environment:
62+
OPENAI_API_KEY:
63+
+ OPENAI_BASE_URL: "http://llm/api/v1"
64+
+ MODEL: "anthropic.claude-3-sonnet-20240229-v1:0"
65+
healthcheck:
66+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
67+
```
68+
69+
You will also need to configure your application to use one of the bedrock models. We recommend configuring an environment variable called `MODEL` like this:
70+
71+
## Selecting a model
72+
73+
```diff
74+
services:
75+
app:
76+
ports:
77+
- target: 3000
78+
published: 3000
79+
protocol: tcp
80+
mode: ingress
81+
environment:
82+
OPENAI_API_KEY:
83+
OPENAI_BASE_URL: "http://llm/api/v1"
84+
+ MODEL: "anthropic.claude-3-sonnet-20240229-v1:0"
85+
healthcheck:
86+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
87+
```
88+
89+
## Enabling bedrock model access
90+
91+
AWS currently requires access to be manually configured on a per-model basis in each account. See this guide for [how to enable model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access-modify.html).
92+
93+
## Your OpenAI key
94+
95+
It's worth noting that you no longer need ot use your original OpenAI API key. We do recommend using _something_ in its place, but feel free to generate a new secret and set it with `defang config set OPENAI_API_KEY`.
96+
97+
## Complete Example Compose File
98+
99+
```yaml
100+
services:
101+
app:
102+
build:
103+
context: .
104+
ports:
105+
- target: 3000
106+
published: 3000
107+
protocol: tcp
108+
mode: ingress
109+
environment:
110+
OPENAI_API_KEY:
111+
OPENAI_BASE_URL: "http://llm/api/v1"
112+
MODEL: "anthropic.claude-3-sonnet-20240229-v1:0"
113+
healthcheck:
114+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
115+
llm:
116+
image: defangio/openai-access-gateway
117+
x-defang-llm: true
118+
ports:
119+
- target: 80
120+
published: 80
121+
protocol: tcp
122+
mode: host
123+
environment:
124+
- OPENAI_API_KEY
125+
healthcheck:
126+
test: ["CMD", "curl", "-f", "http://localhost/health"]
127+
128+
```

0 commit comments

Comments
 (0)