( payload: CursorRequestPayload, accessToken: string, modelId: string, convKey: string, )
| 1415 | } |
| 1416 | |
| 1417 | async function handleNonStreamingResponse( |
| 1418 | payload: CursorRequestPayload, |
| 1419 | accessToken: string, |
| 1420 | modelId: string, |
| 1421 | convKey: string, |
| 1422 | ): Promise<Response> { |
| 1423 | const completionId = `chatcmpl-${crypto.randomUUID().replace(/-/g, "").slice(0, 28)}`; |
| 1424 | const created = Math.floor(Date.now() / 1000); |
| 1425 | const { text, usage } = await collectFullResponse(payload, accessToken, convKey); |
| 1426 | |
| 1427 | return new Response( |
| 1428 | JSON.stringify({ |
| 1429 | id: completionId, |
| 1430 | object: "chat.completion", |
| 1431 | created, |
| 1432 | model: modelId, |
| 1433 | choices: [ |
| 1434 | { |
| 1435 | index: 0, |
| 1436 | message: { role: "assistant", content: text }, |
| 1437 | finish_reason: "stop", |
| 1438 | }, |
| 1439 | ], |
| 1440 | usage, |
| 1441 | }), |
| 1442 | { headers: { "Content-Type": "application/json" } }, |
| 1443 | ); |
| 1444 | } |
| 1445 | |
| 1446 | interface CollectedResponse { |
| 1447 | text: string; |
no test coverage detected