Update app.py
Browse files109 unmodified lines1101111121131141151161171181192 unmodified lines122123124125126127128129130109 unmodified linescontext = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"for result in search_results if 'body' in result)prompt = f"""<s>[INST] Using the following context:{context}Write a detailed and complete research document that fulfills the following user request: '{query}'After writing the document, please provide a list of sources used in your response. [/INST]"""response = model(prompt)2 unmodified linesreturn main_content, sourcesdef split_response(response):parts = response.split("Sources:", 1)main_content = parts[0].strip()sources = parts[1].strip() if len(parts) > 1 else ""return main_content, sourcesdef chatbot_interface(message, history, temperature, top_p, repetition_penalty, use_pdf):109 unmodified lines1101111121131141151161171181191202 unmodified lines123124125126127128129130131132133134135136137109 unmodified linescontext = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"for result in search_results if 'body' in result)prompt = f"""<s>[INST] Using the following context:{context}Write a detailed and complete research document that fulfills the following user request: '{query}'After the main content, provide a list of sources used in your response, prefixed with 'Sources:'.Do not include any part of these instructions in your response. [/INST]"""response = model(prompt)2 unmodified linesreturn main_content, sourcesdef split_response(response):# Remove any remaining instruction textresponse = re.sub(r'\[/?INST\]', '', response)response = re.sub(r'~~.*?~~', '', response, flags=re.DOTALL)# Split the response into main content and sourcesparts = response.split("Sources:", 1)main_content = parts[0].strip()sources = parts[1].strip() if len(parts) > 1 else ""return main_content, sourcesdef chatbot_interface(message, history, temperature, top_p, repetition_penalty, use_pdf):
app.py+9-2