Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,13 +51,17 @@ async def respond(
|
|
| 51 |
chunk_data = chunk.decode('utf-8')
|
| 52 |
response_json = json.loads(chunk_data)
|
| 53 |
if "choices" in response_json:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
content = delta["content"]
|
| 57 |
-
yield content
|
| 58 |
except json.JSONDecodeError:
|
| 59 |
-
#
|
| 60 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
theme = "Nymbo/Nymbo_Theme"
|
| 63 |
|
|
|
|
| 51 |
chunk_data = chunk.decode('utf-8')
|
| 52 |
response_json = json.loads(chunk_data)
|
| 53 |
if "choices" in response_json:
|
| 54 |
+
content = response_json["choices"][0]["message"]["content"]
|
| 55 |
+
yield content
|
|
|
|
|
|
|
| 56 |
except json.JSONDecodeError:
|
| 57 |
+
# Log the error or handle it appropriately
|
| 58 |
+
pass
|
| 59 |
+
except StopAsyncIteration:
|
| 60 |
+
# Handle the case where the stream is prematurely terminated
|
| 61 |
+
pass
|
| 62 |
+
finally:
|
| 63 |
+
# Ensure that the generator is properly closed
|
| 64 |
+
yield "Stream ended"
|
| 65 |
|
| 66 |
theme = "Nymbo/Nymbo_Theme"
|
| 67 |
|