Niansuh commited on
Commit
38264bf
·
verified ·
1 Parent(s): 38d8ad5

Update api/utils.py

Browse files
Files changed (1) hide show
  1. api/utils.py +4 -1
api/utils.py CHANGED
@@ -37,6 +37,8 @@ def message_to_dict(message):
37
  def create_chat_completion_data(
38
  content: str, model: str, timestamp: int, finish_reason: Optional[str] = None
39
  ) -> Dict[str, Any]:
 
 
40
  return {
41
  "id": f"chatcmpl-{uuid.uuid4()}",
42
  "object": "chat.completion.chunk",
@@ -45,13 +47,14 @@ def create_chat_completion_data(
45
  "choices": [
46
  {
47
  "index": 0,
48
- "delta": {"content": content, "role": "assistant"},
49
  "finish_reason": finish_reason,
50
  }
51
  ],
52
  "usage": None,
53
  }
54
 
 
55
  async def process_streaming_response(request: ChatRequest):
56
  json_data = {
57
  "messages": [message_to_dict(msg) for msg in request.messages],
 
37
  def create_chat_completion_data(
38
  content: str, model: str, timestamp: int, finish_reason: Optional[str] = None
39
  ) -> Dict[str, Any]:
40
+ # Remove extra blank lines
41
+ cleaned_content = '\n'.join([line.rstrip() for line in content.splitlines() if line.strip() != ''])
42
  return {
43
  "id": f"chatcmpl-{uuid.uuid4()}",
44
  "object": "chat.completion.chunk",
 
47
  "choices": [
48
  {
49
  "index": 0,
50
+ "delta": {"content": cleaned_content, "role": "assistant"},
51
  "finish_reason": finish_reason,
52
  }
53
  ],
54
  "usage": None,
55
  }
56
 
57
+
58
  async def process_streaming_response(request: ChatRequest):
59
  json_data = {
60
  "messages": [message_to_dict(msg) for msg in request.messages],