matthoffner commited on
Commit
dcac576
1 Parent(s): 7904b82

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -3
main.py CHANGED
@@ -68,11 +68,11 @@ async def generate_response(chat_chunks, llm):
68
  'role': 'system',
69
  'content': llm.detokenize(chat_chunk)
70
  },
71
- 'finish_reason': 'stop' if chat_chunk == "<|end|>" else 'unknown'
72
  }
73
  ]
74
  }
75
- yield f"data: {json.dumps(response)}\n\n"
76
  yield dict(data="[DONE]")
77
 
78
  @app.post("/v1/chat/completions")
@@ -85,7 +85,7 @@ async def chat(request: ChatCompletionRequest):
85
  except Exception as e:
86
  raise HTTPException(status_code=500, detail=str(e))
87
 
88
- return StreamingResponse(generate_response(chat_chunks, llm), media_type="text/event-stream")
89
 
90
  async def stream_response(tokens: Any) -> None:
91
  try:
 
68
  'role': 'system',
69
  'content': llm.detokenize(chat_chunk)
70
  },
71
+ 'finish_reason': 'stop' if llm.is_eos_token(chat_chunk) else 'unknown'
72
  }
73
  ]
74
  }
75
+ yield dict(data=json.dumps(response))
76
  yield dict(data="[DONE]")
77
 
78
  @app.post("/v1/chat/completions")
 
85
  except Exception as e:
86
  raise HTTPException(status_code=500, detail=str(e))
87
 
88
+ return EventSourceResponse(generate_response(chat_chunks, llm))
89
 
90
  async def stream_response(tokens: Any) -> None:
91
  try: