Last active
April 15, 2024 03:37
-
-
Save ranfysvalle02/f1a7292a6e4b74aba7fa33ca62e4ac96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from elevenlabs.client import ElevenLabs | |
from elevenlabs import play | |
from langchain_community.vectorstores import MongoDBAtlasVectorSearch | |
from langchain_openai import AzureOpenAIEmbeddings | |
from langchain_core.messages import HumanMessage | |
from langchain_openai import AzureChatOpenAI | |
import pymongo | |
# PDF loaded into MongoDB Atlas = https://arxiv.org/pdf/2303.08774.pdf | |
MDB_URI = "" | |
cluster = pymongo.MongoClient(MDB_URI) | |
DB_NAME = "extbrain" | |
COLLECTION_NAME = "demo_collection" | |
azureEmbeddings = AzureOpenAIEmbeddings( | |
deployment="________________", | |
model="text-embedding-ada-002", | |
azure_endpoint="https://_____________.openai.azure.com", | |
openai_api_key="__API_KEY__", | |
openai_api_type="azure", | |
chunk_size=1, | |
disallowed_special=() | |
) | |
vector_search = MongoDBAtlasVectorSearch.from_connection_string( | |
MDB_URI, | |
DB_NAME + "." + COLLECTION_NAME, | |
azureEmbeddings, | |
index_name="vector_index", | |
) | |
model = AzureChatOpenAI( | |
deployment_name="________________", # Or another suitable engine | |
azure_endpoint="https://_____________.openai.azure.com", | |
openai_api_key="__API_KEY__", | |
openai_api_type="azure", | |
api_version="2023-03-15-preview", | |
) | |
query = "How will the development of more efficient hardware and algorithms impact the future compute requirements for training large language models like GPT-4?" | |
print("QUESTION:"+query) | |
results = vector_search.similarity_search(query) | |
print("# of Results:"+str(len(results))) | |
retrieved_documents = [result.page_content for result in results[:3]] | |
message = HumanMessage( | |
content=f"Answer the following question based on these documents:\n**Question:** {query}\n**Documents:** {retrieved_documents} \n**Answer:**" | |
) | |
client = ElevenLabs( | |
api_key="__API_KEY__" | |
) | |
audio = client.generate( | |
text=str(model([message]).content), | |
voice="__VOICE_ID__" | |
) | |
play(audio) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment