svijayanand/Podcast_Oracle
0
1from helpers.utils import create_or_load_vectore_store2from helpers.import_envs import openai_api_key3from langchain_openai import ChatOpenAI4from langchain.schema import StrOutputParser5from langchain_core.runnables.passthrough import RunnablePassthrough6from langchain.prompts import ChatPromptTemplate7from helpers.model_utils import set_question_answer_llm8 9def answer_question(question, transcript_file_name, llm_choice=None):10 question_answer_llm = set_question_answer_llm(llm_choice)11 12 # Specify the path to the file you want to check13 vector_store = create_or_load_vectore_store(transcript_file_name=transcript_file_name)14 15 # create a prompt template to send to our LLM that will incorporate the documents from our retriever with the16 # question we ask the chat model17 prompt_template = ChatPromptTemplate.from_template(18 "Answer the {question} based on the following {context}."19 )20 21 # create a retriever for our documents22 retriever = vector_store.as_retriever()23 24 # create a parser to parse the output of our LLM25 parser = StrOutputParser()26 27 # 💻 Create the sequence (recipe)28 runnable_chain = (29 # TODO: How do we chain the output of our retriever, prompt, model and model output parser so that we can get a good answer to our query?30 {"context": retriever, "question": RunnablePassthrough()}31 | prompt_template32 | question_answer_llm33 | StrOutputParser()34 )35 36 answer = runnable_chain.invoke(question)37 print(answer)38 return answer39 