{"version":3,"sources":["../src/model.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 type { LLMResult } from '@langchain/core/outputs';\nimport type { Genkit, ModelArgument } from 'genkit';\nimport { logger } from 'genkit/logging';\nimport type { ModelAction } from 'genkit/model';\nimport type { CallbackManagerForLLMRun } from 'langchain/callbacks';\nimport { BaseLLM } from 'langchain/llms/base';\n\nexport function genkitModel(\n  ai: Genkit,\n  model: ModelArgument,\n  config?: any\n): BaseLLM {\n  return new ModelAdapter(ai, model, config);\n}\n\nclass ModelAdapter extends BaseLLM {\n  resolvedModel?: ModelAction;\n\n  constructor(\n    private ai: Genkit,\n    private model: ModelArgument,\n    private config?: any\n  ) {\n    super({});\n  }\n\n  async _generate(\n    prompts: string[],\n    options: this['ParsedCallOptions'],\n    runManager?: CallbackManagerForLLMRun | undefined\n  ): Promise<LLMResult> {\n    logger.debug(\n      'ModelAdapter._generate',\n      JSON.stringify(arguments, undefined, '  ')\n    );\n    //options\n    const ress = await Promise.all(\n      prompts.map((p) =>\n        this.ai.generate({\n          model: this.model,\n          prompt: p,\n          config: this.config,\n        })\n      )\n    );\n\n    return {\n      generations: ress.map((r) => [{ text: r.text }]),\n    };\n  }\n\n  _llmType() {\n    return 'genkit';\n  }\n}\n"],"mappings":"AAkBA,SAAS,cAAc;AAGvB,SAAS,eAAe;AAEjB,SAAS,YACd,IACA,OACA,QACS;AACT,SAAO,IAAI,aAAa,IAAI,OAAO,MAAM;AAC3C;AAEA,MAAM,qBAAqB,QAAQ;AAAA,EAGjC,YACU,IACA,OACA,QACR;AACA,UAAM,CAAC,CAAC;AAJA;AACA;AACA;AAAA,EAGV;AAAA,EARA;AAAA,EAUA,MAAM,UACJ,SACA,SACA,YACoB;AACpB,WAAO;AAAA,MACL;AAAA,MACA,KAAK,UAAU,WAAW,QAAW,IAAI;AAAA,IAC3C;AAEA,UAAM,OAAO,MAAM,QAAQ;AAAA,MACzB,QAAQ;AAAA,QAAI,CAAC,MACX,KAAK,GAAG,SAAS;AAAA,UACf,OAAO,KAAK;AAAA,UACZ,QAAQ;AAAA,UACR,QAAQ,KAAK;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,MACL,aAAa,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,WAAW;AACT,WAAO;AAAA,EACT;AACF;","names":[]}