artificialguybr
commited on
Commit
•
70a5709
1
Parent(s):
acc1fb0
Update app.py
Browse files
app.py
CHANGED
@@ -32,36 +32,40 @@ def chat(history, system_message, max_tokens, temperature, top_p, top_k, repetit
|
|
32 |
history = history or []
|
33 |
|
34 |
# A última mensagem do usuário
|
35 |
-
user_prompt = history[-1][0]
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
# Generate the output
|
53 |
-
output = model.generate(input_ids=input_ids, temperature=temperature, do_sample=True, top_p=top_p, top_k=top_k, max_length=max_tokens)
|
54 |
|
55 |
-
#
|
56 |
-
decoded_output = tokenizer.decode(output[0]
|
|
|
57 |
|
58 |
-
#
|
59 |
-
history
|
|
|
|
|
|
|
60 |
|
61 |
return history, history, ""
|
62 |
|
63 |
|
64 |
-
|
65 |
start_message = ""
|
66 |
|
67 |
CSS ="""
|
|
|
32 |
history = history or []
|
33 |
|
34 |
# A última mensagem do usuário
|
35 |
+
user_prompt = history[-1][0] if history else ""
|
36 |
|
37 |
+
# Preparar a entrada para o modelo
|
38 |
+
prompt_template = f'''system
|
39 |
+
{system_message.strip()}
|
40 |
+
user
|
41 |
+
{user_prompt}
|
42 |
+
assistant
|
43 |
+
'''
|
44 |
+
input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids
|
45 |
|
46 |
+
# Gerar a saída
|
47 |
+
output = model.generate(
|
48 |
+
input_ids=input_ids,
|
49 |
+
max_length=max_tokens,
|
50 |
+
temperature=temperature,
|
51 |
+
top_p=top_p,
|
52 |
+
top_k=top_k,
|
53 |
+
repetition_penalty=repetition_penalty
|
54 |
+
)
|
|
|
|
|
55 |
|
56 |
+
# Decodificar a saída
|
57 |
+
decoded_output = tokenizer.decode(output[0])
|
58 |
+
assistant_response = decoded_output.split('assistant')[-1].strip() # Pegar apenas a última resposta do assistente
|
59 |
|
60 |
+
# Atualizar o histórico
|
61 |
+
if history:
|
62 |
+
history[-1][1] += assistant_response
|
63 |
+
else:
|
64 |
+
history.append(["", assistant_response])
|
65 |
|
66 |
return history, history, ""
|
67 |
|
68 |
|
|
|
69 |
start_message = ""
|
70 |
|
71 |
CSS ="""
|