Update app.py
Browse files254 unmodified lines25525625725825825926026115 unmodified lines277278279280281280281282283284285286287288289290291287288289290291254 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: 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 lines
full_response = generate_chunked_response(model, formatted_prompt) # Filter out the prompt and extract only the answer answer_pattern = r"(?:Answer:|Provide a concise and direct answer to the question:)([\s\S]*)" # Extract only the part after the specific sentence answer_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 no match is found, use the entire response but remove any instructions answer = re.sub(r"(?i)If the .+?instructions:", "", full_response).strip() # Remove any numbered list formatting answer = re.sub(r'^\s*\d+\.\s*', '', answer, flags=re.MULTILINE) # If the specific sentence is not found, return the full response answer = full_response.strip()
if not web_search: memory_database[question] = answerapp.py+5-8