serializable.d.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { type SerializedFields } from "./map_keys.js";
  2. export interface BaseSerialized<T extends string> {
  3. lc: number;
  4. type: T;
  5. id: string[];
  6. name?: string;
  7. graph?: Record<string, any>;
  8. }
  9. export interface SerializedConstructor extends BaseSerialized<"constructor"> {
  10. kwargs: SerializedFields;
  11. }
  12. export interface SerializedSecret extends BaseSerialized<"secret"> {
  13. }
  14. export interface SerializedNotImplemented extends BaseSerialized<"not_implemented"> {
  15. }
  16. export type Serialized = SerializedConstructor | SerializedSecret | SerializedNotImplemented;
  17. /**
  18. * Get a unique name for the module, rather than parent class implementations.
  19. * Should not be subclassed, subclass lc_name above instead.
  20. */
  21. export declare function get_lc_unique_name(serializableClass: typeof Serializable): string;
  22. export interface SerializableInterface {
  23. get lc_id(): string[];
  24. }
  25. export declare abstract class Serializable implements SerializableInterface {
  26. lc_serializable: boolean;
  27. lc_kwargs: SerializedFields;
  28. /**
  29. * A path to the module that contains the class, eg. ["langchain", "llms"]
  30. * Usually should be the same as the entrypoint the class is exported from.
  31. */
  32. abstract lc_namespace: string[];
  33. /**
  34. * The name of the serializable. Override to provide an alias or
  35. * to preserve the serialized module name in minified environments.
  36. *
  37. * Implemented as a static method to support loading logic.
  38. */
  39. static lc_name(): string;
  40. /**
  41. * The final serialized identifier for the module.
  42. */
  43. get lc_id(): string[];
  44. /**
  45. * A map of secrets, which will be omitted from serialization.
  46. * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
  47. * Values are the secret ids, which will be used when deserializing.
  48. */
  49. get lc_secrets(): {
  50. [key: string]: string;
  51. } | undefined;
  52. /**
  53. * A map of additional attributes to merge with constructor args.
  54. * Keys are the attribute names, e.g. "foo".
  55. * Values are the attribute values, which will be serialized.
  56. * These attributes need to be accepted by the constructor as arguments.
  57. */
  58. get lc_attributes(): SerializedFields | undefined;
  59. /**
  60. * A map of aliases for constructor args.
  61. * Keys are the attribute names, e.g. "foo".
  62. * Values are the alias that will replace the key in serialization.
  63. * This is used to eg. make argument names match Python.
  64. */
  65. get lc_aliases(): {
  66. [key: string]: string;
  67. } | undefined;
  68. /**
  69. * A manual list of keys that should be serialized.
  70. * If not overridden, all fields passed into the constructor will be serialized.
  71. */
  72. get lc_serializable_keys(): string[] | undefined;
  73. constructor(kwargs?: SerializedFields, ..._args: never[]);
  74. toJSON(): Serialized;
  75. toJSONNotImplemented(): SerializedNotImplemented;
  76. }