Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,7 +56,19 @@ def build_prompt(message, history, system_message, max_ctx_tokens=1024):
|
|
| 56 |
msgs.append({"role": "assistant", "content": a})
|
| 57 |
msgs.append({"role": "user", "content": message})
|
| 58 |
while True:
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
if len(tokenizer(text, add_special_tokens=False).input_ids) <= max_ctx_tokens:
|
| 61 |
return text
|
| 62 |
for i in range(1, len(msgs)):
|
|
|
|
| 56 |
msgs.append({"role": "assistant", "content": a})
|
| 57 |
msgs.append({"role": "user", "content": message})
|
| 58 |
while True:
|
| 59 |
+
chat_template = """{% for m in messages %}
|
| 60 |
+
{{ m['role'] }}: {{ m['content'] }}
|
| 61 |
+
{% endfor %}
|
| 62 |
+
Assistant:"""
|
| 63 |
+
|
| 64 |
+
text = tokenizer.apply_chat_template(
|
| 65 |
+
msgs,
|
| 66 |
+
chat_template=chat_template,
|
| 67 |
+
tokenize=False,
|
| 68 |
+
add_generation_prompt=True
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
if len(tokenizer(text, add_special_tokens=False).input_ids) <= max_ctx_tokens:
|
| 73 |
return text
|
| 74 |
for i in range(1, len(msgs)):
|