Update networks/message_streamer.py
Browse files
networks/message_streamer.py
CHANGED
|
@@ -34,16 +34,16 @@ class MessageStreamer:
|
|
| 34 |
line = line.decode("utf-8")
|
| 35 |
line = re.sub(r"data:\s*", "", line)
|
| 36 |
data = json.loads(line)
|
| 37 |
-
|
| 38 |
-
return
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
print(f"An error occurred: {e}")
|
| 44 |
return None
|
| 45 |
|
| 46 |
-
|
| 47 |
def chat_response(
|
| 48 |
self,
|
| 49 |
prompt: str = None,
|
|
|
|
| 34 |
line = line.decode("utf-8")
|
| 35 |
line = re.sub(r"data:\s*", "", line)
|
| 36 |
data = json.loads(line)
|
| 37 |
+
|
| 38 |
+
# Check if 'token' key exists and return its 'text' value
|
| 39 |
+
if 'token' in data:
|
| 40 |
+
return data['token'].get('text', '') # Return an empty string if 'text' is not found
|
| 41 |
+
else:
|
| 42 |
+
return None # Return None if 'token' key is not present
|
| 43 |
except Exception as e:
|
| 44 |
print(f"An error occurred: {e}")
|
| 45 |
return None
|
| 46 |
|
|
|
|
| 47 |
def chat_response(
|
| 48 |
self,
|
| 49 |
prompt: str = None,
|