Spaces:
Runtime error
Runtime error
if content:
Browse fileshistory[-1][1] += content
history = history[-MAX_HISTORY_LENGTH:]
yield history
app.py
CHANGED
|
@@ -61,17 +61,8 @@ def openai_stream(history, openai_key, chat_model, use_key):
|
|
| 61 |
):
|
| 62 |
content = chunk["choices"][0].get("delta", {}).get("content")
|
| 63 |
if content:
|
| 64 |
-
|
| 65 |
-
if history:
|
| 66 |
-
history[-1][1] += content # Update the last response with the new content.
|
| 67 |
-
else:
|
| 68 |
-
# Handle the case where you might need to add a new message-response pair.
|
| 69 |
-
# This is just a generic example. You might need a different approach based on your exact requirements.
|
| 70 |
-
history.append((messages[-1]["content"], content))
|
| 71 |
-
|
| 72 |
-
# Ensure history keeps only the last 10 message-response pairs.
|
| 73 |
history = history[-MAX_HISTORY_LENGTH:]
|
| 74 |
-
|
| 75 |
yield history
|
| 76 |
|
| 77 |
|
|
|
|
| 61 |
):
|
| 62 |
content = chunk["choices"][0].get("delta", {}).get("content")
|
| 63 |
if content:
|
| 64 |
+
history[-1][1] += content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
history = history[-MAX_HISTORY_LENGTH:]
|
|
|
|
| 66 |
yield history
|
| 67 |
|
| 68 |
|