Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -81,12 +81,15 @@ def predict_chat(message: str, history: list):
|
|
81 |
yield "Error: Model or tokenizer failed to load. Please check the Space logs for details."
|
82 |
return
|
83 |
|
84 |
-
#
|
85 |
-
# We need to convert it to the format expected by the tokenizer's chat template.
|
86 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
messages.append({"role": "user", "content": message})
|
91 |
|
92 |
generated_text = ""
|
@@ -97,7 +100,6 @@ def predict_chat(message: str, history: list):
|
|
97 |
print("Using GGUF model generation path.")
|
98 |
# Apply chat template for GGUF models as well,
|
99 |
# though ctransformers might expect a simpler string.
|
100 |
-
# This can be adjusted if the model has a specific prompt format.
|
101 |
# For Llama-based models, the tokenizer.apply_chat_template should work.
|
102 |
prompt_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
103 |
|
|
|
81 |
yield "Error: Model or tokenizer failed to load. Please check the Space logs for details."
|
82 |
return
|
83 |
|
84 |
+
# Initialize messages list with system message
|
|
|
85 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
86 |
+
|
87 |
+
# Extend messages with the existing history directly
|
88 |
+
# Gradio's gr.Chatbot(type='messages') passes history as a list of dictionaries
|
89 |
+
# with 'role' and 'content' keys, which is compatible with apply_chat_template.
|
90 |
+
messages.extend(history)
|
91 |
+
|
92 |
+
# Append the current user message
|
93 |
messages.append({"role": "user", "content": message})
|
94 |
|
95 |
generated_text = ""
|
|
|
100 |
print("Using GGUF model generation path.")
|
101 |
# Apply chat template for GGUF models as well,
|
102 |
# though ctransformers might expect a simpler string.
|
|
|
103 |
# For Llama-based models, the tokenizer.apply_chat_template should work.
|
104 |
prompt_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
105 |
|