artificialguybr
commited on
Commit
•
8312b78
1
Parent(s):
a85a91b
Update app.py
Browse files
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 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
assistant
|
43 |
-
'''
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
|
48 |
-
#
|
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 |
-
|
51 |
-
|
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 |
-
|
|
|
|
|
|
|
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 |
|