| 4047 | ].join("\n"); |
| 4048 | |
| 4049 | const sendImg2ImgText = (text: string) => { |
| 4050 | const completionId = `chatcmpl-img2img-${Date.now()}`; |
| 4051 | const timestamp = Math.floor(Date.now() / 1000); |
| 4052 | if (isStreaming) { |
| 4053 | res.writeHead(200, { |
| 4054 | "Content-Type": "text/event-stream", |
| 4055 | "Cache-Control": "no-cache", |
| 4056 | Connection: "keep-alive", |
| 4057 | }); |
| 4058 | res.write( |
| 4059 | `data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/img2img", choices: [{ index: 0, delta: { role: "assistant", content: text }, finish_reason: null }] })}\n\n`, |
| 4060 | ); |
| 4061 | res.write( |
| 4062 | `data: ${JSON.stringify({ id: completionId, object: "chat.completion.chunk", created: timestamp, model: "clawrouter/img2img", choices: [{ index: 0, delta: {}, finish_reason: "stop" }] })}\n\n`, |
| 4063 | ); |
| 4064 | res.write("data: [DONE]\n\n"); |
| 4065 | res.end(); |
| 4066 | } else { |
| 4067 | res.writeHead(200, { "Content-Type": "application/json" }); |
| 4068 | res.end( |
| 4069 | JSON.stringify({ |
| 4070 | id: completionId, |
| 4071 | object: "chat.completion", |
| 4072 | created: timestamp, |
| 4073 | model: "clawrouter/img2img", |
| 4074 | choices: [ |
| 4075 | { |
| 4076 | index: 0, |
| 4077 | message: { role: "assistant", content: text }, |
| 4078 | finish_reason: "stop", |
| 4079 | }, |
| 4080 | ], |
| 4081 | usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 }, |
| 4082 | }), |
| 4083 | ); |
| 4084 | } |
| 4085 | }; |
| 4086 | |
| 4087 | if (!imagePath || !img2imgPrompt) { |
| 4088 | sendImg2ImgText(usageText); |