Skip to content

Commit 26ad1a3

Browse files
rough draft documenting x-defang-llm
1 parent 730d110 commit 26ad1a3

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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-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`.

0 commit comments

Comments
 (0)