Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -4,7 +4,6 @@ import yaml
|
|
4 |
from transformers import GenerationConfig
|
5 |
|
6 |
from strings import SPECIAL_STRS
|
7 |
-
from constants import num_of_characters_to_keep
|
8 |
from constants import html_tag_pattern, multi_line_pattern, multi_space_pattern
|
9 |
from constants import repl_empty_str, repl_br_tag, repl_span_tag_multispace, repl_linebreak
|
10 |
|
@@ -22,12 +21,13 @@ def generate_prompt(prompt, histories, ctx=None):
|
|
22 |
convs = f"""{ctx}
|
23 |
|
24 |
"""
|
25 |
-
|
26 |
start_idx = 0
|
27 |
|
28 |
for idx, history in enumerate(histories):
|
29 |
history_prompt = history[0]
|
30 |
-
|
|
|
31 |
start_idx = idx
|
32 |
|
33 |
# drop the previous conversations if user has summarized
|
@@ -40,17 +40,20 @@ def generate_prompt(prompt, histories, ctx=None):
|
|
40 |
html_tag_pattern, repl_empty_str, history_response
|
41 |
)
|
42 |
|
43 |
-
|
44 |
|
45 |
### Response:{history_response}
|
46 |
|
47 |
"""
|
48 |
|
49 |
-
|
50 |
|
51 |
### Response:"""
|
52 |
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
# applicable to instruction to be displayed as well
|
56 |
def common_post_process(original_str):
|
|
|
4 |
from transformers import GenerationConfig
|
5 |
|
6 |
from strings import SPECIAL_STRS
|
|
|
7 |
from constants import html_tag_pattern, multi_line_pattern, multi_space_pattern
|
8 |
from constants import repl_empty_str, repl_br_tag, repl_span_tag_multispace, repl_linebreak
|
9 |
|
|
|
21 |
convs = f"""{ctx}
|
22 |
|
23 |
"""
|
24 |
+
sub_convs = ""
|
25 |
start_idx = 0
|
26 |
|
27 |
for idx, history in enumerate(histories):
|
28 |
history_prompt = history[0]
|
29 |
+
history_response = history[1]
|
30 |
+
if history_response == "β
summarization is done and set as context" or history_prompt == SPECIAL_STRS["summarize"]:
|
31 |
start_idx = idx
|
32 |
|
33 |
# drop the previous conversations if user has summarized
|
|
|
40 |
html_tag_pattern, repl_empty_str, history_response
|
41 |
)
|
42 |
|
43 |
+
sub_convs = sub_convs + f"""### Instruction:{history_prompt}
|
44 |
|
45 |
### Response:{history_response}
|
46 |
|
47 |
"""
|
48 |
|
49 |
+
sub_convs = sub_convs + f"""### Instruction:{prompt}
|
50 |
|
51 |
### Response:"""
|
52 |
|
53 |
+
convs = convs + sub_convs
|
54 |
+
print(convs)
|
55 |
+
|
56 |
+
return convs, len(sub_convs)
|
57 |
|
58 |
# applicable to instruction to be displayed as well
|
59 |
def common_post_process(original_str):
|