(c: any)
| 114 | |
| 115 | // Main endpoint handler |
| 116 | const handleRun = async (c: any) => { |
| 117 | try { |
| 118 | const body = await c.req.json(); |
| 119 | |
| 120 | const llmKey = (body.llmApiKey as string) || ''; |
| 121 | const hiddenChars = new Array(45).fill('*').join(''); |
| 122 | const redactedKey = llmKey.length |
| 123 | ? llmKey.slice(0, 8) + hiddenChars |
| 124 | : ''; |
| 125 | |
| 126 | const logData = { ...body, llmApiKey: redactedKey }; |
| 127 | logger('pipe.request', logData, 'Pipe Request Body'); |
| 128 | |
| 129 | const validatedBody = validateRequestBody(body); |
| 130 | |
| 131 | const { pipe, messages, llmApiKey, stream, variables } = validatedBody; |
| 132 | const model = pipe.model as PipeModelT; |
| 133 | |
| 134 | const rawLlmResponse = await callLLM({ |
| 135 | pipe: { |
| 136 | ...pipe, |
| 137 | model |
| 138 | }, |
| 139 | messages, |
| 140 | llmApiKey, |
| 141 | stream, |
| 142 | variables, |
| 143 | paramsTools: validatedBody.tools |
| 144 | }); |
| 145 | |
| 146 | return processLlmResponse(c, validatedBody, rawLlmResponse); |
| 147 | } catch (error: unknown) { |
| 148 | return handleGenerateError(c, error); |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | // Register the endpoint |
| 153 | export const registerV1PipesRun = (app: Hono) => { |
nothing calls this directly
no test coverage detected