Niansuh commited on
Commit
8e53718
·
verified ·
1 Parent(s): 8a3edf7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -6
main.py CHANGED
@@ -202,9 +202,13 @@ async def chat_completions(request: ChatRequest):
202
  else:
203
  response_content += chunk.content
204
 
205
- # Clean up the response to get only the plain text content
206
- start = response_content.find('"content": "') + len('"content": "')
207
- end = response_content.find('"', start)
208
- clean_content = response_content[start:end].replace('\\n', '\n') # Handle newline characters
209
-
210
- return Response(content=clean_content.strip(), media_type="text/plain") # Return plain text
 
 
 
 
 
202
  else:
203
  response_content += chunk.content
204
 
205
+ # Clean up the response to extract the plain text content
206
+ clean_content = response_content.replace('\\n', '\n').strip()
207
+
208
+ return {
209
+ "id": str(uuid.uuid4()),
210
+ "object": "chat.completion",
211
+ "created": int(datetime.now().timestamp()),
212
+ "model": request.model,
213
+ "choices": [{"index": 0, "message": {"role": "assistant", "content": clean_content}, "finish_reason": "stop"}]
214
+ }