{"version":3,"file":"llms.cjs","names":["LLM"],"sources":["../../../src/utils/testing/llms.ts"],"sourcesContent":["import { CallbackManagerForLLMRun } from \"../../callbacks/manager.js\";\nimport { BaseLLMParams, LLM } from \"../../language_models/llms.js\";\nimport { GenerationChunk } from \"../../outputs.js\";\n\nexport class FakeLLM extends LLM {\n  response?: string;\n\n  thrownErrorString?: string;\n\n  constructor(\n    fields: { response?: string; thrownErrorString?: string } & BaseLLMParams\n  ) {\n    super(fields);\n    this.response = fields.response;\n    this.thrownErrorString = fields.thrownErrorString;\n  }\n\n  _llmType() {\n    return \"fake\";\n  }\n\n  async _call(\n    prompt: string,\n    _options: this[\"ParsedCallOptions\"],\n    runManager?: CallbackManagerForLLMRun\n  ): Promise<string> {\n    if (this.thrownErrorString) {\n      throw new Error(this.thrownErrorString);\n    }\n    const response = this.response ?? prompt;\n    await runManager?.handleLLMNewToken(response);\n    return response;\n  }\n}\n\nexport class FakeStreamingLLM extends LLM {\n  sleep?: number = 50;\n\n  responses?: string[];\n\n  thrownErrorString?: string;\n\n  constructor(\n    fields: {\n      sleep?: number;\n      responses?: string[];\n      thrownErrorString?: string;\n    } & BaseLLMParams\n  ) {\n    super(fields);\n    this.sleep = fields.sleep ?? this.sleep;\n    this.responses = fields.responses;\n    this.thrownErrorString = fields.thrownErrorString;\n  }\n\n  _llmType() {\n    return \"fake\";\n  }\n\n  async _call(prompt: string): Promise<string> {\n    if (this.thrownErrorString) {\n      throw new Error(this.thrownErrorString);\n    }\n    const response = this.responses?.[0];\n    this.responses = this.responses?.slice(1);\n    return response ?? prompt;\n  }\n\n  async *_streamResponseChunks(\n    input: string,\n    _options?: this[\"ParsedCallOptions\"],\n    runManager?: CallbackManagerForLLMRun\n  ) {\n    if (this.thrownErrorString) {\n      throw new Error(this.thrownErrorString);\n    }\n    const response = this.responses?.[0];\n    this.responses = this.responses?.slice(1);\n    for (const c of response ?? input) {\n      await new Promise((resolve) => setTimeout(resolve, this.sleep));\n      yield { text: c, generationInfo: {} } as GenerationChunk;\n      await runManager?.handleLLMNewToken(c);\n    }\n  }\n}\n"],"mappings":";;AAIA,IAAa,UAAb,cAA6BA,6BAAAA,IAAI;CAC/B;CAEA;CAEA,YACE,QACA;EACA,MAAM,MAAM;EACZ,KAAK,WAAW,OAAO;EACvB,KAAK,oBAAoB,OAAO;CAClC;CAEA,WAAW;EACT,OAAO;CACT;CAEA,MAAM,MACJ,QACA,UACA,YACiB;EACjB,IAAI,KAAK,mBACP,MAAM,IAAI,MAAM,KAAK,iBAAiB;EAExC,MAAM,WAAW,KAAK,YAAY;EAClC,MAAM,YAAY,kBAAkB,QAAQ;EAC5C,OAAO;CACT;AACF;AAEA,IAAa,mBAAb,cAAsCA,6BAAAA,IAAI;CACxC,QAAiB;CAEjB;CAEA;CAEA,YACE,QAKA;EACA,MAAM,MAAM;EACZ,KAAK,QAAQ,OAAO,SAAS,KAAK;EAClC,KAAK,YAAY,OAAO;EACxB,KAAK,oBAAoB,OAAO;CAClC;CAEA,WAAW;EACT,OAAO;CACT;CAEA,MAAM,MAAM,QAAiC;EAC3C,IAAI,KAAK,mBACP,MAAM,IAAI,MAAM,KAAK,iBAAiB;EAExC,MAAM,WAAW,KAAK,YAAY;EAClC,KAAK,YAAY,KAAK,WAAW,MAAM,CAAC;EACxC,OAAO,YAAY;CACrB;CAEA,OAAO,sBACL,OACA,UACA,YACA;EACA,IAAI,KAAK,mBACP,MAAM,IAAI,MAAM,KAAK,iBAAiB;EAExC,MAAM,WAAW,KAAK,YAAY;EAClC,KAAK,YAAY,KAAK,WAAW,MAAM,CAAC;EACxC,KAAK,MAAM,KAAK,YAAY,OAAO;GACjC,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,KAAK,KAAK,CAAC;GAC9D,MAAM;IAAE,MAAM;IAAG,gBAAgB,CAAC;GAAE;GACpC,MAAM,YAAY,kBAAkB,CAAC;EACvC;CACF;AACF"}