outputs.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { type BaseMessage, type BaseMessageChunk } from "./messages/base.js";
  2. export declare const RUN_KEY = "__run";
  3. /**
  4. * Output of a single generation.
  5. */
  6. export interface Generation {
  7. /**
  8. * Generated text output
  9. */
  10. text: string;
  11. /**
  12. * Raw generation info response from the provider.
  13. * May include things like reason for finishing (e.g. in {@link OpenAI})
  14. */
  15. generationInfo?: Record<string, any>;
  16. }
  17. export type GenerationChunkFields = {
  18. text: string;
  19. generationInfo?: Record<string, any>;
  20. };
  21. /**
  22. * Chunk of a single generation. Used for streaming.
  23. */
  24. export declare class GenerationChunk implements Generation {
  25. text: string;
  26. generationInfo?: Record<string, any>;
  27. constructor(fields: GenerationChunkFields);
  28. concat(chunk: GenerationChunk): GenerationChunk;
  29. }
  30. /**
  31. * Contains all relevant information returned by an LLM.
  32. */
  33. export type LLMResult = {
  34. /**
  35. * List of the things generated. Each input could have multiple {@link Generation | generations}, hence this is a list of lists.
  36. */
  37. generations: Generation[][];
  38. /**
  39. * Dictionary of arbitrary LLM-provider specific output.
  40. */
  41. llmOutput?: Record<string, any>;
  42. /**
  43. * Dictionary of run metadata
  44. */
  45. [RUN_KEY]?: Record<string, any>;
  46. };
  47. export interface ChatGeneration extends Generation {
  48. message: BaseMessage;
  49. }
  50. export type ChatGenerationChunkFields = GenerationChunkFields & {
  51. message: BaseMessageChunk;
  52. };
  53. export declare class ChatGenerationChunk extends GenerationChunk implements ChatGeneration {
  54. message: BaseMessageChunk;
  55. constructor(fields: ChatGenerationChunkFields);
  56. concat(chunk: ChatGenerationChunk): ChatGenerationChunk;
  57. }
  58. export interface ChatResult {
  59. generations: ChatGeneration[];
  60. llmOutput?: Record<string, any>;
  61. }