Skip to content

Commit

Permalink
small change to newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-widder committed Jun 1, 2023
1 parent 8ca3266 commit e20e63b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def stream_with_data(body, headers, endpoint):
if line:
lineJson = json.loads(line.lstrip(b'data:').decode('utf-8'))
if 'error' in lineJson:
yield json.dumps(lineJson) + "<newline>"
yield json.dumps(lineJson).replace("\n", "\\n") + "\n"
response["id"] = lineJson["id"]
response["model"] = lineJson["model"]
response["created"] = lineJson["created"]
Expand All @@ -139,9 +139,9 @@ def stream_with_data(body, headers, endpoint):
if deltaText != "[DONE]":
response["choices"][0]["messages"][1]["content"] += deltaText

yield json.dumps(response) + "<newline>"
yield json.dumps(response).replace("\n", "\\n") + "\n"
except Exception as e:
yield json.dumps({"error": str(e)}) + "<newline>"
yield json.dumps({"error": str(e)}).replace("\n", "\\n") + "\n"


def conversation_with_data(request):
Expand All @@ -153,7 +153,7 @@ def conversation_with_data(request):
status_code = r.status_code
r = r.json()

return Response(json.dumps(r), status=status_code)
return Response(json.dumps(r).replace("\n", "\\n"), status=status_code)
else:
if request.method == "POST":
return Response(stream_with_data(body, headers, endpoint), mimetype='text/event-stream')
Expand All @@ -179,7 +179,7 @@ def stream_without_data(response):
}]
}]
}
yield json.dumps(response_obj) + "<newline>"
yield json.dumps(response_obj).replace("\n", "\\n") + "\n"


def conversation_without_data(request):
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const Chat = () => {
if (done) break;

var text = new TextDecoder("utf-8").decode(value);
const objects = text.split("<newline>");
const objects = text.split("\n");
objects.forEach((obj) => {
try {
runningText += obj;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Azure AI</title>
<script type="module" crossorigin src="/assets/index-e68f04f5.js"></script>
<script type="module" crossorigin src="/assets/index-618def07.js"></script>
<link rel="stylesheet" href="/assets/index-09fe54a5.css">
</head>
<body>
Expand Down

0 comments on commit e20e63b

Please sign in to comment.