@genkit-ai/dotprompt
Version:
Genkit AI framework `.prompt` file format and management library.
1 lines • 3.27 kB
Source Map (JSON)
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Registry } from '@genkit-ai/core/registry';\nimport { readFileSync } from 'fs';\nimport { basename } from 'path';\nimport {\n defineDotprompt,\n Dotprompt,\n DotpromptRef,\n type PromptGenerateOptions,\n} from './prompt.js';\nimport { loadPromptFolder, lookupPrompt } from './registry.js';\n\nexport { type PromptMetadata } from './metadata.js';\nexport { defineHelper, definePartial } from './template.js';\nexport {\n defineDotprompt,\n Dotprompt,\n loadPromptFolder,\n type PromptGenerateOptions,\n};\n\nexport interface DotpromptPluginOptions {\n // Directory to look for .prompt files.\n //\n // Note: This directory will be searched recursively, and any sub-directory\n // paths will be included in the prompt name. E.g. - if a prompt file is\n // located at `<dir>/foo/bar.prompt`, the prompt name will be `foo-bar`.\n dir: string;\n}\n\nexport async function prompt<Variables = unknown>(\n registry: Registry,\n name: string,\n options?: { variant?: string; dir?: string }\n): Promise<Dotprompt<Variables>> {\n return (await lookupPrompt(\n registry,\n name,\n options?.variant,\n options?.dir ?? './prompts'\n )) as Dotprompt<Variables>;\n}\n\nexport function promptRef<Variables = unknown>(\n name: string,\n options?: { variant?: string; dir?: string }\n): DotpromptRef<Variables> {\n return new DotpromptRef(name, options);\n}\n\nexport function loadPromptFile(registry: Registry, path: string): Dotprompt {\n return Dotprompt.parse(\n registry,\n basename(path).split('.')[0],\n readFileSync(path, 'utf-8')\n );\n}\n\nexport async function loadPromptUrl(\n registry: Registry,\n\n name: string,\n url: string\n): Promise<Dotprompt> {\n const fetch = (await import('node-fetch')).default;\n const response = await fetch(url);\n const text = await response.text();\n return Dotprompt.parse(registry, name, text);\n}\n"],"mappings":";;;AAiBA,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,kBAAkB,oBAAoB;AAG/C,SAAS,cAAc,qBAAqB;AAiB5C,SAAsB,OACpB,UACA,MACA,SAC+B;AAAA;AAjDjC;AAkDE,WAAQ,MAAM;AAAA,MACZ;AAAA,MACA;AAAA,MACA,mCAAS;AAAA,OACT,wCAAS,QAAT,YAAgB;AAAA,IAClB;AAAA,EACF;AAAA;AAEO,SAAS,UACd,MACA,SACyB;AACzB,SAAO,IAAI,aAAa,MAAM,OAAO;AACvC;AAEO,SAAS,eAAe,UAAoB,MAAyB;AAC1E,SAAO,UAAU;AAAA,IACf;AAAA,IACA,SAAS,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,IAC3B,aAAa,MAAM,OAAO;AAAA,EAC5B;AACF;AAEA,SAAsB,cACpB,UAEA,MACA,KACoB;AAAA;AACpB,UAAM,SAAS,MAAM,OAAO,YAAY,GAAG;AAC3C,UAAM,WAAW,MAAM,MAAM,GAAG;AAChC,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO,UAAU,MAAM,UAAU,MAAM,IAAI;AAAA,EAC7C;AAAA;","names":[]}