Update app.py
Browse files
app.py
CHANGED
|
@@ -110,10 +110,11 @@ def get_response_with_search(query, temperature, top_p, repetition_penalty, use_
|
|
| 110 |
context = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"
|
| 111 |
for result in search_results if 'body' in result)
|
| 112 |
|
| 113 |
-
|
| 114 |
{context}
|
| 115 |
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
| 116 |
-
After
|
|
|
|
| 117 |
|
| 118 |
response = model(prompt)
|
| 119 |
|
|
@@ -122,9 +123,15 @@ After writing the document, please provide a list of sources used in your respon
|
|
| 122 |
return main_content, sources
|
| 123 |
|
| 124 |
def split_response(response):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
parts = response.split("Sources:", 1)
|
| 126 |
main_content = parts[0].strip()
|
| 127 |
sources = parts[1].strip() if len(parts) > 1 else ""
|
|
|
|
| 128 |
return main_content, sources
|
| 129 |
|
| 130 |
def chatbot_interface(message, history, temperature, top_p, repetition_penalty, use_pdf):
|
|
|
|
| 110 |
context = "\n".join(f"{result['title']}\n{result['body']}\nSource: {result['href']}\n"
|
| 111 |
for result in search_results if 'body' in result)
|
| 112 |
|
| 113 |
+
prompt = f"""<s>[INST] Using the following context:
|
| 114 |
{context}
|
| 115 |
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
| 116 |
+
After the main content, provide a list of sources used in your response, prefixed with 'Sources:'.
|
| 117 |
+
Do not include any part of these instructions in your response. [/INST]"""
|
| 118 |
|
| 119 |
response = model(prompt)
|
| 120 |
|
|
|
|
| 123 |
return main_content, sources
|
| 124 |
|
| 125 |
def split_response(response):
|
| 126 |
+
# Remove any remaining instruction text
|
| 127 |
+
response = re.sub(r'\[/?INST\]', '', response)
|
| 128 |
+
response = re.sub(r'~~.*?~~', '', response, flags=re.DOTALL)
|
| 129 |
+
|
| 130 |
+
# Split the response into main content and sources
|
| 131 |
parts = response.split("Sources:", 1)
|
| 132 |
main_content = parts[0].strip()
|
| 133 |
sources = parts[1].strip() if len(parts) > 1 else ""
|
| 134 |
+
|
| 135 |
return main_content, sources
|
| 136 |
|
| 137 |
def chatbot_interface(message, history, temperature, top_p, repetition_penalty, use_pdf):
|