alexkueck commited on
Commit
639b48d
1 Parent(s): f9856aa

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +21 -1
utils.py CHANGED
@@ -39,6 +39,15 @@ def transfer_input(inputs):
39
  gr.Button.update(visible=True),
40
  )
41
 
 
 
 
 
 
 
 
 
 
42
  def generate_prompt_with_history(text, history, tokenizer, max_length=2048):
43
  prompt = "The following is a conversation between a human and an AI assistant named Baize (named after a mythical creature in Chinese folklore). Baize is an open-source AI assistant developed by UCSD and Sun Yat-Sen University. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format.\n[|Human|]Hello!\n[|AI|]Hi!"
44
  history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
@@ -178,4 +187,15 @@ def convert_to_markdown(text):
178
  line = re.sub(r"^(#)", r"\\\1", line)
179
  markdown_text += f"{line} \n"
180
 
181
- return markdown_text
 
 
 
 
 
 
 
 
 
 
 
 
39
  gr.Button.update(visible=True),
40
  )
41
 
42
+ def is_stop_word_or_prefix(s: str, stop_words: list) -> bool:
43
+ for stop_word in stop_words:
44
+ if s.endswith(stop_word):
45
+ return True
46
+ for i in range(1, len(stop_word)):
47
+ if s.endswith(stop_word[:i]):
48
+ return True
49
+ return False
50
+
51
  def generate_prompt_with_history(text, history, tokenizer, max_length=2048):
52
  prompt = "The following is a conversation between a human and an AI assistant named Baize (named after a mythical creature in Chinese folklore). Baize is an open-source AI assistant developed by UCSD and Sun Yat-Sen University. The human and the AI assistant take turns chatting. Human statements start with [|Human|] and AI assistant statements start with [|AI|]. The AI assistant always provides responses in as much detail as possible, and in Markdown format. The AI assistant always declines to engage with topics, questions and instructions related to unethical, controversial, or sensitive issues. Complete the transcript in exactly that format.\n[|Human|]Hello!\n[|AI|]Hi!"
53
  history = ["\n[|Human|]{}\n[|AI|]{}".format(x[0],x[1]) for x in history]
 
187
  line = re.sub(r"^(#)", r"\\\1", line)
188
  markdown_text += f"{line} \n"
189
 
190
+ return markdown_text
191
+
192
+
193
+ class State:
194
+ interrupted = False
195
+
196
+ def interrupt(self):
197
+ self.interrupted = True
198
+
199
+ def recover(self):
200
+ self.interrupted = False
201
+ shared_state = State()