MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / handleNonStream

Function handleNonStream

tools/model-gateway/server.mjs:226–248  ·  view source on GitHub ↗
(body, res, config)

Source from the content-addressed store, hash-verified

224}
225
226async 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
250async function handleStream(body, res, config) {
251 const upstreamBody = anthropicToOpenAI(body, true, config)

Callers 1

startGatewayServerFunction · 0.85

Calls 7

anthropicToOpenAIFunction · 0.85
buildUpstreamHeadersFunction · 0.85
textMethod · 0.80
joinUrlFunction · 0.70
writeJsonFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected