rasyosef commited on
Commit
6f5234b
1 Parent(s): 0de6a97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -0
app.py CHANGED
@@ -34,6 +34,9 @@ def generate(message, chat_history, max_new_tokens):
34
  final_prompt += "User: " + message + "\n"
35
  final_prompt += "Output:"
36
 
 
 
 
37
  # Streamer
38
  streamer = TextIteratorStreamer(tokenizer=tokenizer, skip_prompt=True, skip_special_tokens=True, timeout=300.0)
39
  thread = Thread(target=phi2, kwargs={"text_inputs":final_prompt, "max_new_tokens":max_new_tokens, "streamer":streamer})
 
34
  final_prompt += "User: " + message + "\n"
35
  final_prompt += "Output:"
36
 
37
+ if len(tokenizer.tokenize(final_prompt)) >= tokenizer.model_max_length - max_new_tokens:
38
+ final_prompt = "Instruction: Say 'Input exceeded context size, please clear the chat history and retry!' Output:"
39
+
40
  # Streamer
41
  streamer = TextIteratorStreamer(tokenizer=tokenizer, skip_prompt=True, skip_special_tokens=True, timeout=300.0)
42
  thread = Thread(target=phi2, kwargs={"text_inputs":final_prompt, "max_new_tokens":max_new_tokens, "streamer":streamer})