LennardZuendorf commited on
Commit
11174d4
1 Parent(s): 7409c2e

fix: fixing issue with history handling

Browse files
Files changed (1) hide show
  1. model/mistral.py +13 -13
model/mistral.py CHANGED
@@ -66,26 +66,26 @@ def format_prompt(message: str, history: list, system_prompt: str, knowledge: st
66
 
67
  if knowledge != "":
68
  gr.Info("""
69
- Mistral doesn't support additional knowledge, it's gonna be ignored.
70
- """)
71
 
72
  # if no history, use system prompt and example message
73
  if len(history) == 0:
74
- prompt = f"""<s>[INST] {system_prompt} [/INST] How can I help you today? </s>
75
- [INST] {message} [/INST]"""
 
 
76
  else:
77
  # takes the very first exchange and the system prompt as base
78
- for user_prompt, bot_response in history[0]:
79
- prompt = (
80
- f"<s>[INST] {system_prompt} {user_prompt} [/INST] {bot_response}</s>"
81
- )
82
-
83
- # takes all the following conversations and adds them as context
84
- prompt += "".join(
85
- f"[INST] {user_prompt} [/INST] {bot_response}</s>"
86
- for user_prompt, bot_response in history[1:]
87
  )
88
 
 
 
 
 
 
89
  return prompt
90
 
91
 
 
66
 
67
  if knowledge != "":
68
  gr.Info("""
69
+ Mistral doesn't support additional knowledge, it's gonna be ignored.
70
+ """)
71
 
72
  # if no history, use system prompt and example message
73
  if len(history) == 0:
74
+ prompt = f"""
75
+ <s>[INST] {system_prompt} [/INST] How can I help you today? </s>
76
+ [INST] {message} [/INST]
77
+ """
78
  else:
79
  # takes the very first exchange and the system prompt as base
80
+ prompt = (
81
+ f"<s>[INST] {system_prompt} {history[0][0]} [/INST] {history[0][1]}</s>"
 
 
 
 
 
 
 
82
  )
83
 
84
+ # adds conversation history to the prompt
85
+ for conversation in history[1:]:
86
+ # takes all the following conversations and adds them as context
87
+ prompt += "".join(f"[INST] {conversation[0]} [/INST] {conversation[1]}</s>")
88
+
89
  return prompt
90
 
91