Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -73,6 +73,12 @@ chat_history = []
|
|
73 |
def interact(user_input, history, interaction_count):
|
74 |
global tokenizer, model
|
75 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
if tokenizer is None or model is None:
|
77 |
raise ValueError("Tokenizer or model is not initialized.")
|
78 |
|
@@ -85,11 +91,6 @@ def interact(user_input, history, interaction_count):
|
|
85 |
if messages[i-1].get("role") == messages[i].get("role"):
|
86 |
raise ValueError("Conversation roles must alternate user/assistant/user/assistant/...")
|
87 |
|
88 |
-
if interaction_count >= MAX_INTERACTIONS:
|
89 |
-
user_input += '''.
|
90 |
-
***
|
91 |
-
Thank you for your questions. Our session is now over. Goodbye!'''
|
92 |
-
|
93 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
94 |
|
95 |
# Generate response using selected model
|
|
|
73 |
def interact(user_input, history, interaction_count):
|
74 |
global tokenizer, model
|
75 |
try:
|
76 |
+
if interaction_count >= MAX_INTERACTIONS:
|
77 |
+
response = "Thank you for your questions. Our session is now over. Goodbye!"
|
78 |
+
history.append({"role": "assistant", "content": response})
|
79 |
+
formatted_history = [(entry["content"], None) if entry["role"] == "user" else (None, entry["content"]) for entry in history if entry["role"] in ["user", "assistant"]]
|
80 |
+
return "", formatted_history, history, interaction_count
|
81 |
+
|
82 |
if tokenizer is None or model is None:
|
83 |
raise ValueError("Tokenizer or model is not initialized.")
|
84 |
|
|
|
91 |
if messages[i-1].get("role") == messages[i].get("role"):
|
92 |
raise ValueError("Conversation roles must alternate user/assistant/user/assistant/...")
|
93 |
|
|
|
|
|
|
|
|
|
|
|
94 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
95 |
|
96 |
# Generate response using selected model
|