Spaces:
Sleeping
Sleeping
testing ingest scripts
Browse filesFiles changed (4)
- ingest.py+38-9
- ingest_pinecone.pyAdded+51
- qa.py+24-10
- requirements.txt+5
123453 unmodified lines9101112131415161718192021222324252627282930import osimport getpassfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import DeepLake3 unmodified linesfrom dotenv import load_dotenvload_dotenv()embeddings = OpenAIEmbeddings(disallowed_special=())index_name = 'finecast'root_dirs = ['../../elsewhen/finecast/infra2','../../elsewhen/finecast-infrastructure']docs = []for root_dir in root_dirs:for dirpath, dirnames, filenames in os.walk(root_dir):for file in filenames:try:loader = TextLoader(os.path.join(dirpath, file), encoding='utf-8')docs.extend(loader.load_and_split())except Exception as e:passtext_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)texts = text_splitter.split_documents(docs)db = DeepLake(dataset_path=f"./index/" + index_name, embedding_function=embeddings) #dataset would be publicly availabledb.add_documents(texts)1234563 unmodified lines1011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import osimport getpassimport shutilfrom langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import DeepLake3 unmodified linesfrom dotenv import load_dotenvload_dotenv()embeddings = OpenAIEmbeddings(disallowed_special=())index_name = "./index/" + 'finecast'if os.path.exists(index_name):shutil.rmtree(index_name)db = DeepLake(dataset_path=index_name, embedding_function=embeddings) #dataset would be publicly available#root_dirs = ['../../elsewhen/finecast-infrastructure','../../elsewhen/finecast/infra2','../../elsewhen/finecast/infrastructure','../../elsewhen/finecast/ci']root_dirs = ['../../elsewhen/finecast-infrastructure/.github','../../elsewhen/finecast-infrastructure/environments','../../elsewhen/finecast-infrastructure/modules','../../elsewhen/finecast-infrastructure/scripts','../../elsewhen/finecast-infrastructure/layers','../../elsewhen/finecast-infrastructure/*.yaml','../../elsewhen/finecast-infrastructure/*.md','../../elsewhen/finecast/infra2','../../elsewhen/finecast/infrastructure','../../elsewhen/finecast/ci']text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)docs = []texts = []for root_dir in root_dirs:for dirpath, dirnames, filenames in os.walk(root_dir):for file in filenames:try:loader = TextLoader(os.path.join(dirpath, file), encoding='utf-8')docs = loader.load_and_split()docs = text_splitter.split_documents(docs)for d in docs:d.metadata['repo'] = root_dird.metadata['filename'] = filetexts.extend(docs)except Exception as e:print(file, e)db.add_documents(texts)print("db.ds:")db.ds.summary()print(len(db.ds))print ("end db.ds")
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import osimport getpassimport shutilimport pinecone
from langchain.embeddings.openai import OpenAIEmbeddingsfrom langchain.vectorstores import DeepLakefrom langchain.text_splitter import CharacterTextSplitter
from langchain.document_loaders import TextLoaderfrom dotenv import load_dotenvload_dotenv()embeddings = OpenAIEmbeddings(disallowed_special=())
index_name = "./index/" + 'finecast'index_name = 'finecast'pinecone.init( api_key=os.environ.get('PINECONE_API_KEY'), environment="northamerica-northeast1-gcp")# check if index already exists (it shouldn't if this is first time)if index_name not in pinecone.list_indexes(): # if does not exist, create index pinecone.create_index( index_name, dimension=len(res['data'][0]['embedding']), metric='cosine', metadata_config={'indexed': ['channel_id', 'published']} )# connect to indexindex = pinecone.Index(index_name)
if os.path.exists(index_name): shutil.rmtree(index_name)db = DeepLake(dataset_path=index_name, embedding_function=embeddings) #dataset would be publicly available
root_dirs = ['../../elsewhen/finecast-infrastructure','../../elsewhen/finecast/infra2','../../elsewhen/finecast/infrastructure','../../elsewhen/finecast/ci']docs = []for root_dir in root_dirs: docs = [] for dirpath, dirnames, filenames in os.walk(root_dir): for file in filenames: try: loader = TextLoader(os.path.join(dirpath, file), encoding='utf-8') docs.extend(loader.load_and_split()) except Exception as e: pass text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0) texts = text_splitter.split_documents(docs) db.add_documents(texts)
22 unmodified lines23242526272829303132333435363738394041424322 unmodified linesquestions = [# "the admin-webapp trigger is not showing up o github in the finecast-develop environment. what change do i need to make to the yaml file so it runs the trigger when someone raises a PR?"# 'in simple terms explain what will adding this - github: ${\_trigger_code_build_github_repo_connection} to the file infra2/environments/finecast-develop/cloudbuild/triggers.yaml do?'"in infra2, what is the default behaviour of secrets?",# "whats the difference between a random secret and a secret?","in infra2, how many types of secrets are there?","how many repositories are there about finecast?"# "can you generate a set of FAQ for infra2 that could be useful for a programmer to know?"#"how can i add a new random secret called 'abc' for the 'us' environment?"#"can you explain how the yaml files work in the environments folder?",#"what does the cloudbuild yaml file do?",#"what does the git-setup, clone-modules and the git-actions cloud build yaml files do?",#"explain me how i can create a module in finecast-infrastructure that i can use in infra2?"]chat_history = []for question in questions:result = qa({"question": question, "chat_history": chat_history})chat_history.append((question, result['answer']))print(f"-> **Question**: {question} \n")print(f"**Answer**: {result['answer']} \n")22 unmodified lines232425262728293031323334353637383940414243444546474849505152535455565722 unmodified linesquestions = [# "the admin-webapp trigger is not showing up o github in the finecast-develop environment. what change do i need to make to the yaml file so it runs the trigger when someone raises a PR?"# 'in simple terms explain what will adding this - github: ${\_trigger_code_build_github_repo_connection} to the file infra2/environments/finecast-develop/cloudbuild/triggers.yaml do?'# "in infra2, what is the default behaviour of secrets?",# "how many terraform modules are there?",# "whats the difference between a random secret and a secret?",# "in infra2, how many types of secrets are there?",# "how many repo do we have?",#"how many files in infra2 repo?",# "how many repositories are there about finecast?","my name is nayeem, how are you?","what is my name?" #,#"what is the project_number of nexus-artifacts environment?",#"how many environments are there?",# "can you generate a set of FAQ for infra2 that could be useful for a programmer to know?",# "how can i add a new random secret called 'abc' for the 'us' environment?",# "can you explain how the yaml files work in the environments folder?",#"what does the cloudbuild yaml file do?"# "what does the git-setup, clone-modules and the git-actions cloud build yaml files do?",#"explain me how i can create a module in finecast-infrastructure that i can use in infra2?"]chat_history = []for question in questions:# context = "\n".join(f"{q}\n{a}" for q, a in chat_history) # Create the context string# if context:# context += "\n" # Add a newline separator before the current question# context += questionprint(f"Chat history: {chat_history}")result = qa({"question": question, "chat_history": chat_history})#result = qa({"question": question, "context": context})chat_history.append((question, result['answer']))print(f"-> **Question**: {question} \n")print(f"**Answer**: {result['answer']} \n")
12345langchainpython-dotenvopenaideeplaketiktoken
ingest.py+38-9
ingest_pinecone.pyAdded+51
qa.py+24-10
requirements.txt+5