Skip to content

Commit 500a1f6

Browse files
authored
Various small fixes to the serve application (#27)
- Make sure the right API is used - Make sure the DB connection string is set correctly
1 parent 81f629a commit 500a1f6

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

app/query.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
77
from pgvector.psycopg import register_vector
88

9-
from app.config import DB_CONNECTION_STRING
10-
9+
import app.config
1110

1211
def generate_response(
1312
llm,
@@ -57,7 +56,7 @@ def __init__(
5756
self.assistant_content = assistant_content
5857

5958
# VectorDB connection
60-
self.conn = psycopg.connect(DB_CONNECTION_STRING)
59+
self.conn = psycopg.connect(app.config.DB_CONNECTION_STRING)
6160
register_vector(self.conn)
6261

6362
def get_response(self, query):

app/serve.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# You can run the whole script locally with
2-
# serve run serve:deployment
2+
# serve run app.serve:deployment
33

44
import json
55
import os
66

7+
import openai
78
import ray
89
import requests
910
from fastapi import FastAPI
@@ -17,18 +18,10 @@
1718

1819

1920
def get_secret(secret_name):
20-
aws_secret_id = os.environ.get("RAY_ASSISTANT_AWS_SECRET_ID")
21-
if aws_secret_id:
22-
import boto3
23-
client = boto3.client(
24-
"secretsmanager", region_name=os.environ["RAY_ASSISTANT_AWS_REGION"]
25-
)
26-
response = client.get_secret_value(SecretId=aws_secret_id)
27-
return json.loads(response["SecretString"])[secret_name]
28-
else:
29-
raise NotImplemented(
30-
"Currently only AWS is supported "
31-
"and you need to set RAY_ASSISTANT_AWS_SECRET_ID")
21+
import boto3
22+
client = boto3.client("secretsmanager", region_name="us-west-2")
23+
response = client.get_secret_value(SecretId="ray-assistant")
24+
return json.loads(response["SecretString"])[secret_name]
3225

3326

3427
application = FastAPI()
@@ -69,6 +62,8 @@ class Answer(BaseModel):
6962
class RayAssistantDeployment:
7063
def __init__(self):
7164
app.config.DB_CONNECTION_STRING = get_secret("DB_CONNECTION_STRING")
65+
openai.api_key = get_secret("OPENAI_API_KEY")
66+
openai.api_base = "https://api.endpoints.anyscale.com/v1"
7267
self.agent = query.QueryAgent(
7368
llm="meta-llama/Llama-2-70b-chat-hf",
7469
max_context_length=4096,

app/service.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ cluster_env: ray-assistant:2
33
ray_serve_config:
44
import_path: app.serve:deployment
55
runtime_env:
6-
working_dir: "https://github.com/ray-project/llm-applications/archive/refs/tags/v0.0.5.zip"
7-
env_vars: {
8-
RAY_ASSISTANT_AWS_SECRET_ID: "ray-assistant",
9-
RAY_ASSISTANT_AWS_REGION: "us-west-2"
10-
}
6+
working_dir: "https://github.com/ray-project/llm-applications/archive/refs/tags/v0.0.6.zip"

0 commit comments

Comments
 (0)