Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,13 +16,17 @@ Use clear sections, shots, and visual descriptions when possible.
|
|
| 16 |
# Chat Function
|
| 17 |
# -------------------------
|
| 18 |
def respond(message, history, model, temperature, max_tokens):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
messages.append({"role": "assistant", "content": h[1]})
|
| 25 |
|
|
|
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
| 28 |
try:
|
|
@@ -32,10 +36,18 @@ def respond(message, history, model, temperature, max_tokens):
|
|
| 32 |
temperature=temperature,
|
| 33 |
max_completion_tokens=max_tokens,
|
| 34 |
)
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
# -------------------------
|
| 41 |
# Custom CSS
|
|
|
|
| 16 |
# Chat Function
|
| 17 |
# -------------------------
|
| 18 |
def respond(message, history, model, temperature, max_tokens):
|
| 19 |
+
if not message or message.strip() == "":
|
| 20 |
+
return history
|
| 21 |
+
|
| 22 |
+
# Start conversation with system prompt
|
| 23 |
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 24 |
|
| 25 |
+
# Add previous chat history (already dict-based)
|
| 26 |
+
for msg in history:
|
| 27 |
+
messages.append(msg)
|
|
|
|
| 28 |
|
| 29 |
+
# Add new user message
|
| 30 |
messages.append({"role": "user", "content": message})
|
| 31 |
|
| 32 |
try:
|
|
|
|
| 36 |
temperature=temperature,
|
| 37 |
max_completion_tokens=max_tokens,
|
| 38 |
)
|
| 39 |
+
|
| 40 |
+
assistant_reply = response.choices[0].message.content
|
| 41 |
+
|
| 42 |
+
# Update history in NEW format
|
| 43 |
+
history.append({"role": "user", "content": message})
|
| 44 |
+
history.append({"role": "assistant", "content": assistant_reply})
|
| 45 |
+
|
| 46 |
+
return history
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
+
history.append({"role": "assistant", "content": f"❌ Error: {str(e)}"})
|
| 50 |
+
return history
|
| 51 |
|
| 52 |
# -------------------------
|
| 53 |
# Custom CSS
|