Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,12 +104,27 @@ def analyze_and_update_single_repo(repo_id: str) -> Tuple[str, str, pd.DataFrame
|
|
| 104 |
|
| 105 |
# --- NEW: Helper for Chat History Conversion ---
|
| 106 |
def convert_messages_to_tuples(history: List[Dict[str, str]]) -> List[Tuple[str, str]]:
|
| 107 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 108 |
tuple_history = []
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
return tuple_history
|
| 114 |
|
| 115 |
# --- Gradio UI ---
|
|
|
|
| 104 |
|
| 105 |
# --- NEW: Helper for Chat History Conversion ---
|
| 106 |
def convert_messages_to_tuples(history: List[Dict[str, str]]) -> List[Tuple[str, str]]:
|
| 107 |
+
"""
|
| 108 |
+
Converts Gradio's 'messages' format to the old 'tuple' format for compatibility.
|
| 109 |
+
This robust version correctly handles histories that start with an assistant message.
|
| 110 |
+
"""
|
| 111 |
tuple_history = []
|
| 112 |
+
# Find the start of the actual conversation (the first user message)
|
| 113 |
+
start_index = 0
|
| 114 |
+
for i, msg in enumerate(history):
|
| 115 |
+
if msg['role'] == 'user':
|
| 116 |
+
start_index = i
|
| 117 |
+
break
|
| 118 |
+
|
| 119 |
+
# Group the rest of the messages into (user, assistant) pairs
|
| 120 |
+
user_msg_content = None
|
| 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 ---
|