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
1234563 unmodified lines1011121213141415161718192021222324252627282930313233343536373839404142432144454647484950235152535455565726272829305859import osimport getpassimport shutil
from 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']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.extend(loader.load_and_split()) docs = loader.load_and_split() docs = text_splitter.split_documents(docs) for d in docs: d.metadata['repo'] = root_dir d.metadata['filename'] = file texts.extend(docs) except Exception as e: pass print(file, e) db.add_documents(texts)
print("db.ds:")db.ds.summary()
text_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)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 lines23242526262728293031323334282930313233343535363738394041424344453946474849505152535455565722 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?", # "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?" #, "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?" #"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: 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 += question
print(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-dotenvopenaideeplaketiktokeningest.py+38-9
ingest_pinecone.pyAdded+51
qa.py+24-10
requirements.txt+5