(path: string, content: string)
| 3 | import { getLastNPathParts } from "../util/uri"; |
| 4 | |
| 5 | export function parsePromptFile(path: string, content: string) { |
| 6 | let [preambleRaw, prompt] = content.split("\n---\n"); |
| 7 | if (prompt === undefined) { |
| 8 | prompt = preambleRaw; |
| 9 | preambleRaw = ""; |
| 10 | } |
| 11 | |
| 12 | const preamble = YAML.parse(preambleRaw) ?? {}; |
| 13 | const name = preamble.name ?? getLastNPathParts(path, 1).split(".prompt")[0]; |
| 14 | const description = preamble.description ?? name; |
| 15 | const version = preamble.version ?? 2; |
| 16 | |
| 17 | let systemMessage: string | undefined = undefined; |
| 18 | if (prompt.includes("<system>")) { |
| 19 | systemMessage = prompt.split("<system>")[1].split("</system>")[0].trim(); |
| 20 | prompt = prompt.split("</system>")[1].trim(); |
| 21 | } |
| 22 | |
| 23 | return { name, description, systemMessage, prompt, version }; |
| 24 | } |
no test coverage detected