(body, stream, config)
| 429 | } |
| 430 | |
| 431 | function 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 | |
| 460 | function anthropicMessagesToOpenAI(messages, system) { |
| 461 | const result = [] |
no test coverage detected