({
pipe,
systemPrompt
}: {
pipe: Pipe;
systemPrompt: string;
})
| 11 | import type { Pipe } from 'types/pipe'; |
| 12 | |
| 13 | export function addJsonMode({ |
| 14 | pipe, |
| 15 | systemPrompt |
| 16 | }: { |
| 17 | pipe: Pipe; |
| 18 | systemPrompt: string; |
| 19 | }) { |
| 20 | // Return the system prompt if JSON mode is not enabled |
| 21 | if (!pipe?.json) return systemPrompt; |
| 22 | |
| 23 | const modelName = pipe.model.split(':')[1]; |
| 24 | // Return the system prompt if JSON mode is not supported by the current model |
| 25 | if (!jsonModeModels.includes(modelName)) return systemPrompt; |
| 26 | |
| 27 | const jsonModePrompt = getJsonPrompt(pipe); |
| 28 | |
| 29 | // Add JSON mode if enabled & supported by model |
| 30 | return `${systemPrompt}\n\n${jsonModePrompt}`; |
| 31 | } |
| 32 | |
| 33 | function getJsonPrompt(pipe: Pipe): string { |
| 34 | const jsonPrompt = |
no test coverage detected