-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update permissions on chat websocket function Add AWS4Auth to opensearch client Tweak EventConfig to make chat work with OpenSearch
- Loading branch information
Showing
16 changed files
with
199 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
boto3~=1.34.13 | ||
langchain~=0.0.208 | ||
langchain~=0.1.8 | ||
langchain-community | ||
openai~=0.27.8 | ||
opensearch-py | ||
pyjwt~=2.6.0 | ||
python-dotenv~=1.0.0 | ||
requests | ||
requests-aws4auth | ||
tiktoken~=0.4.0 | ||
weaviate-client~=3.19.2 | ||
wheel~=0.40.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
from typing import Dict, List | ||
from langchain_community.embeddings.sagemaker_endpoint import EmbeddingsContentHandler | ||
|
||
class ContentHandler(EmbeddingsContentHandler): | ||
content_type = "application/json" | ||
accepts = "application/json" | ||
|
||
def transform_input(self, inputs: list[str], model_kwargs: Dict) -> bytes: | ||
""" | ||
Transforms the input into bytes that can be consumed by SageMaker endpoint. | ||
Args: | ||
inputs: List of input strings. | ||
model_kwargs: Additional keyword arguments to be passed to the endpoint. | ||
Returns: | ||
The transformed bytes input. | ||
""" | ||
# Example: inference.py expects a JSON string with a "inputs" key: | ||
input_str = json.dumps({"inputs": inputs, **model_kwargs}) | ||
return input_str.encode("utf-8") | ||
|
||
def transform_output(self, output: bytes) -> List[List[float]]: | ||
""" | ||
Transforms the bytes output from the endpoint into a list of embeddings. | ||
Args: | ||
output: The bytes output from SageMaker endpoint. | ||
Returns: | ||
The transformed output - list of embeddings | ||
Note: | ||
The length of the outer list is the number of input strings. | ||
The length of the inner lists is the embedding dimension. | ||
""" | ||
# Example: inference.py returns a JSON string with the list of | ||
# embeddings in a "vectors" key: | ||
response_json = json.loads(output.read().decode("utf-8")) | ||
return [response_json["embedding"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.