Zenithwang commited on
Commit
25a236c
1 Parent(s): 3f6e344

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -46,21 +46,20 @@ def predict(message, history):
46
  stop = StopOnTokens()
47
 
48
  # Formatting the input for the model.
49
- messages = system_prompt + sft_end_token.join([sft_end_token.join([f"\n{sft_start_token}{user_role}\n" + item[0], f"\n{sft_start_token}{assistant_role}\n" + item[1]])
50
- for item in history_transformer_format])
51
- model_inputs = tokenizer([messages], return_tensors="pt").to(device)
 
 
 
 
52
  streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
53
  generate_kwargs = dict(
54
  model_inputs,
55
  streamer=streamer,
56
- max_new_tokens=512,
57
- do_sample=True,
58
- top_p= 0.75,
59
- top_k= 60,
60
- temperature=0.2,
61
- num_beams=1,
62
- stopping_criteria=StoppingCriteriaList([stop]),
63
- repetition_penalty=1.1,
64
  )
65
  t = Thread(target=model.generate, kwargs=generate_kwargs)
66
  t.start() # Starting the generation in a separate thread.
@@ -93,7 +92,7 @@ placeholder = """
93
  </div>
94
  """
95
 
96
- chatbot = gr.Chatbot(label='Sailor', placeholder=placeholder)
97
  with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
98
  # gr.Markdown("""<center><font size=8>Sailor-Chat Bot⚓</center>""")
99
  gr.Markdown("""<p align="center"><img src="https://github.com/sail-sg/sailor-llm/raw/main/misc/wide_sailor_banner.jpg" style="height: 110px"/><p>""")
 
46
  stop = StopOnTokens()
47
 
48
  # Formatting the input for the model.
49
+ # messages = system_prompt + sft_end_token.join([sft_end_token.join([f"\n{sft_start_token}{user_role}\n" + item[0], f"\n{sft_start_token}{assistant_role}\n" + item[1]])
50
+ # for item in history_transformer_format])
51
+
52
+ messages = [{user_role: item[0], assistant_role: item[1]} for item in history_transformer_format]
53
+ model_inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(device)
54
+ # model_inputs = tokenizer([messages], return_tensors="pt").to(device)
55
+
56
  streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
57
  generate_kwargs = dict(
58
  model_inputs,
59
  streamer=streamer,
60
+ max_new_tokens=1024,
61
+ do_sample=False,
62
+ # stopping_criteria=StoppingCriteriaList([stop])
 
 
 
 
 
63
  )
64
  t = Thread(target=model.generate, kwargs=generate_kwargs)
65
  t.start() # Starting the generation in a separate thread.
 
92
  </div>
93
  """
94
 
95
+ chatbot = gr.Chatbot(label='Sailor', placeholder=None)
96
  with gr.Blocks(theme=gr.themes.Soft(), fill_height=True) as demo:
97
  # gr.Markdown("""<center><font size=8>Sailor-Chat Bot⚓</center>""")
98
  gr.Markdown("""<p align="center"><img src="https://github.com/sail-sg/sailor-llm/raw/main/misc/wide_sailor_banner.jpg" style="height: 110px"/><p>""")