Skip to content

Commit 196c5f2

Browse files
Merge pull request #38 from DefangLabs/jordan/bedrock-access-gateway
Migrate to Bedrock
2 parents 062efe0 + ff85e45 commit 196c5f2

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"SECRET_KEY": "supersecret",
1717
"SESSION_COOKIE_SECURE": "0",
1818
"OPENAI_BASE_URL": "http://localhost:8080/api/v1",
19-
"OPENAI_API_KEY": "secret"
19+
"OPENAI_API_KEY": "secret",
20+
"MODEL": "anthropic.claude-3-sonnet-20240229-v1:0"
2021
},
2122
"args": [
2223
"run",

app/rag_system.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88
from sklearn.metrics.pairwise import cosine_similarity
99

10+
openai.api_base = os.getenv("OPENAI_BASE_URL")
1011
openai.api_key = os.getenv("OPENAI_API_KEY")
1112

1213
class RAGSystem:
@@ -134,7 +135,7 @@ def answer_query_stream(self, query):
134135
messages.append(system_message)
135136

136137
stream = openai.ChatCompletion.create(
137-
model="gpt-4-turbo",
138+
model=os.getenv("MODEL"),
138139
messages=messages,
139140
temperature=0.5,
140141
max_tokens=2048,

compose.dev.yaml

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
services:
2-
rag-chatbot:
3-
build:
4-
context: ./app
5-
shm_size: "16gb"
6-
ports:
7-
- target: 5050
8-
published: 5050 # MacOS AirPlay uses port 5000
9-
protocol: tcp
10-
mode: ingress
2+
app:
3+
extends:
4+
file: compose.yaml
5+
service: app
6+
env_file:
7+
- .env
118
environment:
129
ASK_TOKEN: asktoken
1310
FLASK_APP: app.py
1411
SECRET_KEY: supersecret
1512
SEGMENT_WRITE_KEY: ${SEGMENT_WRITE_KEY} # Set your Segment write key here or in the .env file
1613
SESSION_COOKIE_SECURE: 0
17-
OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file
14+
OPENAI_BASE_URL: "http://llm:5051/api/v1"
1815
SENTENCE_TRANSFORMERS_HOME: /app/sentence-transformers
1916
volumes:
2017
- type: bind
2118
source: ./app
2219
target: /app
2320
command: flask run --host=0.0.0.0 --port=5050
24-
deploy:
25-
resources:
26-
reservations:
27-
memory: 4G
21+
22+
llm:
23+
extends:
24+
file: compose.yaml
25+
service: llm
26+
env_file:
27+
- .env
28+
ports:
29+
- target: 5051
30+
published: 5051
31+
protocol: tcp
32+
mode: ingress
33+
environment:
34+
- AWS_REGION=us-west-2
35+
- AWS_PROFILE=defang-lab
36+
- PORT=5051
37+
volumes:
38+
- type: bind
39+
source: ~/.aws
40+
target: /root/.aws

compose.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
services:
2-
rag-chatbot:
2+
app:
33
restart: always
44
domainname: ask.defang.io
55
x-defang-dns-role: arn:aws:iam::258338292852:role/dnsadmin-39a19c3
@@ -19,6 +19,8 @@ services:
1919
SEGMENT_WRITE_KEY:
2020
SESSION_COOKIE_SECURE: 1
2121
OPENAI_API_KEY: ${OPENAI_API_KEY} # Set your OpenAI API key here or in the .env file
22+
OPENAI_BASE_URL: "http://llm/api/v1"
23+
MODEL: "anthropic.claude-3-sonnet-20240229-v1:0"
2224
command: uwsgi --http 0.0.0.0:5050 --wsgi-file app.py --callable app --processes 4 --threads 2
2325
deploy:
2426
resources:
@@ -30,3 +32,16 @@ services:
3032
timeout: 10s
3133
retries: 5
3234
#start_period: 40s
35+
36+
llm:
37+
image: defangio/openai-access-gateway
38+
x-defang-llm: true
39+
ports:
40+
- target: 80
41+
published: 80
42+
protocol: tcp
43+
mode: host
44+
environment:
45+
- OPENAI_API_KEY=${OPENAI_API_KEY}
46+
healthcheck:
47+
test: ["CMD", "curl", "-f", "http://localhost/health"]

0 commit comments

Comments
 (0)