Spaces:
Runtime error
Runtime error
Balance backticks and add title
Browse files
app.py
CHANGED
@@ -41,6 +41,20 @@ def add_text(history, text):
|
|
41 |
history = history + [(text, None)]
|
42 |
return history, gr.Textbox(value="", interactive=False)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
def bot(history, api_kind,
|
46 |
num_docs, model_kind, sub_vector_size, chunk_size, splitter_type, all_at_once):
|
@@ -79,7 +93,10 @@ def bot(history, api_kind,
|
|
79 |
prompt_html = template_html.render(documents=documents, query=query)
|
80 |
|
81 |
hist_chunk = ""
|
82 |
-
prev_hist = history[-1][1]
|
|
|
|
|
|
|
83 |
for character in generate_fn(prompt_i, history[:-1]):
|
84 |
hist_chunk = character
|
85 |
history[-1][1] = prev_hist + hist_chunk
|
|
|
41 |
history = history + [(text, None)]
|
42 |
return history, gr.Textbox(value="", interactive=False)
|
43 |
|
44 |
+
def has_balanced_backticks(markdown_str):
|
45 |
+
in_code_block = False
|
46 |
+
lines = markdown_str.split('\n')
|
47 |
+
|
48 |
+
for line in lines:
|
49 |
+
stripped_line = line.strip()
|
50 |
+
|
51 |
+
# Check if the line contains triple backticks
|
52 |
+
if stripped_line.startswith("```"):
|
53 |
+
# Toggle the in_code_block flag
|
54 |
+
in_code_block = not in_code_block
|
55 |
+
|
56 |
+
# If in_code_block is False at the end, all backticks are balanced
|
57 |
+
return not in_code_block
|
58 |
|
59 |
def bot(history, api_kind,
|
60 |
num_docs, model_kind, sub_vector_size, chunk_size, splitter_type, all_at_once):
|
|
|
93 |
prompt_html = template_html.render(documents=documents, query=query)
|
94 |
|
95 |
hist_chunk = ""
|
96 |
+
prev_hist = history[-1][1]
|
97 |
+
if not has_balanced_backticks(prev_hist):
|
98 |
+
prev_hist += "\n```\n"
|
99 |
+
prev_hist += f"\n\n## model {model_name}, splitter {doc}, size {size}, sub vector {sub_vector}\n\n"
|
100 |
for character in generate_fn(prompt_i, history[:-1]):
|
101 |
hist_chunk = character
|
102 |
history[-1][1] = prev_hist + hist_chunk
|