Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ def format_prompt_basic(message, history):
|
|
26 |
return prompt
|
27 |
|
28 |
# Formats the prompt to hold all of the past messages
|
29 |
-
def
|
30 |
prompt = "<s>"
|
31 |
|
32 |
# String to add before every prompt
|
@@ -47,6 +47,24 @@ def format_prompt_grammar(message, history):
|
|
47 |
print("PROMPT: \n\t{}\n".format(prompt))
|
48 |
return prompt
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
|
52 |
|
@@ -60,7 +78,8 @@ def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=256
|
|
60 |
generate_kwargs = dict(temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42,)
|
61 |
|
62 |
#formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
63 |
-
formatted_prompt = format_prompt_grammar(f"{system_prompt} {prompt}", history)
|
|
|
64 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
65 |
output = ""
|
66 |
|
|
|
26 |
return prompt
|
27 |
|
28 |
# Formats the prompt to hold all of the past messages
|
29 |
+
def format_prompt_grammar1(message, history):
|
30 |
prompt = "<s>"
|
31 |
|
32 |
# String to add before every prompt
|
|
|
47 |
print("PROMPT: \n\t{}\n".format(prompt))
|
48 |
return prompt
|
49 |
|
50 |
+
# Don't track actual history
|
51 |
+
def format_prompt_grammar(message):
|
52 |
+
prompt = "<s>"
|
53 |
+
|
54 |
+
# String to add before every prompt
|
55 |
+
prompt_prefix = "Correct any grammatical errors in the following sentence and provide the corrected version:\nSentence:"
|
56 |
+
prompt_template = "[INST] " + prompt_prefix + ' {} [/INST]'
|
57 |
+
|
58 |
+
history = [["It is my friends house in England.", "It is my friend's house in England."], ["Every girl must bring their books to school.", "Every girl must bring her books to school."]]
|
59 |
+
|
60 |
+
# Iterates through every past user input and response to be added to the prompt
|
61 |
+
for user_prompt, bot_response in history:
|
62 |
+
prompt += prompt_template.format(user_prompt)
|
63 |
+
prompt += f" {bot_response}</s> \n"
|
64 |
+
|
65 |
+
prompt += prompt_template.format(message)
|
66 |
+
print("PROMPT: \n\t{}\n".format(prompt))
|
67 |
+
return prompt
|
68 |
|
69 |
|
70 |
|
|
|
78 |
generate_kwargs = dict(temperature=temperature, max_new_tokens=max_new_tokens, top_p=top_p, repetition_penalty=repetition_penalty, do_sample=True, seed=42,)
|
79 |
|
80 |
#formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
81 |
+
#formatted_prompt = format_prompt_grammar(f"{system_prompt} {prompt}", history)
|
82 |
+
formatted_prompt = format_prompt_grammar(prompt)
|
83 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
84 |
output = ""
|
85 |
|