ColeGuion commited on
Commit
3a3ea8c
·
verified ·
1 Parent(s): 6c67b51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -6,7 +6,7 @@ client = InferenceClient(
6
  )
7
 
8
  # Formats the prompt to hold all of the past messages
9
- def format_prompt(message, history):
10
  prompt = "<s>"
11
 
12
  # Iterates through every pass user input and response to be added to the prompt
@@ -19,7 +19,24 @@ def format_prompt(message, history):
19
  prompt += f"[INST] {message} [/INST]"
20
 
21
  return prompt
 
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
25
  temperature = float(temperature)
 
6
  )
7
 
8
  # Formats the prompt to hold all of the past messages
9
+ """def format_prompt(message, history):
10
  prompt = "<s>"
11
 
12
  # Iterates through every pass user input and response to be added to the prompt
 
19
  prompt += f"[INST] {message} [/INST]"
20
 
21
  return prompt
22
+ """
23
+ def format_prompt(message, history):
24
+ prompt = "<s>"
25
 
26
+ # Prepend "Please correct the grammar in the following sentence: " to each user input
27
+ grammar_correction_prefix = "Please correct the grammar in the following sentence: "
28
+
29
+ # Iterates through every past user input and response to be added to the prompt
30
+ for user_prompt, bot_response in history:
31
+ corrected_user_prompt = grammar_correction_prefix + user_prompt
32
+ prompt += f"[INST] {corrected_user_prompt} [/INST]"
33
+ prompt += f" {bot_response}</s> "
34
+
35
+ # Also prepend the prefix to the current message
36
+ corrected_message = grammar_correction_prefix + message
37
+ prompt += f"[INST] {corrected_message} [/INST]"
38
+
39
+ return prompt
40
 
41
  def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
42
  temperature = float(temperature)