{"version":3,"sources":["../../src/metrics/helper.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 { Dotprompt, type PromptFunction } from 'dotprompt';\nimport { readFileSync } from 'fs';\n\n/** Helper function to get current directory, isolated in a separate file to work with ESM */\nexport function getDirName() {\n  return __dirname;\n}\n\nconst dp = new Dotprompt();\n\nexport function loadPromptFile(path: string): Promise<PromptFunction> {\n  return dp.compile(dp.parse(readFileSync(path, 'utf8')));\n}\n\nexport async function renderText(\n  prompt: PromptFunction,\n  input\n): Promise<string> {\n  const renderred = await prompt({\n    input,\n  });\n  return renderred.messages\n    .map((m) => m.content.map((c) => c.text).join())\n    .join();\n}\n"],"mappings":"AAgBA,SAAS,iBAAsC;AAC/C,SAAS,oBAAoB;AAGtB,SAAS,aAAa;AAC3B,SAAO;AACT;AAEA,MAAM,KAAK,IAAI,UAAU;AAElB,SAAS,eAAe,MAAuC;AACpE,SAAO,GAAG,QAAQ,GAAG,MAAM,aAAa,MAAM,MAAM,CAAC,CAAC;AACxD;AAEA,eAAsB,WACpB,QACA,OACiB;AACjB,QAAM,YAAY,MAAM,OAAO;AAAA,IAC7B;AAAA,EACF,CAAC;AACD,SAAO,UAAU,SACd,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,EAC9C,KAAK;AACV;","names":[]}