Spaces:
Sleeping
Sleeping
jonathanjordan21
commited on
Commit
•
4070db8
1
Parent(s):
0b69791
Update apis/chat_api.py
Browse files- apis/chat_api.py +11 -1
apis/chat_api.py
CHANGED
@@ -152,7 +152,7 @@ class ChatAPIApp:
|
|
152 |
description="(str) Prompt",
|
153 |
)
|
154 |
stream: bool = Field(
|
155 |
-
default=
|
156 |
description="(bool) Stream",
|
157 |
)
|
158 |
options: dict = Field(
|
@@ -223,6 +223,16 @@ class ChatAPIApp:
|
|
223 |
ping=2000,
|
224 |
ping_message_factory=lambda: ServerSentEvent(**{"comment": ""}),
|
225 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
return event_source_response
|
227 |
else:
|
228 |
data_response = streamer.chat_return_dict(stream_response)
|
|
|
152 |
description="(str) Prompt",
|
153 |
)
|
154 |
stream: bool = Field(
|
155 |
+
default=True,
|
156 |
description="(bool) Stream",
|
157 |
)
|
158 |
options: dict = Field(
|
|
|
223 |
ping=2000,
|
224 |
ping_message_factory=lambda: ServerSentEvent(**{"comment": ""}),
|
225 |
)
|
226 |
+
|
227 |
+
import json
|
228 |
+
event_source_response = json.loads(str(event_source_response).split('data: ')[1])
|
229 |
+
event_source_response = {
|
230 |
+
"model": event_source_response.get('model'),
|
231 |
+
"created_at": event_source_response.get('created_at'),
|
232 |
+
"response": event_source_response.get('choices')[-1].get('delta').get('content'),
|
233 |
+
"done": True if event_source_response.get('choices')[-1].get('finish_reason') != None else False,
|
234 |
+
}
|
235 |
+
|
236 |
return event_source_response
|
237 |
else:
|
238 |
data_response = streamer.chat_return_dict(stream_response)
|