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

Function anthropicToOpenAI

tools/model-gateway/server.mjs:431–458  ·  view source on GitHub ↗
(body, stream, config)

Source from the content-addressed store, hash-verified

429}
430
431function anthropicToOpenAI(body, stream, config) {
432 const messages = anthropicMessagesToOpenAI(body.messages ?? [], body.system)
433 const tools = Array.isArray(body.tools)
434 ? body.tools.map(tool => ({
435 type: 'function',
436 function: {
437 name: tool.name,
438 description: tool.description || '',
439 parameters:
440 tool.input_schema || {
441 type: 'object',
442 properties: {},
443 },
444 },
445 }))
446 : undefined
447
448 return {
449 model: config.upstreamModel || body.model,
450 messages,
451 tools,
452 tool_choice: mapToolChoice(body.tool_choice),
453 temperature: body.temperature,
454 max_tokens: Math.min(body.max_tokens || 4096, 8192),
455 stream,
456 stream_options: stream ? { include_usage: true } : undefined,
457 }
458}
459
460function anthropicMessagesToOpenAI(messages, system) {
461 const result = []

Callers 2

handleNonStreamFunction · 0.85
handleStreamFunction · 0.85

Calls 2

mapToolChoiceFunction · 0.85

Tested by

no test coverage detected