FredZhang7 commited on
Commit
58d14e4
1 Parent(s): 7f06e10

fix None errors

Browse files
Files changed (1) hide show
  1. app.py +10 -5
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
- if history is not None:
 
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
- input = (
30
- input.strip().replace("\r\n", "\n").replace("\n\n", "\n").replace("\n\n", "\n")
31
- )
32
- if input and len(input) > 0:
 
 
 
 
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}