Skip to content

Commit

Permalink
Make sure to strip the scheme from the index URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Nov 11, 2024
1 parent eee541f commit 053978b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions chat/src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from handlers.opensearch_neural_search import OpenSearchNeuralSearch
from opensearchpy import OpenSearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
from urllib.parse import urlparse
import os
import boto3

Expand All @@ -16,10 +17,18 @@ def openai_chat_client(**kwargs):
**kwargs,
)

def opensearch_endpoint():
endpoint = os.getenv("OPENSEARCH_ENDPOINT")
parsed = urlparse(endpoint)
if parsed.netloc != '':
return parsed.netloc
else:
return endpoint

def opensearch_client(region_name=os.getenv("AWS_REGION")):
session = boto3.Session(region_name=region_name)
awsauth = AWS4Auth(region=region_name, service="es", refreshable_credentials=session.get_credentials())
endpoint = os.getenv("OPENSEARCH_ENDPOINT")
endpoint = opensearch_endpoint()

return OpenSearch(
hosts=[{'host': endpoint, 'port': 443}],
Expand All @@ -35,7 +44,7 @@ def opensearch_vector_store(region_name=os.getenv("AWS_REGION")):
docsearch = OpenSearchNeuralSearch(
index=prefix("dc-v2-work"),
model_id=os.getenv("OPENSEARCH_MODEL_ID"),
endpoint=os.getenv("OPENSEARCH_ENDPOINT"),
endpoint=opensearch_endpoint(),
connection_class=RequestsHttpConnection,
http_auth=awsauth,
text_field= "id"
Expand Down
7 changes: 6 additions & 1 deletion node/src/handlers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ const _initializeEnvironment = async function () {
secrets[Name.split("/").reverse()[0]] = JSON.parse(SecretString);
}

putenv("OPENSEARCH_ENDPOINT", secrets.index?.endpoint);
let { endpoint } = secrets.index;
if (URL.canParse(endpoint)) {
endpoint = new URL(endpoint).hostname;
}

putenv("OPENSEARCH_ENDPOINT", endpoint);
putenv("OPENSEARCH_MODEL_ID", secrets.index?.embedding_model);
putenv("NUSSO_API_KEY", secrets.nusso?.api_key);
putenv("NUSSO_BASE_URL", secrets.nusso?.base_url);
Expand Down

0 comments on commit 053978b

Please sign in to comment.