Update app.py
Browse files
app.py
CHANGED
|
@@ -80,9 +80,12 @@ def generate_chunked_response(model, prompt, max_tokens=500, max_chunks=5):
|
|
| 80 |
full_response = ""
|
| 81 |
for i in range(max_chunks):
|
| 82 |
chunk = model(prompt + full_response, max_new_tokens=max_tokens)
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
break
|
|
|
|
| 86 |
return full_response.strip()
|
| 87 |
|
| 88 |
def response(database, model, question):
|
|
@@ -95,7 +98,7 @@ def response(database, model, question):
|
|
| 95 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
| 96 |
|
| 97 |
ans = generate_chunked_response(model, formatted_prompt)
|
| 98 |
-
return ans # Only return the answer
|
| 99 |
|
| 100 |
def update_vectors(files, use_recursive_splitter):
|
| 101 |
if not files:
|
|
|
|
| 80 |
full_response = ""
|
| 81 |
for i in range(max_chunks):
|
| 82 |
chunk = model(prompt + full_response, max_new_tokens=max_tokens)
|
| 83 |
+
chunk = chunk.strip()
|
| 84 |
+
# Check for final sentence endings
|
| 85 |
+
if chunk.endswith((".", "!", "?")):
|
| 86 |
+
full_response += chunk
|
| 87 |
break
|
| 88 |
+
full_response += chunk
|
| 89 |
return full_response.strip()
|
| 90 |
|
| 91 |
def response(database, model, question):
|
|
|
|
| 98 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
| 99 |
|
| 100 |
ans = generate_chunked_response(model, formatted_prompt)
|
| 101 |
+
return ans # Only return the final answer
|
| 102 |
|
| 103 |
def update_vectors(files, use_recursive_splitter):
|
| 104 |
if not files:
|