Skip to content

Commit

Permalink
fix(claude): adapt the gpt-like streaming response format
Browse files Browse the repository at this point in the history
  • Loading branch information
UNICKCHENG committed Jul 20, 2023
1 parent d3166f1 commit 8f92171
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,29 @@ export async function iteratorToStream(response: any) {
}

const generateStreamResponseStart = (task_id: string) => {
return JSON.stringify({
return "data: " + JSON.stringify({
"id": task_id,
"object": "chat.completion.chunk", "created": Date.parse(new Date().toString()),
"model": "claude-v2",
"choices": [{ "delta": { "role": "assistant" }, "index": 0, "finish_reason": null }]
}) + "\n";
"choices": [{ "index": 0, "delta": { "role": "assistant", "content": "" }, "finish_reason": null }]
}) + "\n\n";
}

const generateStreamResponse = (content: string, task_id: string) => {
return JSON.stringify({
return "data: " + JSON.stringify({
"id": task_id,
"object": "chat.completion.chunk",
"created": Date.parse(new Date().toString()),
"model": "claude-v2",
"choices": [{ "delta": { "content": content }, "index": 0, "finish_reason": null }]
}) + "\n";
}) + "\n\n";
}

const generateStreamResponseStop = (task_id: string) => {
return JSON.stringify({
return "data: " + JSON.stringify({
"id": task_id,
"object": "chat.completion.chunk", "created": Date.parse(new Date().toString()),
"model": "chatglm-6b",
"choices": [{ "delta": {}, "index": 0, "finish_reason": "stop" }]
}) + "\n";
}) + "\n\n";
}

0 comments on commit 8f92171

Please sign in to comment.