langchain 0.0.195 → 0.0.197-rc.0
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/LICENSE +21 -0
- package/dist/agents/openai/index.cjs +6 -2
- package/dist/agents/openai/index.js +6 -2
- 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/anthropic.cjs +15 -348
- package/dist/chat_models/anthropic.d.ts +1 -156
- package/dist/chat_models/anthropic.js +1 -346
- 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.cjs +21 -1
- package/dist/chat_models/bedrock/web.d.ts +2 -2
- package/dist/chat_models/bedrock/web.js +21 -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/github.cjs +105 -0
- package/dist/document_loaders/web/github.d.ts +26 -0
- package/dist/document_loaders/web/github.js +105 -0
- 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/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/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.cjs +21 -1
- package/dist/llms/bedrock/web.d.ts +2 -2
- package/dist/llms/bedrock/web.js +21 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -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/list.cjs +4 -122
- package/dist/output_parsers/list.d.ts +1 -57
- package/dist/output_parsers/list.js +1 -119
- 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 +13 -477
- package/dist/prompts/chat.d.ts +2 -219
- package/dist/prompts/chat.js +2 -466
- package/dist/prompts/few_shot.cjs +3 -352
- 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 +2 -141
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +2 -145
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +2 -147
- 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 +5 -73
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/template.cjs +8 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- 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/momento_vector_index.cjs +39 -0
- package/dist/vectorstores/momento_vector_index.d.ts +17 -1
- package/dist/vectorstores/momento_vector_index.js +40 -1
- package/dist/vectorstores/mongodb_atlas.cjs +22 -2
- package/dist/vectorstores/mongodb_atlas.d.ts +13 -0
- package/dist/vectorstores/mongodb_atlas.js +22 -2
- package/package.json +18 -11
- 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/base.d.ts
CHANGED
|
@@ -1,132 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { SerializedBasePromptTemplate } from "./serde.js";
|
|
5
|
-
import { SerializedFields } from "../load/map_keys.js";
|
|
6
|
-
import { Runnable } from "../schema/runnable/index.js";
|
|
7
|
-
import { BaseCallbackConfig } from "../callbacks/manager.js";
|
|
8
|
-
import type { StringWithAutocomplete } from "../util/types.js";
|
|
9
|
-
export type TypedPromptInputValues<RunInput> = InputValues<StringWithAutocomplete<Extract<keyof RunInput, string>>>;
|
|
10
|
-
/**
|
|
11
|
-
* Represents a prompt value as a string. It extends the BasePromptValue
|
|
12
|
-
* class and overrides the toString and toChatMessages methods.
|
|
13
|
-
*/
|
|
14
|
-
export declare class StringPromptValue extends BasePromptValue {
|
|
15
|
-
lc_namespace: string[];
|
|
16
|
-
value: string;
|
|
17
|
-
constructor(value: string);
|
|
18
|
-
toString(): string;
|
|
19
|
-
toChatMessages(): HumanMessage[];
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Input common to all prompt templates.
|
|
23
|
-
*/
|
|
24
|
-
export interface BasePromptTemplateInput<InputVariables extends InputValues = any, PartialVariableName extends string = any> {
|
|
25
|
-
/**
|
|
26
|
-
* A list of variable names the prompt template expects
|
|
27
|
-
*/
|
|
28
|
-
inputVariables: Array<Extract<keyof InputVariables, string>>;
|
|
29
|
-
/**
|
|
30
|
-
* How to parse the output of calling an LLM on this formatted prompt
|
|
31
|
-
*/
|
|
32
|
-
outputParser?: BaseOutputParser;
|
|
33
|
-
/** Partial variables */
|
|
34
|
-
partialVariables?: PartialValues<PartialVariableName>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Base class for prompt templates. Exposes a format method that returns a
|
|
38
|
-
* string prompt given a set of input values.
|
|
39
|
-
*/
|
|
40
|
-
export declare abstract class BasePromptTemplate<RunInput extends InputValues = any, RunOutput extends BasePromptValue = BasePromptValue, PartialVariableName extends string = any> extends Runnable<RunInput, RunOutput> implements BasePromptTemplateInput {
|
|
41
|
-
PromptValueReturnType: RunOutput;
|
|
42
|
-
lc_serializable: boolean;
|
|
43
|
-
lc_namespace: string[];
|
|
44
|
-
get lc_attributes(): SerializedFields | undefined;
|
|
45
|
-
inputVariables: Array<Extract<keyof RunInput, string>>;
|
|
46
|
-
outputParser?: BaseOutputParser;
|
|
47
|
-
partialVariables: PartialValues<PartialVariableName>;
|
|
48
|
-
constructor(input: BasePromptTemplateInput);
|
|
49
|
-
abstract partial(values: PartialValues): Promise<BasePromptTemplate<RunInput, RunOutput, PartialVariableName>>;
|
|
50
|
-
/**
|
|
51
|
-
* Merges partial variables and user variables.
|
|
52
|
-
* @param userVariables The user variables to merge with the partial variables.
|
|
53
|
-
* @returns A Promise that resolves to an object containing the merged variables.
|
|
54
|
-
*/
|
|
55
|
-
mergePartialAndUserVariables(userVariables: TypedPromptInputValues<RunInput>): Promise<InputValues<Extract<keyof RunInput, string> | PartialVariableName>>;
|
|
56
|
-
/**
|
|
57
|
-
* Invokes the prompt template with the given input and options.
|
|
58
|
-
* @param input The input to invoke the prompt template with.
|
|
59
|
-
* @param options Optional configuration for the callback.
|
|
60
|
-
* @returns A Promise that resolves to the output of the prompt template.
|
|
61
|
-
*/
|
|
62
|
-
invoke(input: RunInput, options?: BaseCallbackConfig): Promise<RunOutput>;
|
|
63
|
-
/**
|
|
64
|
-
* Format the prompt given the input values.
|
|
65
|
-
*
|
|
66
|
-
* @param values - A dictionary of arguments to be passed to the prompt template.
|
|
67
|
-
* @returns A formatted prompt string.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* prompt.format({ foo: "bar" });
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
abstract format(values: TypedPromptInputValues<RunInput>): Promise<string>;
|
|
75
|
-
/**
|
|
76
|
-
* Format the prompt given the input values and return a formatted prompt value.
|
|
77
|
-
* @param values
|
|
78
|
-
* @returns A formatted PromptValue.
|
|
79
|
-
*/
|
|
80
|
-
abstract formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<RunOutput>;
|
|
81
|
-
/**
|
|
82
|
-
* Return the string type key uniquely identifying this class of prompt template.
|
|
83
|
-
*/
|
|
84
|
-
abstract _getPromptType(): string;
|
|
85
|
-
/**
|
|
86
|
-
* Return a json-like object representing this prompt template.
|
|
87
|
-
* @deprecated
|
|
88
|
-
*/
|
|
89
|
-
serialize(): SerializedBasePromptTemplate;
|
|
90
|
-
/**
|
|
91
|
-
* @deprecated
|
|
92
|
-
* Load a prompt template from a json-like object describing it.
|
|
93
|
-
*
|
|
94
|
-
* @remarks
|
|
95
|
-
* Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
|
|
96
|
-
* reference remote resources that we read asynchronously with a web
|
|
97
|
-
* request.
|
|
98
|
-
*/
|
|
99
|
-
static deserialize(data: SerializedBasePromptTemplate): Promise<BasePromptTemplate<InputValues, BasePromptValue, string>>;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Base class for string prompt templates. It extends the
|
|
103
|
-
* BasePromptTemplate class and overrides the formatPromptValue method to
|
|
104
|
-
* return a StringPromptValue.
|
|
105
|
-
*/
|
|
106
|
-
export declare abstract class BaseStringPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends BasePromptTemplate<RunInput, StringPromptValue, PartialVariableName> {
|
|
107
|
-
/**
|
|
108
|
-
* Formats the prompt given the input values and returns a formatted
|
|
109
|
-
* prompt value.
|
|
110
|
-
* @param values The input values to format the prompt.
|
|
111
|
-
* @returns A Promise that resolves to a formatted prompt value.
|
|
112
|
-
*/
|
|
113
|
-
formatPromptValue(values: TypedPromptInputValues<RunInput>): Promise<StringPromptValue>;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Base class for example selectors.
|
|
117
|
-
*/
|
|
118
|
-
export declare abstract class BaseExampleSelector extends Serializable {
|
|
119
|
-
lc_namespace: string[];
|
|
120
|
-
/**
|
|
121
|
-
* Adds an example to the example selector.
|
|
122
|
-
* @param example The example to add to the example selector.
|
|
123
|
-
* @returns A Promise that resolves to void or a string.
|
|
124
|
-
*/
|
|
125
|
-
abstract addExample(example: Example): Promise<void | string>;
|
|
126
|
-
/**
|
|
127
|
-
* Selects examples from the example selector given the input variables.
|
|
128
|
-
* @param input_variables The input variables to select examples with.
|
|
129
|
-
* @returns A Promise that resolves to an array of selected examples.
|
|
130
|
-
*/
|
|
131
|
-
abstract selectExamples(input_variables: Example): Promise<Example[]>;
|
|
132
|
-
}
|
|
1
|
+
export { type TypedPromptInputValues, BaseStringPromptTemplate, type BasePromptTemplateInput, BasePromptTemplate, } from "langchain-core/prompts";
|
|
2
|
+
export { StringPromptValue } from "langchain-core/prompt_values";
|
|
3
|
+
export { BaseExampleSelector } from "langchain-core/example_selectors";
|
package/dist/prompts/base.js
CHANGED
|
@@ -1,178 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { Serializable } from "../load/serializable.js";
|
|
5
|
-
import { Runnable } from "../schema/runnable/index.js";
|
|
6
|
-
/**
|
|
7
|
-
* Represents a prompt value as a string. It extends the BasePromptValue
|
|
8
|
-
* class and overrides the toString and toChatMessages methods.
|
|
9
|
-
*/
|
|
10
|
-
export class StringPromptValue extends BasePromptValue {
|
|
11
|
-
constructor(value) {
|
|
12
|
-
super({ value });
|
|
13
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: ["langchain", "prompts", "base"]
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "value", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: void 0
|
|
24
|
-
});
|
|
25
|
-
this.value = value;
|
|
26
|
-
}
|
|
27
|
-
toString() {
|
|
28
|
-
return this.value;
|
|
29
|
-
}
|
|
30
|
-
toChatMessages() {
|
|
31
|
-
return [new HumanMessage(this.value)];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Base class for prompt templates. Exposes a format method that returns a
|
|
36
|
-
* string prompt given a set of input values.
|
|
37
|
-
*/
|
|
38
|
-
export class BasePromptTemplate extends Runnable {
|
|
39
|
-
get lc_attributes() {
|
|
40
|
-
return {
|
|
41
|
-
partialVariables: undefined, // python doesn't support this yet
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
constructor(input) {
|
|
45
|
-
super(input);
|
|
46
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: true
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: ["langchain", "prompts", this._getPromptType()]
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(this, "inputVariables", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: void 0
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(this, "outputParser", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
configurable: true,
|
|
67
|
-
writable: true,
|
|
68
|
-
value: void 0
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(this, "partialVariables", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: void 0
|
|
75
|
-
});
|
|
76
|
-
const { inputVariables } = input;
|
|
77
|
-
if (inputVariables.includes("stop")) {
|
|
78
|
-
throw new Error("Cannot have an input variable named 'stop', as it is used internally, please rename.");
|
|
79
|
-
}
|
|
80
|
-
Object.assign(this, input);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Merges partial variables and user variables.
|
|
84
|
-
* @param userVariables The user variables to merge with the partial variables.
|
|
85
|
-
* @returns A Promise that resolves to an object containing the merged variables.
|
|
86
|
-
*/
|
|
87
|
-
async mergePartialAndUserVariables(userVariables) {
|
|
88
|
-
const partialVariables = this.partialVariables ?? {};
|
|
89
|
-
const partialValues = {};
|
|
90
|
-
for (const [key, value] of Object.entries(partialVariables)) {
|
|
91
|
-
if (typeof value === "string") {
|
|
92
|
-
partialValues[key] = value;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
partialValues[key] = await value();
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const allKwargs = {
|
|
99
|
-
...partialValues,
|
|
100
|
-
...userVariables,
|
|
101
|
-
};
|
|
102
|
-
return allKwargs;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Invokes the prompt template with the given input and options.
|
|
106
|
-
* @param input The input to invoke the prompt template with.
|
|
107
|
-
* @param options Optional configuration for the callback.
|
|
108
|
-
* @returns A Promise that resolves to the output of the prompt template.
|
|
109
|
-
*/
|
|
110
|
-
async invoke(input, options) {
|
|
111
|
-
return this._callWithConfig((input) => this.formatPromptValue(input), input, { ...options, runType: "prompt" });
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Return a json-like object representing this prompt template.
|
|
115
|
-
* @deprecated
|
|
116
|
-
*/
|
|
117
|
-
serialize() {
|
|
118
|
-
throw new Error("Use .toJSON() instead");
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @deprecated
|
|
122
|
-
* Load a prompt template from a json-like object describing it.
|
|
123
|
-
*
|
|
124
|
-
* @remarks
|
|
125
|
-
* Deserializing needs to be async because templates (e.g. {@link FewShotPromptTemplate}) can
|
|
126
|
-
* reference remote resources that we read asynchronously with a web
|
|
127
|
-
* request.
|
|
128
|
-
*/
|
|
129
|
-
static async deserialize(data) {
|
|
130
|
-
switch (data._type) {
|
|
131
|
-
case "prompt": {
|
|
132
|
-
const { PromptTemplate } = await import("./prompt.js");
|
|
133
|
-
return PromptTemplate.deserialize(data);
|
|
134
|
-
}
|
|
135
|
-
case undefined: {
|
|
136
|
-
const { PromptTemplate } = await import("./prompt.js");
|
|
137
|
-
return PromptTemplate.deserialize({ ...data, _type: "prompt" });
|
|
138
|
-
}
|
|
139
|
-
case "few_shot": {
|
|
140
|
-
const { FewShotPromptTemplate } = await import("./few_shot.js");
|
|
141
|
-
return FewShotPromptTemplate.deserialize(data);
|
|
142
|
-
}
|
|
143
|
-
default:
|
|
144
|
-
throw new Error(`Invalid prompt type in config: ${data._type}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Base class for string prompt templates. It extends the
|
|
150
|
-
* BasePromptTemplate class and overrides the formatPromptValue method to
|
|
151
|
-
* return a StringPromptValue.
|
|
152
|
-
*/
|
|
153
|
-
export class BaseStringPromptTemplate extends BasePromptTemplate {
|
|
154
|
-
/**
|
|
155
|
-
* Formats the prompt given the input values and returns a formatted
|
|
156
|
-
* prompt value.
|
|
157
|
-
* @param values The input values to format the prompt.
|
|
158
|
-
* @returns A Promise that resolves to a formatted prompt value.
|
|
159
|
-
*/
|
|
160
|
-
async formatPromptValue(values) {
|
|
161
|
-
const formattedPrompt = await this.format(values);
|
|
162
|
-
return new StringPromptValue(formattedPrompt);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Base class for example selectors.
|
|
167
|
-
*/
|
|
168
|
-
export class BaseExampleSelector extends Serializable {
|
|
169
|
-
constructor() {
|
|
170
|
-
super(...arguments);
|
|
171
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
configurable: true,
|
|
174
|
-
writable: true,
|
|
175
|
-
value: ["langchain", "prompts", "selectors"]
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
1
|
+
export { BaseStringPromptTemplate, BasePromptTemplate, } from "langchain-core/prompts";
|
|
2
|
+
export { StringPromptValue } from "langchain-core/prompt_values";
|
|
3
|
+
export { BaseExampleSelector } from "langchain-core/example_selectors";
|