Spaces:
Sleeping

smartgit / qa.py
yamlspace's picture
testing ingest scripts
85ecfcf
Raw History Blame Contribute Delete
2.79 kB
import os
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import DeepLake
from dotenv import load_dotenv
load_dotenv()
from langchain.chat_models import ChatOpenAI
from langchain.chains import ConversationalRetrievalChain
embeddings = OpenAIEmbeddings(disallowed_special=())
index_name = 'finecast'
db = DeepLake(dataset_path="./index/" + index_name, read_only=True, embedding_function=embeddings)
retriever = db.as_retriever()
retriever.search_kwargs['distance_metric'] = 'cos'
retriever.search_kwargs['fetch_k'] = 100
retriever.search_kwargs['maximal_marginal_relevance'] = True
retriever.search_kwargs['k'] = 10
model = ChatOpenAI(model='gpt-4') # switch to 'gpt-4'
qa = ConversationalRetrievalChain.from_llm(model,retriever=retriever)
questions = [
# "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 += 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")