(body, res, config)
| 224 | } |
| 225 | |
| 226 | async function handleNonStream(body, res, config) { |
| 227 | const upstreamBody = anthropicToOpenAI(body, false, config) |
| 228 | const upstreamResponse = await fetch( |
| 229 | joinUrl(config.upstreamBaseUrl, config.upstreamChatPath), |
| 230 | { |
| 231 | method: 'POST', |
| 232 | headers: buildUpstreamHeaders(config), |
| 233 | body: JSON.stringify(upstreamBody), |
| 234 | }, |
| 235 | ) |
| 236 | |
| 237 | const text = await upstreamResponse.text() |
| 238 | if (!upstreamResponse.ok) { |
| 239 | res.statusCode = upstreamResponse.status |
| 240 | res.setHeader('content-type', 'application/json') |
| 241 | res.end(text) |
| 242 | return |
| 243 | } |
| 244 | |
| 245 | const payload = JSON.parse(text) |
| 246 | const anthropicMessage = openAINonStreamToAnthropic(body, payload) |
| 247 | writeJson(res, 200, anthropicMessage) |
| 248 | } |
| 249 | |
| 250 | async function handleStream(body, res, config) { |
| 251 | const upstreamBody = anthropicToOpenAI(body, true, config) |
no test coverage detected