Update app.py
Browse files
app.py
CHANGED
@@ -132,16 +132,21 @@ Please provide detailed analysis from these perspectives:
|
|
132 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
133 |
|
134 |
# Convert history to message format
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
140 |
messages.append({"role": "user", "content": message})
|
141 |
|
142 |
try:
|
143 |
client = get_client(model_name)
|
144 |
partial_message = ""
|
|
|
145 |
|
146 |
for msg in client.chat_completion(
|
147 |
messages,
|
@@ -153,18 +158,19 @@ Please provide detailed analysis from these perspectives:
|
|
153 |
token = msg.choices[0].delta.get('content', None)
|
154 |
if token:
|
155 |
partial_message += token
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
formatted_history.append({"role": "assistant", "content": h[1]})
|
162 |
-
yield "", formatted_history
|
163 |
|
164 |
except Exception as e:
|
165 |
error_msg = f"❌ Inference error: {str(e)}"
|
166 |
-
|
167 |
-
|
|
|
|
|
|
|
168 |
|
169 |
css = """
|
170 |
footer {visibility: hidden}
|
|
|
132 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
133 |
|
134 |
# Convert history to message format
|
135 |
+
if history is not None:
|
136 |
+
for item in history:
|
137 |
+
if isinstance(item, dict):
|
138 |
+
messages.append(item)
|
139 |
+
elif isinstance(item, (list, tuple)) and len(item) == 2:
|
140 |
+
messages.append({"role": "user", "content": item[0]})
|
141 |
+
if item[1]:
|
142 |
+
messages.append({"role": "assistant", "content": item[1]})
|
143 |
+
|
144 |
messages.append({"role": "user", "content": message})
|
145 |
|
146 |
try:
|
147 |
client = get_client(model_name)
|
148 |
partial_message = ""
|
149 |
+
current_history = []
|
150 |
|
151 |
for msg in client.chat_completion(
|
152 |
messages,
|
|
|
158 |
token = msg.choices[0].delta.get('content', None)
|
159 |
if token:
|
160 |
partial_message += token
|
161 |
+
current_history = [
|
162 |
+
{"role": "user", "content": message},
|
163 |
+
{"role": "assistant", "content": partial_message}
|
164 |
+
]
|
165 |
+
yield "", current_history
|
|
|
|
|
166 |
|
167 |
except Exception as e:
|
168 |
error_msg = f"❌ Inference error: {str(e)}"
|
169 |
+
error_history = [
|
170 |
+
{"role": "user", "content": message},
|
171 |
+
{"role": "assistant", "content": error_msg}
|
172 |
+
]
|
173 |
+
yield "", error_history
|
174 |
|
175 |
css = """
|
176 |
footer {visibility: hidden}
|