Update app.py
Browse files
app.py
CHANGED
@@ -109,22 +109,14 @@ def convert_messages_to_tuples(history: List[Dict[str, str]]) -> List[Tuple[str,
|
|
109 |
This robust version correctly handles histories that start with an assistant message.
|
110 |
"""
|
111 |
tuple_history = []
|
112 |
-
#
|
113 |
-
start_index = 0
|
114 |
for i, msg in enumerate(history):
|
115 |
if msg['role'] == 'user':
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
for i in range(start_index, len(history)):
|
122 |
-
if history[i]['role'] == 'user':
|
123 |
-
user_msg_content = history[i]['content']
|
124 |
-
elif history[i]['role'] == 'assistant' and user_msg_content is not None:
|
125 |
-
tuple_history.append((user_msg_content, history[i]['content']))
|
126 |
-
user_msg_content = None # Reset to find the next pair
|
127 |
-
|
128 |
return tuple_history
|
129 |
|
130 |
# --- Gradio UI ---
|
|
|
109 |
This robust version correctly handles histories that start with an assistant message.
|
110 |
"""
|
111 |
tuple_history = []
|
112 |
+
# Iterate through the history to find user messages
|
|
|
113 |
for i, msg in enumerate(history):
|
114 |
if msg['role'] == 'user':
|
115 |
+
# Once a user message is found, check if the next message is from the assistant
|
116 |
+
if i + 1 < len(history) and history[i+1]['role'] == 'assistant':
|
117 |
+
user_content = msg['content']
|
118 |
+
assistant_content = history[i+1]['content']
|
119 |
+
tuple_history.append((user_content, assistant_content))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
return tuple_history
|
121 |
|
122 |
# --- Gradio UI ---
|