artificialguybr commited on
Commit
8312b78
1 Parent(s): a85a91b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -19
app.py CHANGED
@@ -34,29 +34,25 @@ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetit
34
  # A última mensagem do usuário
35
  user_prompt = history[-1][0]
36
 
37
- # Definindo o template e o prompt
38
- prompt_template = f'''system
39
- {system_message.strip()}
40
- user
41
- {user_prompt}
42
- assistant
43
- '''
44
 
45
- # Preparando o input
46
- input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids # .cuda() se você estiver usando GPU
47
 
48
- # Gerar a saída
49
- output = model.generate(input_ids=input_ids, temperature=temperature, do_sample=True, top_p=top_p, top_k=top_k, max_length=max_tokens)
50
- print("Output:")
51
- print(output)
52
- # Decodificar a saída
53
  decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
54
- print("Decoded_Output:")
55
- print(decoded_output)
56
- # Atualizar o histórico
57
- history[-1][1] += decoded_output
58
 
59
- yield history, history, ""
 
 
 
60
 
61
  start_message = ""
62
 
 
34
  # A última mensagem do usuário
35
  user_prompt = history[-1][0]
36
 
37
+ # Prepare the messages
38
+ messages = [
39
+ {"role": "system", "content": system_message.strip()},
40
+ {"role": "user", "content": user_prompt}
41
+ ]
 
 
42
 
43
+ # Apply the chat template
44
+ gen_input = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
45
 
46
+ # Generate the output
47
+ output = model.generate(input_ids=gen_input.input_ids, temperature=temperature, do_sample=True, top_p=top_p, top_k=top_k, max_length=max_tokens)
48
+
49
+ # Decode the output
 
50
  decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
 
 
 
 
51
 
52
+ # Update the history
53
+ history[-1][1] += decoded_output.split('\n')[-1] # Only take the assistant's last response
54
+
55
+ return history, history, ""
56
 
57
  start_message = ""
58