string.js 881 B

123456789101112131415161718192021
  1. // Default generic "any" values are for backwards compatibility.
  2. // Replace with "string" when we are comfortable with a breaking change.
  3. import { StringPromptValue, } from "../prompt_values.js";
  4. import { BasePromptTemplate } from "./base.js";
  5. /**
  6. * Base class for string prompt templates. It extends the
  7. * BasePromptTemplate class and overrides the formatPromptValue method to
  8. * return a StringPromptValue.
  9. */
  10. export class BaseStringPromptTemplate extends BasePromptTemplate {
  11. /**
  12. * Formats the prompt given the input values and returns a formatted
  13. * prompt value.
  14. * @param values The input values to format the prompt.
  15. * @returns A Promise that resolves to a formatted prompt value.
  16. */
  17. async formatPromptValue(values) {
  18. const formattedPrompt = await this.format(values);
  19. return new StringPromptValue(formattedPrompt);
  20. }
  21. }