langchain 0.0.194 → 0.0.196
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
package/dist/prompts/few_shot.js
CHANGED
|
@@ -1,350 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { checkValidTemplate, renderTemplate, } from "./template.js";
|
|
3
|
-
import { PromptTemplate } from "./prompt.js";
|
|
4
|
-
import { BaseChatPromptTemplate } from "./chat.js";
|
|
5
|
-
/**
|
|
6
|
-
* Prompt template that contains few-shot examples.
|
|
7
|
-
* @augments BasePromptTemplate
|
|
8
|
-
* @augments FewShotPromptTemplateInput
|
|
9
|
-
* @example
|
|
10
|
-
* ```typescript
|
|
11
|
-
* const examplePrompt = PromptTemplate.fromTemplate(
|
|
12
|
-
* "Input: {input}\nOutput: {output}",
|
|
13
|
-
* );
|
|
14
|
-
*
|
|
15
|
-
* const exampleSelector = await SemanticSimilarityExampleSelector.fromExamples(
|
|
16
|
-
* [
|
|
17
|
-
* { input: "happy", output: "sad" },
|
|
18
|
-
* { input: "tall", output: "short" },
|
|
19
|
-
* { input: "energetic", output: "lethargic" },
|
|
20
|
-
* { input: "sunny", output: "gloomy" },
|
|
21
|
-
* { input: "windy", output: "calm" },
|
|
22
|
-
* ],
|
|
23
|
-
* new OpenAIEmbeddings(),
|
|
24
|
-
* HNSWLib,
|
|
25
|
-
* { k: 1 },
|
|
26
|
-
* );
|
|
27
|
-
*
|
|
28
|
-
* const dynamicPrompt = new FewShotPromptTemplate({
|
|
29
|
-
* exampleSelector,
|
|
30
|
-
* examplePrompt,
|
|
31
|
-
* prefix: "Give the antonym of every input",
|
|
32
|
-
* suffix: "Input: {adjective}\nOutput:",
|
|
33
|
-
* inputVariables: ["adjective"],
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Format the dynamic prompt with the input 'rainy'
|
|
37
|
-
* console.log(await dynamicPrompt.format({ adjective: "rainy" }));
|
|
38
|
-
*
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export class FewShotPromptTemplate extends BaseStringPromptTemplate {
|
|
42
|
-
constructor(input) {
|
|
43
|
-
super(input);
|
|
44
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: false
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(this, "examples", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true,
|
|
54
|
-
value: void 0
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(this, "exampleSelector", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(this, "examplePrompt", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "suffix", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: ""
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(this, "exampleSeparator", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: "\n\n"
|
|
79
|
-
});
|
|
80
|
-
Object.defineProperty(this, "prefix", {
|
|
81
|
-
enumerable: true,
|
|
82
|
-
configurable: true,
|
|
83
|
-
writable: true,
|
|
84
|
-
value: ""
|
|
85
|
-
});
|
|
86
|
-
Object.defineProperty(this, "templateFormat", {
|
|
87
|
-
enumerable: true,
|
|
88
|
-
configurable: true,
|
|
89
|
-
writable: true,
|
|
90
|
-
value: "f-string"
|
|
91
|
-
});
|
|
92
|
-
Object.defineProperty(this, "validateTemplate", {
|
|
93
|
-
enumerable: true,
|
|
94
|
-
configurable: true,
|
|
95
|
-
writable: true,
|
|
96
|
-
value: true
|
|
97
|
-
});
|
|
98
|
-
Object.assign(this, input);
|
|
99
|
-
if (this.examples !== undefined && this.exampleSelector !== undefined) {
|
|
100
|
-
throw new Error("Only one of 'examples' and 'example_selector' should be provided");
|
|
101
|
-
}
|
|
102
|
-
if (this.examples === undefined && this.exampleSelector === undefined) {
|
|
103
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
104
|
-
}
|
|
105
|
-
if (this.validateTemplate) {
|
|
106
|
-
let totalInputVariables = this.inputVariables;
|
|
107
|
-
if (this.partialVariables) {
|
|
108
|
-
totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
|
|
109
|
-
}
|
|
110
|
-
checkValidTemplate(this.prefix + this.suffix, this.templateFormat, totalInputVariables);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
_getPromptType() {
|
|
114
|
-
return "few_shot";
|
|
115
|
-
}
|
|
116
|
-
static lc_name() {
|
|
117
|
-
return "FewShotPromptTemplate";
|
|
118
|
-
}
|
|
119
|
-
async getExamples(inputVariables) {
|
|
120
|
-
if (this.examples !== undefined) {
|
|
121
|
-
return this.examples;
|
|
122
|
-
}
|
|
123
|
-
if (this.exampleSelector !== undefined) {
|
|
124
|
-
return this.exampleSelector.selectExamples(inputVariables);
|
|
125
|
-
}
|
|
126
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
127
|
-
}
|
|
128
|
-
async partial(values) {
|
|
129
|
-
const newInputVariables = this.inputVariables.filter((iv) => !(iv in values));
|
|
130
|
-
const newPartialVariables = {
|
|
131
|
-
...(this.partialVariables ?? {}),
|
|
132
|
-
...values,
|
|
133
|
-
};
|
|
134
|
-
const promptDict = {
|
|
135
|
-
...this,
|
|
136
|
-
inputVariables: newInputVariables,
|
|
137
|
-
partialVariables: newPartialVariables,
|
|
138
|
-
};
|
|
139
|
-
return new FewShotPromptTemplate(promptDict);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Formats the prompt with the given values.
|
|
143
|
-
* @param values The values to format the prompt with.
|
|
144
|
-
* @returns A promise that resolves to a string representing the formatted prompt.
|
|
145
|
-
*/
|
|
146
|
-
async format(values) {
|
|
147
|
-
const allValues = await this.mergePartialAndUserVariables(values);
|
|
148
|
-
const examples = await this.getExamples(allValues);
|
|
149
|
-
const exampleStrings = await Promise.all(examples.map((example) => this.examplePrompt.format(example)));
|
|
150
|
-
const template = [this.prefix, ...exampleStrings, this.suffix].join(this.exampleSeparator);
|
|
151
|
-
return renderTemplate(template, this.templateFormat, allValues);
|
|
152
|
-
}
|
|
153
|
-
serialize() {
|
|
154
|
-
if (this.exampleSelector || !this.examples) {
|
|
155
|
-
throw new Error("Serializing an example selector is not currently supported");
|
|
156
|
-
}
|
|
157
|
-
if (this.outputParser !== undefined) {
|
|
158
|
-
throw new Error("Serializing an output parser is not currently supported");
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
_type: this._getPromptType(),
|
|
162
|
-
input_variables: this.inputVariables,
|
|
163
|
-
example_prompt: this.examplePrompt.serialize(),
|
|
164
|
-
example_separator: this.exampleSeparator,
|
|
165
|
-
suffix: this.suffix,
|
|
166
|
-
prefix: this.prefix,
|
|
167
|
-
template_format: this.templateFormat,
|
|
168
|
-
examples: this.examples,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
static async deserialize(data) {
|
|
172
|
-
const { example_prompt } = data;
|
|
173
|
-
if (!example_prompt) {
|
|
174
|
-
throw new Error("Missing example prompt");
|
|
175
|
-
}
|
|
176
|
-
const examplePrompt = await PromptTemplate.deserialize(example_prompt);
|
|
177
|
-
let examples;
|
|
178
|
-
if (Array.isArray(data.examples)) {
|
|
179
|
-
examples = data.examples;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
throw new Error("Invalid examples format. Only list or string are supported.");
|
|
183
|
-
}
|
|
184
|
-
return new FewShotPromptTemplate({
|
|
185
|
-
inputVariables: data.input_variables,
|
|
186
|
-
examplePrompt,
|
|
187
|
-
examples,
|
|
188
|
-
exampleSeparator: data.example_separator,
|
|
189
|
-
prefix: data.prefix,
|
|
190
|
-
suffix: data.suffix,
|
|
191
|
-
templateFormat: data.template_format,
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Chat prompt template that contains few-shot examples.
|
|
197
|
-
* @augments BasePromptTemplateInput
|
|
198
|
-
* @augments FewShotChatMessagePromptTemplateInput
|
|
199
|
-
*/
|
|
200
|
-
export class FewShotChatMessagePromptTemplate extends BaseChatPromptTemplate {
|
|
201
|
-
_getPromptType() {
|
|
202
|
-
return "few_shot_chat";
|
|
203
|
-
}
|
|
204
|
-
static lc_name() {
|
|
205
|
-
return "FewShotChatMessagePromptTemplate";
|
|
206
|
-
}
|
|
207
|
-
constructor(fields) {
|
|
208
|
-
super(fields);
|
|
209
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
210
|
-
enumerable: true,
|
|
211
|
-
configurable: true,
|
|
212
|
-
writable: true,
|
|
213
|
-
value: true
|
|
214
|
-
});
|
|
215
|
-
Object.defineProperty(this, "examples", {
|
|
216
|
-
enumerable: true,
|
|
217
|
-
configurable: true,
|
|
218
|
-
writable: true,
|
|
219
|
-
value: void 0
|
|
220
|
-
});
|
|
221
|
-
Object.defineProperty(this, "exampleSelector", {
|
|
222
|
-
enumerable: true,
|
|
223
|
-
configurable: true,
|
|
224
|
-
writable: true,
|
|
225
|
-
value: void 0
|
|
226
|
-
});
|
|
227
|
-
Object.defineProperty(this, "examplePrompt", {
|
|
228
|
-
enumerable: true,
|
|
229
|
-
configurable: true,
|
|
230
|
-
writable: true,
|
|
231
|
-
value: void 0
|
|
232
|
-
});
|
|
233
|
-
Object.defineProperty(this, "suffix", {
|
|
234
|
-
enumerable: true,
|
|
235
|
-
configurable: true,
|
|
236
|
-
writable: true,
|
|
237
|
-
value: ""
|
|
238
|
-
});
|
|
239
|
-
Object.defineProperty(this, "exampleSeparator", {
|
|
240
|
-
enumerable: true,
|
|
241
|
-
configurable: true,
|
|
242
|
-
writable: true,
|
|
243
|
-
value: "\n\n"
|
|
244
|
-
});
|
|
245
|
-
Object.defineProperty(this, "prefix", {
|
|
246
|
-
enumerable: true,
|
|
247
|
-
configurable: true,
|
|
248
|
-
writable: true,
|
|
249
|
-
value: ""
|
|
250
|
-
});
|
|
251
|
-
Object.defineProperty(this, "templateFormat", {
|
|
252
|
-
enumerable: true,
|
|
253
|
-
configurable: true,
|
|
254
|
-
writable: true,
|
|
255
|
-
value: "f-string"
|
|
256
|
-
});
|
|
257
|
-
Object.defineProperty(this, "validateTemplate", {
|
|
258
|
-
enumerable: true,
|
|
259
|
-
configurable: true,
|
|
260
|
-
writable: true,
|
|
261
|
-
value: true
|
|
262
|
-
});
|
|
263
|
-
this.examples = fields.examples;
|
|
264
|
-
this.examplePrompt = fields.examplePrompt;
|
|
265
|
-
this.exampleSeparator = fields.exampleSeparator ?? "\n\n";
|
|
266
|
-
this.exampleSelector = fields.exampleSelector;
|
|
267
|
-
this.prefix = fields.prefix ?? "";
|
|
268
|
-
this.suffix = fields.suffix ?? "";
|
|
269
|
-
this.templateFormat = fields.templateFormat ?? "f-string";
|
|
270
|
-
this.validateTemplate = fields.validateTemplate ?? true;
|
|
271
|
-
if (this.examples !== undefined && this.exampleSelector !== undefined) {
|
|
272
|
-
throw new Error("Only one of 'examples' and 'example_selector' should be provided");
|
|
273
|
-
}
|
|
274
|
-
if (this.examples === undefined && this.exampleSelector === undefined) {
|
|
275
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
276
|
-
}
|
|
277
|
-
if (this.validateTemplate) {
|
|
278
|
-
let totalInputVariables = this.inputVariables;
|
|
279
|
-
if (this.partialVariables) {
|
|
280
|
-
totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
|
|
281
|
-
}
|
|
282
|
-
checkValidTemplate(this.prefix + this.suffix, this.templateFormat, totalInputVariables);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async getExamples(inputVariables) {
|
|
286
|
-
if (this.examples !== undefined) {
|
|
287
|
-
return this.examples;
|
|
288
|
-
}
|
|
289
|
-
if (this.exampleSelector !== undefined) {
|
|
290
|
-
return this.exampleSelector.selectExamples(inputVariables);
|
|
291
|
-
}
|
|
292
|
-
throw new Error("One of 'examples' and 'example_selector' should be provided");
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Formats the list of values and returns a list of formatted messages.
|
|
296
|
-
* @param values The values to format the prompt with.
|
|
297
|
-
* @returns A promise that resolves to a string representing the formatted prompt.
|
|
298
|
-
*/
|
|
299
|
-
async formatMessages(values) {
|
|
300
|
-
const allValues = await this.mergePartialAndUserVariables(values);
|
|
301
|
-
let examples = await this.getExamples(allValues);
|
|
302
|
-
examples = examples.map((example) => {
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
304
|
-
const result = {};
|
|
305
|
-
this.examplePrompt.inputVariables.forEach((inputVariable) => {
|
|
306
|
-
result[inputVariable] = example[inputVariable];
|
|
307
|
-
});
|
|
308
|
-
return result;
|
|
309
|
-
});
|
|
310
|
-
const messages = [];
|
|
311
|
-
for (const example of examples) {
|
|
312
|
-
const exampleMessages = await this.examplePrompt.formatMessages(example);
|
|
313
|
-
messages.push(...exampleMessages);
|
|
314
|
-
}
|
|
315
|
-
return messages;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Formats the prompt with the given values.
|
|
319
|
-
* @param values The values to format the prompt with.
|
|
320
|
-
* @returns A promise that resolves to a string representing the formatted prompt.
|
|
321
|
-
*/
|
|
322
|
-
async format(values) {
|
|
323
|
-
const allValues = await this.mergePartialAndUserVariables(values);
|
|
324
|
-
const examples = await this.getExamples(allValues);
|
|
325
|
-
const exampleMessages = await Promise.all(examples.map((example) => this.examplePrompt.formatMessages(example)));
|
|
326
|
-
const exampleStrings = exampleMessages
|
|
327
|
-
.flat()
|
|
328
|
-
.map((message) => message.content);
|
|
329
|
-
const template = [this.prefix, ...exampleStrings, this.suffix].join(this.exampleSeparator);
|
|
330
|
-
return renderTemplate(template, this.templateFormat, allValues);
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Partially formats the prompt with the given values.
|
|
334
|
-
* @param values The values to partially format the prompt with.
|
|
335
|
-
* @returns A promise that resolves to an instance of `FewShotChatMessagePromptTemplate` with the given values partially formatted.
|
|
336
|
-
*/
|
|
337
|
-
async partial(values) {
|
|
338
|
-
const newInputVariables = this.inputVariables.filter((variable) => !(variable in values));
|
|
339
|
-
const newPartialVariables = {
|
|
340
|
-
...(this.partialVariables ?? {}),
|
|
341
|
-
...values,
|
|
342
|
-
};
|
|
343
|
-
const promptDict = {
|
|
344
|
-
...this,
|
|
345
|
-
inputVariables: newInputVariables,
|
|
346
|
-
partialVariables: newPartialVariables,
|
|
347
|
-
};
|
|
348
|
-
return new FewShotChatMessagePromptTemplate(promptDict);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
1
|
+
export * from "langchain-core/prompts/few_shot";
|
package/dist/prompts/index.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PipelinePromptTemplate = exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotChatMessagePromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.isLLM = exports.isChatModel = exports.ConditionalPromptSelector = exports.BasePromptSelector = exports.PromptTemplate = exports.
|
|
3
|
+
exports.PipelinePromptTemplate = exports.checkValidTemplate = exports.renderTemplate = exports.parseTemplate = exports.BaseChatPromptTemplate = exports.MessagesPlaceholder = exports.ChatMessagePromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatPromptTemplate = exports.FewShotChatMessagePromptTemplate = exports.FewShotPromptTemplate = exports.SemanticSimilarityExampleSelector = exports.LengthBasedExampleSelector = exports.isLLM = exports.isChatModel = exports.ConditionalPromptSelector = exports.BasePromptSelector = exports.PromptTemplate = exports.BaseExampleSelector = exports.BaseStringPromptTemplate = exports.StringPromptValue = exports.BasePromptTemplate = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
|
-
Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_js_1.BaseExampleSelector; } });
|
|
6
5
|
Object.defineProperty(exports, "BasePromptTemplate", { enumerable: true, get: function () { return base_js_1.BasePromptTemplate; } });
|
|
7
6
|
Object.defineProperty(exports, "StringPromptValue", { enumerable: true, get: function () { return base_js_1.StringPromptValue; } });
|
|
8
7
|
Object.defineProperty(exports, "BaseStringPromptTemplate", { enumerable: true, get: function () { return base_js_1.BaseStringPromptTemplate; } });
|
|
8
|
+
var base_1 = require("langchain-core/prompts/example_selector/base");
|
|
9
|
+
Object.defineProperty(exports, "BaseExampleSelector", { enumerable: true, get: function () { return base_1.BaseExampleSelector; } });
|
|
9
10
|
var prompt_js_1 = require("./prompt.cjs");
|
|
10
11
|
Object.defineProperty(exports, "PromptTemplate", { enumerable: true, get: function () { return prompt_js_1.PromptTemplate; } });
|
|
11
12
|
var conditional_js_1 = require("./selectors/conditional.cjs");
|
package/dist/prompts/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BasePromptTemplate, type BasePromptTemplateInput, StringPromptValue, BaseStringPromptTemplate, } from "./base.js";
|
|
2
|
+
export { BaseExampleSelector } from "langchain-core/prompts/example_selector/base";
|
|
2
3
|
export { PromptTemplate, type PromptTemplateInput } from "./prompt.js";
|
|
3
4
|
export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
|
|
4
5
|
export { LengthBasedExampleSelector, type LengthBasedExampleSelectorInput, } from "./selectors/LengthBasedExampleSelector.js";
|
package/dist/prompts/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BasePromptTemplate, StringPromptValue, BaseStringPromptTemplate, } from "./base.js";
|
|
2
|
+
export { BaseExampleSelector } from "langchain-core/prompts/example_selector/base";
|
|
2
3
|
export { PromptTemplate } from "./prompt.js";
|
|
3
4
|
export { BasePromptSelector, ConditionalPromptSelector, isChatModel, isLLM, } from "./selectors/conditional.js";
|
|
4
5
|
export { LengthBasedExampleSelector, } from "./selectors/LengthBasedExampleSelector.js";
|
|
@@ -1,144 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
const base_js_1 = require("./base.cjs");
|
|
5
|
-
const chat_js_1 = require("./chat.cjs");
|
|
6
|
-
/**
|
|
7
|
-
* Class that handles a sequence of prompts, each of which may require
|
|
8
|
-
* different input variables. Includes methods for formatting these
|
|
9
|
-
* prompts, extracting required input values, and handling partial
|
|
10
|
-
* prompts.
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const composedPrompt = new PipelinePromptTemplate({
|
|
14
|
-
* pipelinePrompts: [
|
|
15
|
-
* {
|
|
16
|
-
* name: "introduction",
|
|
17
|
-
* prompt: PromptTemplate.fromTemplate(`You are impersonating {person}.`),
|
|
18
|
-
* },
|
|
19
|
-
* {
|
|
20
|
-
* name: "example",
|
|
21
|
-
* prompt: PromptTemplate.fromTemplate(
|
|
22
|
-
* `Here's an example of an interaction:
|
|
23
|
-
* Q: {example_q}
|
|
24
|
-
* A: {example_a}`,
|
|
25
|
-
* ),
|
|
26
|
-
* },
|
|
27
|
-
* {
|
|
28
|
-
* name: "start",
|
|
29
|
-
* prompt: PromptTemplate.fromTemplate(
|
|
30
|
-
* `Now, do this for real!
|
|
31
|
-
* Q: {input}
|
|
32
|
-
* A:`,
|
|
33
|
-
* ),
|
|
34
|
-
* },
|
|
35
|
-
* ],
|
|
36
|
-
* finalPrompt: PromptTemplate.fromTemplate(
|
|
37
|
-
* `{introduction}
|
|
38
|
-
* {example}
|
|
39
|
-
* {start}`,
|
|
40
|
-
* ),
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* const formattedPrompt = await composedPrompt.format({
|
|
44
|
-
* person: "Elon Musk",
|
|
45
|
-
* example_q: `What's your favorite car?`,
|
|
46
|
-
* example_a: "Tesla",
|
|
47
|
-
* input: `What's your favorite social media site?`,
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
class PipelinePromptTemplate extends base_js_1.BasePromptTemplate {
|
|
52
|
-
static lc_name() {
|
|
53
|
-
return "PipelinePromptTemplate";
|
|
54
|
-
}
|
|
55
|
-
constructor(input) {
|
|
56
|
-
super({ ...input, inputVariables: [] });
|
|
57
|
-
Object.defineProperty(this, "pipelinePrompts", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "finalPrompt", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
this.pipelinePrompts = input.pipelinePrompts;
|
|
70
|
-
this.finalPrompt = input.finalPrompt;
|
|
71
|
-
this.inputVariables = this.computeInputValues();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Computes the input values required by the pipeline prompts.
|
|
75
|
-
* @returns Array of input values required by the pipeline prompts.
|
|
76
|
-
*/
|
|
77
|
-
computeInputValues() {
|
|
78
|
-
const intermediateValues = this.pipelinePrompts.map((pipelinePrompt) => pipelinePrompt.name);
|
|
79
|
-
const inputValues = this.pipelinePrompts
|
|
80
|
-
.map((pipelinePrompt) => pipelinePrompt.prompt.inputVariables.filter((inputValue) => !intermediateValues.includes(inputValue)))
|
|
81
|
-
.flat();
|
|
82
|
-
return [...new Set(inputValues)];
|
|
83
|
-
}
|
|
84
|
-
static extractRequiredInputValues(allValues, requiredValueNames) {
|
|
85
|
-
return requiredValueNames.reduce((requiredValues, valueName) => {
|
|
86
|
-
// eslint-disable-next-line no-param-reassign
|
|
87
|
-
requiredValues[valueName] = allValues[valueName];
|
|
88
|
-
return requiredValues;
|
|
89
|
-
}, {});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Formats the pipeline prompts based on the provided input values.
|
|
93
|
-
* @param values Input values to format the pipeline prompts.
|
|
94
|
-
* @returns Promise that resolves with the formatted input values.
|
|
95
|
-
*/
|
|
96
|
-
async formatPipelinePrompts(values) {
|
|
97
|
-
const allValues = await this.mergePartialAndUserVariables(values);
|
|
98
|
-
for (const { name: pipelinePromptName, prompt: pipelinePrompt } of this
|
|
99
|
-
.pipelinePrompts) {
|
|
100
|
-
const pipelinePromptInputValues = PipelinePromptTemplate.extractRequiredInputValues(allValues, pipelinePrompt.inputVariables);
|
|
101
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
102
|
-
if (pipelinePrompt instanceof chat_js_1.ChatPromptTemplate) {
|
|
103
|
-
allValues[pipelinePromptName] = await pipelinePrompt.formatMessages(pipelinePromptInputValues);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
allValues[pipelinePromptName] = await pipelinePrompt.format(pipelinePromptInputValues);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return PipelinePromptTemplate.extractRequiredInputValues(allValues, this.finalPrompt.inputVariables);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Formats the final prompt value based on the provided input values.
|
|
113
|
-
* @param values Input values to format the final prompt value.
|
|
114
|
-
* @returns Promise that resolves with the formatted final prompt value.
|
|
115
|
-
*/
|
|
116
|
-
async formatPromptValue(values) {
|
|
117
|
-
return this.finalPrompt.formatPromptValue(await this.formatPipelinePrompts(values));
|
|
118
|
-
}
|
|
119
|
-
async format(values) {
|
|
120
|
-
return this.finalPrompt.format(await this.formatPipelinePrompts(values));
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Handles partial prompts, which are prompts that have been partially
|
|
124
|
-
* filled with input values.
|
|
125
|
-
* @param values Partial input values.
|
|
126
|
-
* @returns Promise that resolves with a new PipelinePromptTemplate instance with updated input variables.
|
|
127
|
-
*/
|
|
128
|
-
async partial(values) {
|
|
129
|
-
const promptDict = { ...this };
|
|
130
|
-
promptDict.inputVariables = this.inputVariables.filter((iv) => !(iv in values));
|
|
131
|
-
promptDict.partialVariables = {
|
|
132
|
-
...(this.partialVariables ?? {}),
|
|
133
|
-
...values,
|
|
134
|
-
};
|
|
135
|
-
return new PipelinePromptTemplate(promptDict);
|
|
136
|
-
}
|
|
137
|
-
serialize() {
|
|
138
|
-
throw new Error("Not implemented.");
|
|
139
|
-
}
|
|
140
|
-
_getPromptType() {
|
|
141
|
-
return "pipeline";
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
exports.PipelinePromptTemplate = PipelinePromptTemplate;
|
|
17
|
+
__exportStar(require("langchain-core/prompts/pipeline"), exports);
|
|
@@ -1,98 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BasePromptTemplate, BasePromptTemplateInput } from "./base.js";
|
|
3
|
-
import { SerializedBasePromptTemplate } from "./serde.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
|
-
}
|
|
1
|
+
export * from "langchain-core/prompts/pipeline";
|