Skip to content
Snippets Groups Projects
Commit 0b19227b authored by abir.chebbi's avatar abir.chebbi
Browse files

update the script

parent 607b999e
No related branches found
No related tags found
No related merge requests found
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
import boto3
import os
import argparse
......
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
## Source: https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-sdk.html
import boto3
import botocore
import time
......
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
import boto3
BUCKET_NAME = 'cloud-lecture-2023'
BUCKET_NAME = ''
S3_CLIENT = boto3.client('s3')
S3_RESOURCE = boto3.resource('s3')
......
import boto3
from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth
from langchain_community.embeddings import BedrockEmbeddings
# AWS and OpenSearch Configuration
host = 'd7gvxdj7jpz3h3bj0xq6.us-east-1.aoss.amazonaws.com'
index_name = 'cloud_lecture'
awsauth = AWSV4SignerAuth(boto3.Session().get_credentials(), 'us-east-1', 'aoss')
# OpenSearch Client
opensearch_client = OpenSearch(
hosts=[{'host': host, 'port': 443}],
http_auth=awsauth,
use_ssl=True,
verify_certs=True,
connection_class=RequestsHttpConnection,
)
# Embeddings Client
bedrock_client = boto3.client(service_name="bedrock-runtime")
def get_embedding(question, bedrock_client):
embeddings_model = BedrockEmbeddings(model_id="amazon.titan-embed-text-v1", client=bedrock_client)
embedding = embeddings_model.embed_query(question)
return embedding
def knn_query(vector, index_name):
query_body = {
"size": 10,
"query": {
"knn": {
"vector_field": {
"vector": vector,
"k": 10
}
}
}
}
response = opensearch_client.search(index=index_name, body=query_body)
return response['hits']['hits']
def main():
question = "What is FAAS?"
print("Generating embedding for the question...")
question_embedding = get_embedding(question, bedrock_client)
print("Querying the index for similar contents...")
search_results = knn_query(question_embedding, index_name)
print(search_results[0])
if __name__ == "__main__":
main()
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
import boto3
import os
from langchain_community.document_loaders import PyPDFDirectoryLoader
......
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
import boto3
import streamlit as st
......
[aws]
aws_access_key_id = AKIAVEKYIBTQKSG2R342
aws_secret_access_key = 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
region = us-east-1
aws_access_key_id =
aws_secret_access_key =
region =
[opensearch]
endpoint = ku7nut9wcogpz1nw15j0.us-east-1.aoss.amazonaws.com
index_name = cloud-lecture
endpoint =
index_name =
# Creator: Abir Chebbi (abir.chebbi@hesge.ch)
import boto3
import base64
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment