UNPKG

@langchain/core

Version:
1 lines 3.59 kB
{"version":3,"file":"outputs.cjs","names":["fields: GenerationChunkFields","chunk: GenerationChunk","fields: ChatGenerationChunkFields","chunk: ChatGenerationChunk"],"sources":["../src/outputs.ts"],"sourcesContent":["import { type BaseMessage, type BaseMessageChunk } from \"./messages/base.js\";\n\nexport const RUN_KEY = \"__run\";\n\n/**\n * Output of a single generation.\n */\nexport interface Generation {\n /**\n * Generated text output\n */\n text: string;\n /**\n * Raw generation info response from the provider.\n * May include things like reason for finishing (e.g. in {@link OpenAI})\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n generationInfo?: Record<string, any>;\n}\n\nexport type GenerationChunkFields = {\n text: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n generationInfo?: Record<string, any>;\n};\n\n/**\n * Chunk of a single generation. Used for streaming.\n */\nexport class GenerationChunk implements Generation {\n public text: string;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public generationInfo?: Record<string, any>;\n\n constructor(fields: GenerationChunkFields) {\n this.text = fields.text;\n this.generationInfo = fields.generationInfo;\n }\n\n concat(chunk: GenerationChunk): GenerationChunk {\n return new GenerationChunk({\n text: this.text + chunk.text,\n generationInfo: {\n ...this.generationInfo,\n ...chunk.generationInfo,\n },\n });\n }\n}\n\n/**\n * Contains all relevant information returned by an LLM.\n */\nexport type LLMResult = {\n /**\n * List of the things generated. Each input could have multiple {@link Generation | generations}, hence this is a list of lists.\n */\n generations: Generation[][];\n /**\n * Dictionary of arbitrary LLM-provider specific output.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n llmOutput?: Record<string, any>;\n /**\n * Dictionary of run metadata\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [RUN_KEY]?: Record<string, any>;\n};\n\nexport interface ChatGeneration extends Generation {\n message: BaseMessage;\n}\n\nexport type ChatGenerationChunkFields = GenerationChunkFields & {\n message: BaseMessageChunk;\n};\n\nexport class ChatGenerationChunk\n extends GenerationChunk\n implements ChatGeneration\n{\n public message: BaseMessageChunk;\n\n constructor(fields: ChatGenerationChunkFields) {\n super(fields);\n this.message = fields.message;\n }\n\n concat(chunk: ChatGenerationChunk) {\n return new ChatGenerationChunk({\n text: this.text + chunk.text,\n generationInfo: {\n ...this.generationInfo,\n ...chunk.generationInfo,\n },\n message: this.message.concat(chunk.message),\n });\n }\n}\n\nexport interface ChatResult {\n generations: ChatGeneration[];\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n llmOutput?: Record<string, any>;\n}\n"],"mappings":";;;;;;;;;AAEA,MAAa,UAAU;;;;AA2BvB,IAAa,kBAAb,MAAa,gBAAsC;CACjD,AAAO;CAGP,AAAO;CAEP,YAAYA,QAA+B;EACzC,KAAK,OAAO,OAAO;EACnB,KAAK,iBAAiB,OAAO;CAC9B;CAED,OAAOC,OAAyC;AAC9C,SAAO,IAAI,gBAAgB;GACzB,MAAM,KAAK,OAAO,MAAM;GACxB,gBAAgB;IACd,GAAG,KAAK;IACR,GAAG,MAAM;GACV;EACF;CACF;AACF;AA8BD,IAAa,sBAAb,MAAa,4BACH,gBAEV;CACE,AAAO;CAEP,YAAYC,QAAmC;EAC7C,MAAM,OAAO;EACb,KAAK,UAAU,OAAO;CACvB;CAED,OAAOC,OAA4B;AACjC,SAAO,IAAI,oBAAoB;GAC7B,MAAM,KAAK,OAAO,MAAM;GACxB,gBAAgB;IACd,GAAG,KAAK;IACR,GAAG,MAAM;GACV;GACD,SAAS,KAAK,QAAQ,OAAO,MAAM,QAAQ;EAC5C;CACF;AACF"}