ivxivx commited on
Commit
16541ad
·
unverified ·
1 Parent(s): 9313d4b

chore: simplify

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -65,12 +65,11 @@ examples = [
65
  def predict(message, history):
66
  history.append({"role": "system", "content": system_prompt})
67
  history.append({"role": "user", "content": message})
68
- input_text = tokenizer.apply_chat_template(history, tokenize=False)
69
- inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
70
- outputs = model.generate(inputs, max_new_tokens=100, temperature=0.2, top_p=0.9, do_sample=True)
71
- decoded = tokenizer.decode(outputs[0])
72
- response = decoded.split("<|im_start|>assistant\n")[-1].split("<|im_end|>")[0]
73
- # response: I'm ready to help you with your math homework. What's your math problem?
74
  print(f"Response: {response}, outputs: {outputs}")
75
  return response
76
 
 
65
  def predict(message, history):
66
  history.append({"role": "system", "content": system_prompt})
67
  history.append({"role": "user", "content": message})
68
+
69
+ inputs = tokenizer.apply_chat_template(history, return_tensors="pt").to(device)
70
+ outputs = model.generate(**inputs, max_new_tokens=100)
71
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
72
+
 
73
  print(f"Response: {response}, outputs: {outputs}")
74
  return response
75