pipeline.d.ts 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import type { InputValues, PartialValues } from "../utils/types/index.js";
  2. import type { SerializedBasePromptTemplate } from "./serde.js";
  3. import { BasePromptTemplate, type BasePromptTemplateInput } from "./base.js";
  4. /**
  5. * Type that includes the name of the prompt and the prompt itself.
  6. */
  7. export type PipelinePromptParams<PromptTemplateType extends BasePromptTemplate> = {
  8. name: string;
  9. prompt: PromptTemplateType;
  10. };
  11. /**
  12. * Type that extends the BasePromptTemplateInput type, excluding the
  13. * inputVariables property. It includes an array of pipelinePrompts and a
  14. * finalPrompt.
  15. */
  16. export type PipelinePromptTemplateInput<PromptTemplateType extends BasePromptTemplate> = Omit<BasePromptTemplateInput, "inputVariables"> & {
  17. pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];
  18. finalPrompt: PromptTemplateType;
  19. };
  20. /**
  21. * Class that handles a sequence of prompts, each of which may require
  22. * different input variables. Includes methods for formatting these
  23. * prompts, extracting required input values, and handling partial
  24. * prompts.
  25. * @example
  26. * ```typescript
  27. * const composedPrompt = new PipelinePromptTemplate({
  28. * pipelinePrompts: [
  29. * {
  30. * name: "introduction",
  31. * prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),
  32. * },
  33. * {
  34. * name: "example",
  35. * prompt: PromptTemplate.fromTemplate(
  36. * `Here's an example of an interaction:
  37. * Q: {example_q}
  38. * A: {example_a}`,
  39. * ),
  40. * },
  41. * {
  42. * name: "start",
  43. * prompt: PromptTemplate.fromTemplate(
  44. * `Now, do this for real!
  45. * Q: {input}
  46. * A:`,
  47. * ),
  48. * },
  49. * ],
  50. * finalPrompt: PromptTemplate.fromTemplate(
  51. * `{introduction}
  52. * {example}
  53. * {start}`,
  54. * ),
  55. * });
  56. *
  57. * const formattedPrompt = await composedPrompt.format({
  58. * person: "Elon Musk",
  59. * example_q: `What's your favorite car?`,
  60. * example_a: "Tesla",
  61. * input: `What's your favorite social media site?`,
  62. * });
  63. * ```
  64. */
  65. export declare class PipelinePromptTemplate<PromptTemplateType extends BasePromptTemplate> extends BasePromptTemplate {
  66. static lc_name(): string;
  67. pipelinePrompts: PipelinePromptParams<PromptTemplateType>[];
  68. finalPrompt: PromptTemplateType;
  69. constructor(input: PipelinePromptTemplateInput<PromptTemplateType>);
  70. /**
  71. * Computes the input values required by the pipeline prompts.
  72. * @returns Array of input values required by the pipeline prompts.
  73. */
  74. protected computeInputValues(): string[];
  75. protected static extractRequiredInputValues(allValues: InputValues, requiredValueNames: string[]): InputValues;
  76. /**
  77. * Formats the pipeline prompts based on the provided input values.
  78. * @param values Input values to format the pipeline prompts.
  79. * @returns Promise that resolves with the formatted input values.
  80. */
  81. protected formatPipelinePrompts(values: InputValues): Promise<InputValues>;
  82. /**
  83. * Formats the final prompt value based on the provided input values.
  84. * @param values Input values to format the final prompt value.
  85. * @returns Promise that resolves with the formatted final prompt value.
  86. */
  87. formatPromptValue(values: InputValues): Promise<PromptTemplateType["PromptValueReturnType"]>;
  88. format(values: InputValues): Promise<string>;
  89. /**
  90. * Handles partial prompts, which are prompts that have been partially
  91. * filled with input values.
  92. * @param values Partial input values.
  93. * @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.
  94. */
  95. partial(values: PartialValues): Promise<PipelinePromptTemplate<PromptTemplateType>>;
  96. serialize(): SerializedBasePromptTemplate;
  97. _getPromptType(): string;
  98. }