(params: {
body: ChatCompletionRequestBody
originalModel: string
fetch: typeof globalThis.fetch
})
| 90 | } |
| 91 | |
| 92 | function createMoonshotRequest(params: { |
| 93 | body: ChatCompletionRequestBody |
| 94 | originalModel: string |
| 95 | fetch: typeof globalThis.fetch |
| 96 | }) { |
| 97 | const { body, originalModel, fetch } = params |
| 98 | const moonshotBody = buildMoonshotRequestBody(body, originalModel) |
| 99 | |
| 100 | return fetch(`${MOONSHOT_BASE_URL}/chat/completions`, { |
| 101 | method: 'POST', |
| 102 | headers: { |
| 103 | Authorization: `Bearer ${getMoonshotApiKey()}`, |
| 104 | 'Content-Type': 'application/json', |
| 105 | }, |
| 106 | body: JSON.stringify(moonshotBody), |
| 107 | // @ts-expect-error - dispatcher is a valid undici option not in fetch types |
| 108 | dispatcher: moonshotAgent, |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | export function buildMoonshotRequestBody( |
| 113 | body: ChatCompletionRequestBody, |
no test coverage detected