class FewShotPromptTemplateInternal method that handles batching and configuration for a runnable
Return the string type key uniquely identifying this class of prompt template.
Default streaming implementation.
Assigns new fields to the dict output of this runnable. Returns a new runnable.
Convert a runnable to a tool. Return a new instance of RunnableToolLike
Default implementation of batch, which calls invoke N times.
Format the prompt given the input values and return a formatted prompt value.
Method to invoke the document transformation. This method calls the
Merges partial variables and user variables.
Pick keys from the dict output of this runnable. Returns a new runnable.
Create a new runnable sequence that runs each individual runnable in series,
Stream output in chunks.
Generate a stream of events emitted by the internal steps of the runnable.
Stream all output from a runnable, as reported to the callback system.
Default implementation of transform, which buffers input and then calls stream.
Bind config to a Runnable, returning a new Runnable.
Create a new runnable from the current one that will try invoking
Bind lifecycle listeners to a Runnable, returning a new Runnable.
Add retry logic to an existing runnable.
The name of the serializable. Override to provide an alias or
A path to the module that contains the class, eg. ["langchain", "llms"]
A path to the module that contains the class, eg. ["langchain", "llms"]
A path to the module that contains the class, eg. ["langchain", "llms"]
const examplePrompt = PromptTemplate.fromTemplate(
"Input: {input}\nOutput: {output}",
);
const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(
[
{ input: "happy", output: "sad" },
{ input: "tall", output: "short" },
{ input: "energetic", output: "lethargic" },
{ input: "sunny", output: "gloomy" },
{ input: "windy", output: "calm" },
],
new OpenAIEmbeddings(),
HNSWLib,
{ k: 1 },
);
const dynamicPrompt = new FewShotPromptTemplate({
exampleSelector,
examplePrompt,
prefix: "Give the antonym of every input",
suffix: "Input: {adjective}\nOutput:",
inputVariables: ["adjective"],
});
// Format the dynamic prompt with the input 'rainy'
console.log(await dynamicPrompt.format({ adjective: "rainy" }));Examples to format into the prompt. Exactly one of this or exampleSelector must be provided.
An BaseExampleSelector Examples to format into the prompt. Exactly one of this or examples must be provided.
String separator used to join the prefix, the examples, and suffix.
A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.
A prompt template string to put before the examples.
A prompt template string to put after the examples.
The formatting method to use on the prompt.
Whether to try validating the template on initialization
Prompt template that contains few-shot examples.
Default streaming implementation.