Update app.py
Browse files214 unmodified lines21521621721821922012 unmodified lines23323423523623723823924024124224324424524615 unmodified lines262263264265266267214 unmodified linesprint(" Text: None")print("End of search results")return all_resultsdef ask_question(question, temperature, top_p, repetition_penalty, web_search):12 unmodified linescontext_str = "\n".join([result["text"] for result in search_results if result["text"]])prompt_template = """Answer the question based on the following web search results:Web Search Results:{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 linesanswer = generate_chunked_response(model, formatted_prompt)answer = re.split(r'Question:|Current Question:', answer)[-1].strip()if not web_search:memory_database[question] = answer214 unmodified lines21521621721821922022122222322412 unmodified lines23723823924024124224324424524624715 unmodified lines263264265266267268269270271272214 unmodified linesprint(" Text: None")print("End of search results")if not all_results:print("No search results found. Returning a default message.")return [{"link": None, "text": "No information found in the web search results."}]return all_resultsdef ask_question(question, temperature, top_p, repetition_penalty, web_search):12 unmodified linescontext_str = "\n".join([result["text"] for result in search_results if result["text"]])prompt_template = """Answer the question based on the following web search results:Web Search Results:{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 linesanswer = generate_chunked_response(model, formatted_prompt)answer = re.split(r'Question:|Current Question:', answer)[-1].strip()# Remove any remaining prompt instructions from the answeranswer_lines = answer.split('\n')answer = '\n'.join(line for line in answer_lines if not line.startswith('If') and not line.startswith('Provide'))if not web_search:memory_database[question] = answer
app.py+9-4