Update app.py
Browse files254 unmodified lines25525625725825926026115 unmodified lines277278279280281282283284285286287288289290291292293294254 unmodified lines{context}Current Question: {question}If the web search results don't contain relevant information, state that the information is not available in the search results.Provide a concise and direct answer to the question:"""prompt_val = ChatPromptTemplate.from_template(prompt_template)formatted_prompt = prompt_val.format(context=context_str, question=question)15 unmodified linesfull_response = generate_chunked_response(model, formatted_prompt)# Filter out the prompt and extract only the answeranswer_pattern = r"(?:Answer:|Provide a concise and direct answer to the question:)([\s\S]*)"match = re.search(answer_pattern, full_response, re.IGNORECASE)if match:answer = match.group(1).strip()else:# If no match is found, use the entire response but remove any instructionsanswer = re.sub(r"(?i)If the .+?instructions:", "", full_response).strip()# Remove any numbered list formattinganswer = re.sub(r'^\s*\d+\.\s*', '', answer, flags=re.MULTILINE)if not web_search:memory_database[question] = answer254 unmodified lines25525625725825926026115 unmodified lines277278279280281282283284285286287288289290291254 unmodified lines{context}Current Question: {question}If the web search results don't contain relevant information, state that the information is not available in the search results.Provide a concise and direct answer to the question without mentioning the web search or these instructions:"""prompt_val = ChatPromptTemplate.from_template(prompt_template)formatted_prompt = prompt_val.format(context=context_str, question=question)15 unmodified linesfull_response = generate_chunked_response(model, formatted_prompt)# Extract only the part after the specific sentenceanswer_pattern = r"Provide a concise and direct answer to the question without mentioning the web search or these instructions:([\s\S]*)"match = re.search(answer_pattern, full_response, re.IGNORECASE)if match:answer = match.group(1).strip()else:# If the specific sentence is not found, return the full responseanswer = full_response.strip()if not web_search:memory_database[question] = answer
app.py+5-8