-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
string.ts
38 lines (36 loc) · 1.32 KB
/
string.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Default generic "any" values are for backwards compatibility.
// Replace with "string" when we are comfortable with a breaking change.
import type { InputValues } from "../utils/types/index.js";
import {
type StringPromptValueInterface,
StringPromptValue,
} from "../prompt_values.js";
import { BasePromptTemplate, type TypedPromptInputValues } from "./base.js";
/**
* Base class for string prompt templates. It extends the
* BasePromptTemplate class and overrides the formatPromptValue method to
* return a StringPromptValue.
*/
export abstract class BaseStringPromptTemplate<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
RunInput extends InputValues = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
PartialVariableName extends string = any
> extends BasePromptTemplate<
RunInput,
StringPromptValueInterface,
PartialVariableName
> {
/**
* Formats the prompt given the input values and returns a formatted
* prompt value.
* @param values The input values to format the prompt.
* @returns A Promise that resolves to a formatted prompt value.
*/
async formatPromptValue(
values: TypedPromptInputValues<RunInput>
): Promise<StringPromptValueInterface> {
const formattedPrompt = await this.format(values);
return new StringPromptValue(formattedPrompt);
}
}