memory.d.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Type alias for a record where the keys are strings and the values can
  3. * be any type. This is used to represent the input values for a Chain.
  4. */
  5. export type InputValues = Record<string, any>;
  6. /**
  7. * Type alias for a record where the keys are strings and the values can
  8. * be any type. This is used to represent the output values from a Chain.
  9. */
  10. export type OutputValues = Record<string, any>;
  11. /**
  12. * Type alias for a record where the keys are strings and the values can
  13. * be any type. This is used to represent the memory variables in a Chain.
  14. */
  15. export type MemoryVariables = Record<string, any>;
  16. /**
  17. * Abstract base class for memory in LangChain's Chains. Memory refers to
  18. * the state in Chains. It can be used to store information about past
  19. * executions of a Chain and inject that information into the inputs of
  20. * future executions of the Chain.
  21. */
  22. export declare abstract class BaseMemory {
  23. abstract get memoryKeys(): string[];
  24. /**
  25. * Abstract method that should take an object of input values and return a
  26. * Promise that resolves with an object of memory variables. The
  27. * implementation of this method should load the memory variables from the
  28. * provided input values.
  29. * @param values An object of input values.
  30. * @returns Promise that resolves with an object of memory variables.
  31. */
  32. abstract loadMemoryVariables(values: InputValues): Promise<MemoryVariables>;
  33. /**
  34. * Abstract method that should take two objects, one of input values and
  35. * one of output values, and return a Promise that resolves when the
  36. * context has been saved. The implementation of this method should save
  37. * the context based on the provided input and output values.
  38. * @param inputValues An object of input values.
  39. * @param outputValues An object of output values.
  40. * @returns Promise that resolves when the context has been saved.
  41. */
  42. abstract saveContext(inputValues: InputValues, outputValues: OutputValues): Promise<void>;
  43. }
  44. /**
  45. * This function is used by memory classes to select the input value
  46. * to use for the memory. If there is only one input value, it is used.
  47. * If there are multiple input values, the inputKey must be specified.
  48. */
  49. export declare const getInputValue: (inputValues: InputValues, inputKey?: string) => any;
  50. /**
  51. * This function is used by memory classes to select the output value
  52. * to use for the memory. If there is only one output value, it is used.
  53. * If there are multiple output values, the outputKey must be specified.
  54. * If no outputKey is specified, an error is thrown.
  55. */
  56. export declare const getOutputValue: (outputValues: OutputValues, outputKey?: string) => any;
  57. /**
  58. * Function used by memory classes to get the key of the prompt input,
  59. * excluding any keys that are memory variables or the "stop" key. If
  60. * there is not exactly one prompt input key, an error is thrown.
  61. */
  62. export declare function getPromptInputKey(inputs: Record<string, unknown>, memoryVariables: string[]): string;