(params: {
body: ChatCompletionRequestBody
originalModel: string
fetch: typeof globalThis.fetch
modelIdOverride?: string
sessionId: string
})
| 91 | } |
| 92 | |
| 93 | function createFireworksRequest(params: { |
| 94 | body: ChatCompletionRequestBody |
| 95 | originalModel: string |
| 96 | fetch: typeof globalThis.fetch |
| 97 | modelIdOverride?: string |
| 98 | sessionId: string |
| 99 | }) { |
| 100 | const { body, originalModel, fetch, modelIdOverride, sessionId } = params |
| 101 | const fireworksBody: Record<string, unknown> = { |
| 102 | ...body, |
| 103 | model: modelIdOverride ?? getFireworksModelId(originalModel), |
| 104 | } |
| 105 | |
| 106 | // Transform OpenRouter-style `reasoning` object into Fireworks' `reasoning_effort`. |
| 107 | // Unlike OpenAI, Fireworks supports reasoning_effort together with function tools |
| 108 | // (e.g. GLM-4.5/5.1 are designed for interleaved reasoning + tool use). |
| 109 | if (fireworksBody.reasoning && typeof fireworksBody.reasoning === 'object') { |
| 110 | const reasoning = fireworksBody.reasoning as { |
| 111 | enabled?: boolean |
| 112 | effort?: 'high' | 'medium' | 'low' |
| 113 | } |
| 114 | if (reasoning.enabled ?? true) { |
| 115 | fireworksBody.reasoning_effort = reasoning.effort ?? 'medium' |
| 116 | } |
| 117 | } |
| 118 | delete fireworksBody.reasoning |
| 119 | |
| 120 | // Strip OpenRouter-specific / internal fields |
| 121 | delete fireworksBody.provider |
| 122 | delete fireworksBody.transforms |
| 123 | delete fireworksBody.codebuff_metadata |
| 124 | delete fireworksBody.usage |
| 125 | |
| 126 | // Add strict: true to tool definitions to prevent hallucinated tool call formats |
| 127 | if (Array.isArray(fireworksBody.tools)) { |
| 128 | fireworksBody.tools = ( |
| 129 | fireworksBody.tools as Array<Record<string, unknown>> |
| 130 | ).map((tool) => { |
| 131 | if ( |
| 132 | tool.type === 'function' && |
| 133 | typeof tool.function === 'object' && |
| 134 | tool.function !== null |
| 135 | ) { |
| 136 | return { |
| 137 | ...tool, |
| 138 | function: { |
| 139 | ...(tool.function as Record<string, unknown>), |
| 140 | strict: true, |
| 141 | }, |
| 142 | } |
| 143 | } |
| 144 | return tool |
| 145 | }) |
| 146 | } |
| 147 | |
| 148 | // For streaming, request usage in the final chunk |
| 149 | if (fireworksBody.stream) { |
| 150 | fireworksBody.stream_options = { include_usage: true } |
no test coverage detected