jonathanjordan21 commited on
Commit
6fe3f86
1 Parent(s): a673ddb

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +14 -12
apis/chat_api.py CHANGED
@@ -217,24 +217,26 @@ class ChatAPIApp:
217
  )
218
 
219
  if item.stream:
 
 
220
  event_source_response = EventSourceResponse(
221
- streamer.chat_return_generator(stream_response),
222
  media_type="text/event-stream",
223
  ping=2000,
224
  ping_message_factory=lambda: ServerSentEvent(**{"comment": ""}),
225
  )
226
 
227
- import json
228
- print(event_source_response, "EVENT RESPONSE FIRST")
229
- event_source_response = json.loads(str(event_source_response).split('data: ')[-1])
230
- print(event_source_response, "EVENT RESPONSE SECOND")
231
- event_source_response = {
232
- "model": event_source_response.get('model'),
233
- "created_at": event_source_response.get('created_at'),
234
- "response": event_source_response.get('choices')[-1].get('delta').get('content'),
235
- "done": True if event_source_response.get('choices')[-1].get('finish_reason') != None else False,
236
- }
237
- print(event_source_response, "EVENT RESPONSE THIRD")
238
 
239
  return event_source_response
240
  else:
 
217
  )
218
 
219
  if item.stream:
220
+ stream_out = streamer.chat_return_generator(stream_response)
221
+ print(stream_out, type(stream_out))
222
  event_source_response = EventSourceResponse(
223
+ stream_out,
224
  media_type="text/event-stream",
225
  ping=2000,
226
  ping_message_factory=lambda: ServerSentEvent(**{"comment": ""}),
227
  )
228
 
229
+ # import json
230
+ # print(event_source_response, "EVENT RESPONSE FIRST")
231
+ # event_source_response = json.loads(str(event_source_response).split('data: ')[-1])
232
+ # print(event_source_response, "EVENT RESPONSE SECOND")
233
+ # event_source_response = {
234
+ # "model": event_source_response.get('model'),
235
+ # "created_at": event_source_response.get('created_at'),
236
+ # "response": event_source_response.get('choices')[-1].get('delta').get('content'),
237
+ # "done": True if event_source_response.get('choices')[-1].get('finish_reason') != None else False,
238
+ # }
239
+ # print(event_source_response, "EVENT RESPONSE THIRD")
240
 
241
  return event_source_response
242
  else: