AkashDataScience commited on
Commit
749e9d7
·
1 Parent(s): 1a5b783

Adding chat history

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -26,8 +26,15 @@ tokenizer.padding_side = "right"
26
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
27
 
28
  def infer(message, history):
29
- prompt = pipe.tokenizer.apply_chat_template([{"role": "user", "content": message}], tokenize=False, add_generation_prompt=True)
 
 
 
 
 
 
 
30
  outputs = pipe(prompt, max_new_tokens=256, do_sample=True, num_beams=1, temperature=0.3, top_k=50, top_p=0.95, max_time= 180)
31
  return outputs[0]['generated_text'][len(prompt):].strip()
32
 
33
- gr.ChatInterface(infer).launch()
 
26
  pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
27
 
28
  def infer(message, history):
29
+ chat_list = []
30
+ for chat in history:
31
+ chat_user = {"role":"user", "content":chat[0]}
32
+ chat_assistant = {"role":"assistant", "content":chat[1]}
33
+ chat_list.append(chat_user)
34
+ chat_list.append(chat_assistant)
35
+ chat_list.append({"role": "user", "content": message})
36
+ prompt = pipe.tokenizer.apply_chat_template(chat_list, tokenize=False, add_generation_prompt=True)
37
  outputs = pipe(prompt, max_new_tokens=256, do_sample=True, num_beams=1, temperature=0.3, top_k=50, top_p=0.95, max_time= 180)
38
  return outputs[0]['generated_text'][len(prompt):].strip()
39
 
40
+ gr.ChatInterface(infer, title="Phi-3 Assistant").launch()