Skip to content

Commit 1c96337

Browse files
Merge pull request #192 from DefangLabs/jordan/x-defang-llm-docs
x-defang-llm documentation
2 parents 40d3250 + 2f9cba7 commit 1c96337

File tree

9 files changed

+198
-1
lines changed

9 files changed

+198
-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/managed-llms/openai-access-gateway)
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/) 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 LLMs
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 LLMs
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 LLMs
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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
title: Deploying your OpenAI application to AWS using Bedrock
3+
sidebar_position: 50
4+
---
5+
6+
# Deploying your OpenAI application to AWS 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+
- 3000:3000
19+
environment:
20+
OPENAI_API_KEY:
21+
healthcheck:
22+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
23+
```
24+
25+
## Add an LLM service to your compose file
26+
27+
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:
28+
29+
```diff
30+
+ llm:
31+
+ image: defangio/openai-access-gateway
32+
+ x-defang-llm: true
33+
+ ports:
34+
+ - target: 80
35+
+ published: 80
36+
+ mode: host
37+
+ environment:
38+
+ - OPENAI_API_KEY
39+
```
40+
41+
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), with 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.
42+
43+
:::warning
44+
**Your OpenAI key**
45+
46+
You no longer need to 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 --random`.
47+
48+
This is used to authenticate your application service with the openai-access-gateway.
49+
:::
50+
51+
52+
## Redirecting application traffic
53+
54+
Then you need to configure your application to redirect traffic to the openai-access-gateway, like this:
55+
56+
```diff
57+
services:
58+
app:
59+
ports:
60+
- 3000:3000
61+
environment:
62+
OPENAI_API_KEY:
63+
+ OPENAI_BASE_URL: "http://llm/api/v1"
64+
healthcheck:
65+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
66+
```
67+
68+
## Selecting a model
69+
70+
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:
71+
72+
```diff
73+
services:
74+
app:
75+
ports:
76+
- 3000:3000
77+
environment:
78+
OPENAI_API_KEY:
79+
OPENAI_BASE_URL: "http://llm/api/v1"
80+
+ MODEL: "anthropic.claude-3-sonnet-20240229-v1:0"
81+
healthcheck:
82+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
83+
```
84+
85+
:::warning
86+
**Enabling bedrock model access**
87+
88+
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).
89+
:::
90+
91+
## Complete Example Compose File
92+
93+
```yaml
94+
services:
95+
app:
96+
build:
97+
context: .
98+
ports:
99+
- 3000:3000
100+
environment:
101+
OPENAI_API_KEY:
102+
OPENAI_BASE_URL: "http://llm/api/v1"
103+
MODEL: "us:anthropic.claude-3-sonnet-20240229-v1:0"
104+
healthcheck:
105+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
106+
llm:
107+
image: defangio/openai-access-gateway
108+
x-defang-llm: true
109+
ports:
110+
- target: 80
111+
published: 80
112+
mode: host
113+
environment:
114+
- OPENAI_API_KEY
115+
116+
```

docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ const config = {
168168
// Existing footer configuration...
169169
},
170170
prism: {
171+
additionalLanguages: ['diff'],
171172
theme: lightCodeTheme,
172173
darkTheme: darkCodeTheme,
173174
},

0 commit comments

Comments
 (0)