Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,10 @@ BANDAR_AI_PROMPT = (
|
|
| 39 |
def initialize_history():
|
| 40 |
return [{"role": "system", "content": BANDAR_AI_PROMPT}]
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# ✅ Chat Response Function
|
| 43 |
def respond(message, history):
|
| 44 |
history.append({"role": "user", "content": message})
|
|
@@ -48,7 +52,7 @@ def respond(message, history):
|
|
| 48 |
token = msg.choices[0].delta.content
|
| 49 |
if token:
|
| 50 |
response += token
|
| 51 |
-
yield
|
| 52 |
|
| 53 |
history.append({"role": "assistant", "content": response})
|
| 54 |
|
|
|
|
| 39 |
def initialize_history():
|
| 40 |
return [{"role": "system", "content": BANDAR_AI_PROMPT}]
|
| 41 |
|
| 42 |
+
# ✅ Convert history to Gradio-compatible format (list of tuples)
|
| 43 |
+
def format_history(history):
|
| 44 |
+
return [(history[i]["content"], history[i + 1]["content"]) for i in range(0, len(history) - 1, 2) if history[i]["role"] == "user"]
|
| 45 |
+
|
| 46 |
# ✅ Chat Response Function
|
| 47 |
def respond(message, history):
|
| 48 |
history.append({"role": "user", "content": message})
|
|
|
|
| 52 |
token = msg.choices[0].delta.content
|
| 53 |
if token:
|
| 54 |
response += token
|
| 55 |
+
yield format_history(history) + [(message, response)] # Corrected Output Format
|
| 56 |
|
| 57 |
history.append({"role": "assistant", "content": response})
|
| 58 |
|