matthoffner commited on
Commit
c796178
1 Parent(s): e177246

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -0
main.py CHANGED
@@ -59,6 +59,22 @@ async def completion(request: ChatCompletionRequestV0, response_mode=None):
59
  response = llm(request.prompt)
60
  return response
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  @app.post("/v1/chat/completions")
63
  async def chat(request: ChatCompletionRequest):
64
  combined_messages = ' '.join([message.content for message in request.messages])
 
59
  response = llm(request.prompt)
60
  return response
61
 
62
+ async def generate_response(chat_chunks, llm):
63
+ for chat_chunk in chat_chunks:
64
+ response = {
65
+ 'choices': [
66
+ {
67
+ 'message': {
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 f"data: {json.dumps(response)}\n\n"
76
+ yield "event: done\ndata: {}\n\n"
77
+
78
  @app.post("/v1/chat/completions")
79
  async def chat(request: ChatCompletionRequest):
80
  combined_messages = ' '.join([message.content for message in request.messages])