fix None errors
Browse files
app.py
CHANGED
@@ -16,7 +16,8 @@ def generate_prompt(instruction, input=None, history=None):
|
|
16 |
# parse the chat history into a string of user and assistant messages
|
17 |
history_str = ""
|
18 |
|
19 |
-
|
|
|
20 |
for pair in history:
|
21 |
history_str += f"User: {pair[0]}\n\nAssistant: {pair[1]}\n\n"
|
22 |
|
@@ -26,10 +27,14 @@ def generate_prompt(instruction, input=None, history=None):
|
|
26 |
.replace("\n\n", "\n")
|
27 |
.replace("\n\n", "\n")
|
28 |
)
|
29 |
-
|
30 |
-
input
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
return f"""{history_str}Instruction: {instruction}
|
34 |
|
35 |
Input: {input}
|
|
|
16 |
# parse the chat history into a string of user and assistant messages
|
17 |
history_str = ""
|
18 |
|
19 |
+
has_history = (history is not None)
|
20 |
+
if has_history:
|
21 |
for pair in history:
|
22 |
history_str += f"User: {pair[0]}\n\nAssistant: {pair[1]}\n\n"
|
23 |
|
|
|
27 |
.replace("\n\n", "\n")
|
28 |
.replace("\n\n", "\n")
|
29 |
)
|
30 |
+
if not has_history:
|
31 |
+
input = (
|
32 |
+
input.strip()
|
33 |
+
.replace("\r\n", "\n")
|
34 |
+
.replace("\n\n", "\n")
|
35 |
+
.replace("\n\n", "\n")
|
36 |
+
)
|
37 |
+
if not has_history and len(input) > 0:
|
38 |
return f"""{history_str}Instruction: {instruction}
|
39 |
|
40 |
Input: {input}
|