langchain 0.1.1 → 0.1.2
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/agent.cjs +1 -1
- package/dist/agents/agent.d.ts +1 -1
- package/dist/agents/agent.js +1 -1
- package/dist/chains/openai_functions/index.d.ts +1 -1
- package/dist/evaluation/agents/trajectory.d.ts +2 -2
- package/dist/evaluation/base.d.ts +7 -6
- package/dist/evaluation/comparison/pairwise.d.ts +2 -2
- package/dist/evaluation/criteria/criteria.d.ts +2 -2
- package/dist/experimental/chat_models/ollama_functions.d.ts +1 -0
- package/dist/experimental/prompts/custom_format.cjs +68 -0
- package/dist/experimental/prompts/custom_format.d.ts +24 -0
- package/dist/experimental/prompts/custom_format.js +64 -0
- package/dist/experimental/prompts/handlebars.cjs +71 -0
- package/dist/experimental/prompts/handlebars.d.ts +13 -0
- package/dist/experimental/prompts/handlebars.js +62 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- 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/output_parsers/datetime.cjs +63 -0
- package/dist/output_parsers/datetime.d.ts +27 -0
- package/dist/output_parsers/datetime.js +59 -0
- package/dist/output_parsers/index.cjs +3 -1
- package/dist/output_parsers/index.d.ts +1 -0
- package/dist/output_parsers/index.js +1 -0
- package/dist/output_parsers/openai_functions.cjs +8 -3
- package/dist/output_parsers/openai_functions.d.ts +3 -0
- package/dist/output_parsers/openai_functions.js +8 -3
- package/dist/output_parsers/openai_tools.cjs +18 -5
- package/dist/output_parsers/openai_tools.d.ts +4 -0
- package/dist/output_parsers/openai_tools.js +18 -5
- package/experimental/prompts/custom_format.cjs +1 -0
- package/experimental/prompts/custom_format.d.ts +1 -0
- package/experimental/prompts/custom_format.js +1 -0
- package/experimental/prompts/handlebars.cjs +1 -0
- package/experimental/prompts/handlebars.d.ts +1 -0
- package/experimental/prompts/handlebars.js +1 -0
- package/package.json +24 -2
package/dist/agents/agent.cjs
CHANGED
|
@@ -82,7 +82,7 @@ function isAgentAction(input) {
|
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Class representing a single action agent which accepts runnables.
|
|
85
|
-
* Extends the
|
|
85
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
86
86
|
* planning agent actions with runnables.
|
|
87
87
|
*/
|
|
88
88
|
class RunnableAgent extends BaseMultiActionAgent {
|
package/dist/agents/agent.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export declare abstract class BaseMultiActionAgent extends BaseAgent {
|
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Class representing a single action agent which accepts runnables.
|
|
80
|
-
* Extends the
|
|
80
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
81
81
|
* planning agent actions with runnables.
|
|
82
82
|
*/
|
|
83
83
|
export declare class RunnableAgent extends BaseMultiActionAgent {
|
package/dist/agents/agent.js
CHANGED
|
@@ -76,7 +76,7 @@ function isAgentAction(input) {
|
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* Class representing a single action agent which accepts runnables.
|
|
79
|
-
* Extends the
|
|
79
|
+
* Extends the BaseMultiActionAgent class and provides methods for
|
|
80
80
|
* planning agent actions with runnables.
|
|
81
81
|
*/
|
|
82
82
|
export class RunnableAgent extends BaseMultiActionAgent {
|
|
@@ -2,4 +2,4 @@ export { createExtractionChain, createExtractionChainFromZod, } from "./extracti
|
|
|
2
2
|
export { type TaggingChainOptions, createTaggingChain, createTaggingChainFromZod, } from "./tagging.js";
|
|
3
3
|
export { type OpenAPIChainOptions, createOpenAPIChain } from "./openapi.js";
|
|
4
4
|
export { type StructuredOutputChainInput, createStructuredOutputChain, createStructuredOutputChainFromZod, } from "./structured_output.js";
|
|
5
|
-
export { createStructuredOutputRunnable, createOpenAIFnRunnable, } from "./base.js";
|
|
5
|
+
export { type CreateStructuredOutputRunnableConfig, createStructuredOutputRunnable, type CreateOpenAIFnRunnableConfig, createOpenAIFnRunnable, } from "./base.js";
|
|
@@ -6,7 +6,7 @@ import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
|
6
6
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
7
7
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
8
8
|
import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
9
|
-
import { AgentTrajectoryEvaluator, EvalOutputType, LLMEvalChainInput, LLMTrajectoryEvaluatorArgs } from "../base.js";
|
|
9
|
+
import { AgentTrajectoryEvaluator, EvalOutputType, LLMEvalChainInput, LLMTrajectoryEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
10
10
|
/**
|
|
11
11
|
* A parser for the output of the TrajectoryEvalChain.
|
|
12
12
|
*/
|
|
@@ -51,5 +51,5 @@ export declare class TrajectoryEvalChain extends AgentTrajectoryEvaluator {
|
|
|
51
51
|
*/
|
|
52
52
|
getAgentTrajectory(steps: AgentStep[]): string;
|
|
53
53
|
formatReference(reference?: string): string;
|
|
54
|
-
_evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions: this["llm"]
|
|
54
|
+
_evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
55
55
|
}
|
|
@@ -8,6 +8,7 @@ import { BaseChain, LLMChain, LLMChainInput } from "../chains/index.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export interface LLMEvalChainInput<T extends EvalOutputType = EvalOutputType, L extends BaseLanguageModelInterface = BaseLanguageModelInterface> extends LLMChainInput<T, L> {
|
|
10
10
|
}
|
|
11
|
+
export type ExtractLLMCallOptions<LanguageModelInterface> = LanguageModelInterface extends BaseLanguageModelInterface<any, infer CallOptions> ? CallOptions : never;
|
|
11
12
|
/**
|
|
12
13
|
* Compare two sets for equality
|
|
13
14
|
*
|
|
@@ -113,7 +114,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
113
114
|
* @param callOptions
|
|
114
115
|
* @param config
|
|
115
116
|
*/
|
|
116
|
-
abstract _evaluateStrings(args: StringEvaluatorArgs, callOptions?: this["llm"]
|
|
117
|
+
abstract _evaluateStrings(args: StringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
117
118
|
/**
|
|
118
119
|
* Evaluate Chain or LLM output, based on optional input and label.
|
|
119
120
|
* @returns The evaluation results containing the score or value. It is recommended that the dictionary contain the following keys:
|
|
@@ -124,7 +125,7 @@ export declare abstract class LLMStringEvaluator<T extends EvalOutputType = Eval
|
|
|
124
125
|
* @param callOptions
|
|
125
126
|
* @param config
|
|
126
127
|
*/
|
|
127
|
-
evaluateStrings(args: StringEvaluatorArgs, callOptions?: this["llm"]
|
|
128
|
+
evaluateStrings(args: StringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Grade, tag, or otherwise evaluate predictions relative to their inputs
|
|
@@ -194,7 +195,7 @@ export declare abstract class LLMPairwiseStringEvaluator extends LLMEvalChain {
|
|
|
194
195
|
* @param config
|
|
195
196
|
* @return A dictionary containing the preference, scores, and/or other information.
|
|
196
197
|
*/
|
|
197
|
-
abstract _evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: this["llm"]
|
|
198
|
+
abstract _evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
198
199
|
/**
|
|
199
200
|
* Evaluate the output string pairs.
|
|
200
201
|
* @param args
|
|
@@ -202,7 +203,7 @@ export declare abstract class LLMPairwiseStringEvaluator extends LLMEvalChain {
|
|
|
202
203
|
* @param config
|
|
203
204
|
* @return A dictionary containing the preference, scores, and/or other information.
|
|
204
205
|
*/
|
|
205
|
-
evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: this["llm"]
|
|
206
|
+
evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
206
207
|
}
|
|
207
208
|
/**
|
|
208
209
|
* Interface for evaluating agent trajectories.
|
|
@@ -220,7 +221,7 @@ export declare abstract class AgentTrajectoryEvaluator extends LLMEvalChain {
|
|
|
220
221
|
* @param callOptions
|
|
221
222
|
* @param config
|
|
222
223
|
*/
|
|
223
|
-
abstract _evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: this["llm"]
|
|
224
|
+
abstract _evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
224
225
|
/**
|
|
225
226
|
* Evaluate a trajectory.
|
|
226
227
|
* @return The evaluation result.
|
|
@@ -228,5 +229,5 @@ export declare abstract class AgentTrajectoryEvaluator extends LLMEvalChain {
|
|
|
228
229
|
* @param callOptions
|
|
229
230
|
* @param config
|
|
230
231
|
*/
|
|
231
|
-
evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: this["llm"]
|
|
232
|
+
evaluateAgentTrajectory(args: LLMTrajectoryEvaluatorArgs, callOptions?: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
232
233
|
}
|
|
@@ -4,7 +4,7 @@ import { ChainValues } from "@langchain/core/utils/types";
|
|
|
4
4
|
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
5
5
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
7
|
-
import { EvalOutputType, LLMEvalChainInput, LLMPairwiseStringEvaluator, LLMPairwiseStringEvaluatorArgs } from "../base.js";
|
|
7
|
+
import { EvalOutputType, LLMEvalChainInput, LLMPairwiseStringEvaluator, LLMPairwiseStringEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
8
8
|
import { CriteriaLike } from "../criteria/criteria.js";
|
|
9
9
|
/**
|
|
10
10
|
* A parser for the output of the PairwiseStringEvalChain.
|
|
@@ -36,7 +36,7 @@ export declare class PairwiseStringEvalChain extends LLMPairwiseStringEvaluator
|
|
|
36
36
|
*/
|
|
37
37
|
static fromLLM(llm: BaseLanguageModelInterface, criteria?: CriteriaLike, chainOptions?: Partial<Omit<LLMEvalChainInput, "llm">>): Promise<PairwiseStringEvalChain>;
|
|
38
38
|
_prepareOutput(result: ChainValues): any;
|
|
39
|
-
_evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions: this["llm"]
|
|
39
|
+
_evaluateStringPairs(args: LLMPairwiseStringEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* A chain for comparing two outputs, such as the outputs
|
|
@@ -4,7 +4,7 @@ import { ChainValues } from "@langchain/core/utils/types";
|
|
|
4
4
|
import { ChatGeneration, Generation } from "@langchain/core/outputs";
|
|
5
5
|
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
6
6
|
import { Callbacks, BaseCallbackConfig } from "@langchain/core/callbacks/manager";
|
|
7
|
-
import { EvalOutputType, LLMEvalChainInput, LLMStringEvaluator, StringEvaluatorArgs } from "../base.js";
|
|
7
|
+
import { EvalOutputType, LLMEvalChainInput, LLMStringEvaluator, StringEvaluatorArgs, type ExtractLLMCallOptions } from "../base.js";
|
|
8
8
|
import { ConstitutionalPrinciple } from "../../chains/constitutional_ai/constitutional_principle.js";
|
|
9
9
|
/**
|
|
10
10
|
* A Criteria to evaluate.
|
|
@@ -61,7 +61,7 @@ export declare class CriteriaEvalChain extends LLMStringEvaluator {
|
|
|
61
61
|
* @param result
|
|
62
62
|
*/
|
|
63
63
|
_prepareOutput(result: ChainValues): any;
|
|
64
|
-
_evaluateStrings(args: StringEvaluatorArgs, callOptions: this["llm"]
|
|
64
|
+
_evaluateStrings(args: StringEvaluatorArgs, callOptions: ExtractLLMCallOptions<this["llm"]>, config?: Callbacks | BaseCallbackConfig): Promise<ChainValues>;
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Criteria evaluation chain that requires references.
|
|
@@ -49,6 +49,7 @@ export declare class OllamaFunctions extends BaseChatModel<ChatOllamaFunctionsCa
|
|
|
49
49
|
num_gpu: number | undefined;
|
|
50
50
|
num_gqa: number | undefined;
|
|
51
51
|
num_keep: number | undefined;
|
|
52
|
+
num_predict: number | undefined;
|
|
52
53
|
num_thread: number | undefined;
|
|
53
54
|
penalize_newline: boolean | undefined;
|
|
54
55
|
presence_penalty: number | undefined;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomFormatPromptTemplate = void 0;
|
|
4
|
+
const prompts_1 = require("@langchain/core/prompts");
|
|
5
|
+
class CustomFormatPromptTemplate extends prompts_1.PromptTemplate {
|
|
6
|
+
static lc_name() {
|
|
7
|
+
return "CustomPromptTemplate";
|
|
8
|
+
}
|
|
9
|
+
constructor(input) {
|
|
10
|
+
super(input);
|
|
11
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: false
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "templateValidator", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "renderer", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.assign(this, input);
|
|
30
|
+
if (this.validateTemplate && this.templateValidator !== undefined) {
|
|
31
|
+
let totalInputVariables = this.inputVariables;
|
|
32
|
+
if (this.partialVariables) {
|
|
33
|
+
totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
|
|
34
|
+
}
|
|
35
|
+
this.templateValidator(this.template, totalInputVariables);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Load prompt template from a template
|
|
40
|
+
*/
|
|
41
|
+
static fromTemplate(template, { customParser, ...rest }) {
|
|
42
|
+
const names = new Set();
|
|
43
|
+
const nodes = customParser(template);
|
|
44
|
+
for (const node of nodes) {
|
|
45
|
+
if (node.type === "variable") {
|
|
46
|
+
names.add(node.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
50
|
+
return new this({
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
+
inputVariables: [...names],
|
|
53
|
+
template,
|
|
54
|
+
customParser,
|
|
55
|
+
...rest,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Formats the prompt template with the provided values.
|
|
60
|
+
* @param values The values to be used to format the prompt template.
|
|
61
|
+
* @returns A promise that resolves to a string which is the formatted prompt.
|
|
62
|
+
*/
|
|
63
|
+
async format(values) {
|
|
64
|
+
const allValues = await this.mergePartialAndUserVariables(values);
|
|
65
|
+
return this.renderer(this.template, allValues);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.CustomFormatPromptTemplate = CustomFormatPromptTemplate;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InputValues } from "@langchain/core/utils/types";
|
|
2
|
+
import { type ParsedFStringNode, PromptTemplate, type PromptTemplateInput, TypedPromptInputValues } from "@langchain/core/prompts";
|
|
3
|
+
export type CustomFormatPromptTemplateInput<RunInput extends InputValues> = Omit<PromptTemplateInput<RunInput, string>, "templateFormat"> & {
|
|
4
|
+
customParser: (template: string) => ParsedFStringNode[];
|
|
5
|
+
templateValidator?: (template: string, inputVariables: string[]) => boolean;
|
|
6
|
+
renderer: (template: string, values: InputValues) => string;
|
|
7
|
+
};
|
|
8
|
+
export declare class CustomFormatPromptTemplate<RunInput extends InputValues = any, PartialVariableName extends string = any> extends PromptTemplate<RunInput, PartialVariableName> {
|
|
9
|
+
static lc_name(): string;
|
|
10
|
+
lc_serializable: boolean;
|
|
11
|
+
templateValidator?: (template: string, inputVariables: string[]) => boolean;
|
|
12
|
+
renderer: (template: string, values: InputValues) => string;
|
|
13
|
+
constructor(input: CustomFormatPromptTemplateInput<RunInput>);
|
|
14
|
+
/**
|
|
15
|
+
* Load prompt template from a template
|
|
16
|
+
*/
|
|
17
|
+
static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, { customParser, ...rest }: Omit<CustomFormatPromptTemplateInput<RunInput>, "template" | "inputVariables">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;
|
|
18
|
+
/**
|
|
19
|
+
* Formats the prompt template with the provided values.
|
|
20
|
+
* @param values The values to be used to format the prompt template.
|
|
21
|
+
* @returns A promise that resolves to a string which is the formatted prompt.
|
|
22
|
+
*/
|
|
23
|
+
format(values: TypedPromptInputValues<RunInput>): Promise<string>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { PromptTemplate, } from "@langchain/core/prompts";
|
|
2
|
+
export class CustomFormatPromptTemplate extends PromptTemplate {
|
|
3
|
+
static lc_name() {
|
|
4
|
+
return "CustomPromptTemplate";
|
|
5
|
+
}
|
|
6
|
+
constructor(input) {
|
|
7
|
+
super(input);
|
|
8
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: false
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "templateValidator", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(this, "renderer", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: void 0
|
|
25
|
+
});
|
|
26
|
+
Object.assign(this, input);
|
|
27
|
+
if (this.validateTemplate && this.templateValidator !== undefined) {
|
|
28
|
+
let totalInputVariables = this.inputVariables;
|
|
29
|
+
if (this.partialVariables) {
|
|
30
|
+
totalInputVariables = totalInputVariables.concat(Object.keys(this.partialVariables));
|
|
31
|
+
}
|
|
32
|
+
this.templateValidator(this.template, totalInputVariables);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load prompt template from a template
|
|
37
|
+
*/
|
|
38
|
+
static fromTemplate(template, { customParser, ...rest }) {
|
|
39
|
+
const names = new Set();
|
|
40
|
+
const nodes = customParser(template);
|
|
41
|
+
for (const node of nodes) {
|
|
42
|
+
if (node.type === "variable") {
|
|
43
|
+
names.add(node.name);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
47
|
+
return new this({
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
inputVariables: [...names],
|
|
50
|
+
template,
|
|
51
|
+
customParser,
|
|
52
|
+
...rest,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Formats the prompt template with the provided values.
|
|
57
|
+
* @param values The values to be used to format the prompt template.
|
|
58
|
+
* @returns A promise that resolves to a string which is the formatted prompt.
|
|
59
|
+
*/
|
|
60
|
+
async format(values) {
|
|
61
|
+
const allValues = await this.mergePartialAndUserVariables(values);
|
|
62
|
+
return this.renderer(this.template, allValues);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HandlebarsPromptTemplate = exports.interpolateHandlebars = exports.parseHandlebars = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const custom_format_js_1 = require("./custom_format.cjs");
|
|
9
|
+
const parseHandlebars = (template) => {
|
|
10
|
+
const parsed = [];
|
|
11
|
+
const nodes = [...handlebars_1.default.parse(template).body];
|
|
12
|
+
while (nodes.length) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
14
|
+
const node = nodes.pop();
|
|
15
|
+
if (node.type === "ContentStatement") {
|
|
16
|
+
// @ts-expect-error - handlebars' hbs.AST.ContentStatement isn't exported
|
|
17
|
+
const text = node.value;
|
|
18
|
+
parsed.push({ type: "literal", text });
|
|
19
|
+
}
|
|
20
|
+
else if (node.type === "MustacheStatement") {
|
|
21
|
+
// @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
|
|
22
|
+
const name = node.path.parts[0];
|
|
23
|
+
// @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
|
|
24
|
+
const { original } = node.path;
|
|
25
|
+
if (!!name &&
|
|
26
|
+
!original.startsWith("this.") &&
|
|
27
|
+
!original.startsWith("@")) {
|
|
28
|
+
parsed.push({ type: "variable", name });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (node.type === "PathExpression") {
|
|
32
|
+
// @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
|
|
33
|
+
const name = node.parts[0];
|
|
34
|
+
// @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
|
|
35
|
+
const { original } = node;
|
|
36
|
+
if (!!name &&
|
|
37
|
+
!original.startsWith("this.") &&
|
|
38
|
+
!original.startsWith("@")) {
|
|
39
|
+
parsed.push({ type: "variable", name });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (node.type === "BlockStatement") {
|
|
43
|
+
// @ts-expect-error - handlebars' hbs.AST.BlockStatement isn't exported
|
|
44
|
+
nodes.push(...node.params, ...node.program.body);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return parsed;
|
|
48
|
+
};
|
|
49
|
+
exports.parseHandlebars = parseHandlebars;
|
|
50
|
+
const interpolateHandlebars = (template, values) => {
|
|
51
|
+
const compiled = handlebars_1.default.compile(template, { noEscape: true });
|
|
52
|
+
return compiled(values);
|
|
53
|
+
};
|
|
54
|
+
exports.interpolateHandlebars = interpolateHandlebars;
|
|
55
|
+
class HandlebarsPromptTemplate extends custom_format_js_1.CustomFormatPromptTemplate {
|
|
56
|
+
static lc_name() {
|
|
57
|
+
return "HandlebarsPromptTemplate";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load prompt template from a template
|
|
61
|
+
*/
|
|
62
|
+
static fromTemplate(template, params) {
|
|
63
|
+
return super.fromTemplate(template, {
|
|
64
|
+
...params,
|
|
65
|
+
validateTemplate: false,
|
|
66
|
+
customParser: exports.parseHandlebars,
|
|
67
|
+
renderer: exports.interpolateHandlebars,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.HandlebarsPromptTemplate = HandlebarsPromptTemplate;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ParsedFStringNode } from "@langchain/core/prompts";
|
|
2
|
+
import type { InputValues } from "@langchain/core/utils/types";
|
|
3
|
+
import { CustomFormatPromptTemplate, CustomFormatPromptTemplateInput } from "./custom_format.js";
|
|
4
|
+
export declare const parseHandlebars: (template: string) => ParsedFStringNode[];
|
|
5
|
+
export declare const interpolateHandlebars: (template: string, values: InputValues) => string;
|
|
6
|
+
export type HandlebarsPromptTemplateInput<RunInput extends InputValues> = CustomFormatPromptTemplateInput<RunInput>;
|
|
7
|
+
export declare class HandlebarsPromptTemplate<RunInput extends InputValues = any> extends CustomFormatPromptTemplate<RunInput> {
|
|
8
|
+
static lc_name(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Load prompt template from a template
|
|
11
|
+
*/
|
|
12
|
+
static fromTemplate<RunInput extends InputValues = Record<string, any>>(template: string, params?: Omit<HandlebarsPromptTemplateInput<RunInput>, "template" | "inputVariables" | "customParser" | "templateValidator" | "renderer">): CustomFormatPromptTemplate<RunInput extends Symbol ? never : RunInput, any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Handlebars from "handlebars";
|
|
2
|
+
import { CustomFormatPromptTemplate, } from "./custom_format.js";
|
|
3
|
+
export const parseHandlebars = (template) => {
|
|
4
|
+
const parsed = [];
|
|
5
|
+
const nodes = [...Handlebars.parse(template).body];
|
|
6
|
+
while (nodes.length) {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
|
+
const node = nodes.pop();
|
|
9
|
+
if (node.type === "ContentStatement") {
|
|
10
|
+
// @ts-expect-error - handlebars' hbs.AST.ContentStatement isn't exported
|
|
11
|
+
const text = node.value;
|
|
12
|
+
parsed.push({ type: "literal", text });
|
|
13
|
+
}
|
|
14
|
+
else if (node.type === "MustacheStatement") {
|
|
15
|
+
// @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
|
|
16
|
+
const name = node.path.parts[0];
|
|
17
|
+
// @ts-expect-error - handlebars' hbs.AST.MustacheStatement isn't exported
|
|
18
|
+
const { original } = node.path;
|
|
19
|
+
if (!!name &&
|
|
20
|
+
!original.startsWith("this.") &&
|
|
21
|
+
!original.startsWith("@")) {
|
|
22
|
+
parsed.push({ type: "variable", name });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (node.type === "PathExpression") {
|
|
26
|
+
// @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
|
|
27
|
+
const name = node.parts[0];
|
|
28
|
+
// @ts-expect-error - handlebars' hbs.AST.PathExpression isn't exported
|
|
29
|
+
const { original } = node;
|
|
30
|
+
if (!!name &&
|
|
31
|
+
!original.startsWith("this.") &&
|
|
32
|
+
!original.startsWith("@")) {
|
|
33
|
+
parsed.push({ type: "variable", name });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (node.type === "BlockStatement") {
|
|
37
|
+
// @ts-expect-error - handlebars' hbs.AST.BlockStatement isn't exported
|
|
38
|
+
nodes.push(...node.params, ...node.program.body);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return parsed;
|
|
42
|
+
};
|
|
43
|
+
export const interpolateHandlebars = (template, values) => {
|
|
44
|
+
const compiled = Handlebars.compile(template, { noEscape: true });
|
|
45
|
+
return compiled(values);
|
|
46
|
+
};
|
|
47
|
+
export class HandlebarsPromptTemplate extends CustomFormatPromptTemplate {
|
|
48
|
+
static lc_name() {
|
|
49
|
+
return "HandlebarsPromptTemplate";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Load prompt template from a template
|
|
53
|
+
*/
|
|
54
|
+
static fromTemplate(template, params) {
|
|
55
|
+
return super.fromTemplate(template, {
|
|
56
|
+
...params,
|
|
57
|
+
validateTemplate: false,
|
|
58
|
+
customParser: parseHandlebars,
|
|
59
|
+
renderer: interpolateHandlebars,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -175,5 +175,6 @@ exports.optionalImportEntrypoints = [
|
|
|
175
175
|
"langchain/experimental/chat_models/anthropic_functions",
|
|
176
176
|
"langchain/experimental/llms/bittensor",
|
|
177
177
|
"langchain/experimental/hubs/makersuite/googlemakersuitehub",
|
|
178
|
+
"langchain/experimental/prompts/handlebars",
|
|
178
179
|
"langchain/experimental/tools/pyinterpreter",
|
|
179
180
|
];
|
|
@@ -172,5 +172,6 @@ export const optionalImportEntrypoints = [
|
|
|
172
172
|
"langchain/experimental/chat_models/anthropic_functions",
|
|
173
173
|
"langchain/experimental/llms/bittensor",
|
|
174
174
|
"langchain/experimental/hubs/makersuite/googlemakersuitehub",
|
|
175
|
+
"langchain/experimental/prompts/handlebars",
|
|
175
176
|
"langchain/experimental/tools/pyinterpreter",
|
|
176
177
|
];
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__remote = exports.output_parsers = exports.schema__query_constructor = exports.schema__prompt_template = exports.chat_models__anthropic = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.text_splitter = exports.vectorstores__memory = exports.llms__fake = exports.embeddings__fake = exports.embeddings__cache_backed = exports.chains__retrieval = exports.chains__openai_functions = exports.chains__history_aware_retriever = exports.chains__combine_documents__reduce = exports.chains__combine_documents = exports.chains = exports.tools__retriever = exports.tools__render = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad__openai_tools = exports.agents__format_scratchpad = exports.agents__toolkits = exports.agents = void 0;
|
|
28
|
-
exports.llms__fireworks = exports.chat_models__fireworks = exports.schema__output = exports.schema__output_parser = exports.schema__runnable = exports.prompts__base = exports.prompts__pipeline = exports.prompts__chat = exports.schema__messages = exports.prompts__prompt = exports.embeddings__openai = exports.llms__openai = exports.chat_models__openai = exports.runnables__remote = exports.evaluation = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = void 0;
|
|
28
|
+
exports.llms__fireworks = exports.chat_models__fireworks = exports.schema__output = exports.schema__output_parser = exports.schema__runnable = exports.prompts__base = exports.prompts__pipeline = exports.prompts__chat = exports.schema__messages = exports.prompts__prompt = exports.embeddings__openai = exports.llms__openai = exports.chat_models__openai = exports.runnables__remote = exports.evaluation = exports.experimental__prompts__custom_format = exports.experimental__masking = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = void 0;
|
|
29
29
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
30
30
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
31
31
|
exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad/openai_functions.cjs"));
|
|
@@ -87,6 +87,7 @@ exports.experimental__plan_and_execute = __importStar(require("../experimental/p
|
|
|
87
87
|
exports.experimental__chat_models__bittensor = __importStar(require("../experimental/chat_models/bittensor.cjs"));
|
|
88
88
|
exports.experimental__chains__violation_of_expectations = __importStar(require("../experimental/chains/violation_of_expectations/index.cjs"));
|
|
89
89
|
exports.experimental__masking = __importStar(require("../experimental/masking/index.cjs"));
|
|
90
|
+
exports.experimental__prompts__custom_format = __importStar(require("../experimental/prompts/custom_format.cjs"));
|
|
90
91
|
exports.evaluation = __importStar(require("../evaluation/index.cjs"));
|
|
91
92
|
exports.runnables__remote = __importStar(require("../runnables/remote.cjs"));
|
|
92
93
|
const openai_1 = require("@langchain/openai");
|
|
@@ -59,6 +59,7 @@ export * as experimental__plan_and_execute from "../experimental/plan_and_execut
|
|
|
59
59
|
export * as experimental__chat_models__bittensor from "../experimental/chat_models/bittensor.js";
|
|
60
60
|
export * as experimental__chains__violation_of_expectations from "../experimental/chains/violation_of_expectations/index.js";
|
|
61
61
|
export * as experimental__masking from "../experimental/masking/index.js";
|
|
62
|
+
export * as experimental__prompts__custom_format from "../experimental/prompts/custom_format.js";
|
|
62
63
|
export * as evaluation from "../evaluation/index.js";
|
|
63
64
|
export * as runnables__remote from "../runnables/remote.js";
|
|
64
65
|
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
package/dist/load/import_map.js
CHANGED
|
@@ -60,6 +60,7 @@ export * as experimental__plan_and_execute from "../experimental/plan_and_execut
|
|
|
60
60
|
export * as experimental__chat_models__bittensor from "../experimental/chat_models/bittensor.js";
|
|
61
61
|
export * as experimental__chains__violation_of_expectations from "../experimental/chains/violation_of_expectations/index.js";
|
|
62
62
|
export * as experimental__masking from "../experimental/masking/index.js";
|
|
63
|
+
export * as experimental__prompts__custom_format from "../experimental/prompts/custom_format.js";
|
|
63
64
|
export * as evaluation from "../evaluation/index.js";
|
|
64
65
|
export * as runnables__remote from "../runnables/remote.js";
|
|
65
66
|
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatetimeOutputParser = void 0;
|
|
4
|
+
const output_parsers_1 = require("@langchain/core/output_parsers");
|
|
5
|
+
/**
|
|
6
|
+
* Class to parse the output of an LLM call to a date.
|
|
7
|
+
* @augments BaseOutputParser
|
|
8
|
+
*/
|
|
9
|
+
class DatetimeOutputParser extends output_parsers_1.BaseOutputParser {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ["langchain", "output_parsers"]
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* ISO 8601 date time standard.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(this, "format", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: "YYYY-MM-DDTHH:mm:ssZ"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
static lc_name() {
|
|
35
|
+
return "DatetimeOutputParser";
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Parses the given text into a Date.
|
|
39
|
+
* If the parsing fails, throws an OutputParserException.
|
|
40
|
+
* @param text The text to parse.
|
|
41
|
+
* @returns A date object.
|
|
42
|
+
*/
|
|
43
|
+
async parse(text) {
|
|
44
|
+
const parsedDate = new Date(text.trim());
|
|
45
|
+
if (Number.isNaN(parsedDate.getTime())) {
|
|
46
|
+
throw new output_parsers_1.OutputParserException(`Could not parse output: ${text}`, text);
|
|
47
|
+
}
|
|
48
|
+
return parsedDate;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Provides instructions on the expected format of the response for the
|
|
52
|
+
* CommaSeparatedListOutputParser.
|
|
53
|
+
* @returns A string containing instructions on the expected format of the response.
|
|
54
|
+
*/
|
|
55
|
+
getFormatInstructions() {
|
|
56
|
+
return [
|
|
57
|
+
`Your response should be a datetime string that matches the following pattern: "${this.format}".`,
|
|
58
|
+
`Examples: 2011-10-05T14:48:00Z, 2019-01-01T00:00:00Z, 1932-04-21T04:42:23Z`,
|
|
59
|
+
`Return ONLY this string, no other words!`,
|
|
60
|
+
].join("\n\n");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.DatetimeOutputParser = DatetimeOutputParser;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BaseOutputParser } from "@langchain/core/output_parsers";
|
|
2
|
+
/**
|
|
3
|
+
* Class to parse the output of an LLM call to a date.
|
|
4
|
+
* @augments BaseOutputParser
|
|
5
|
+
*/
|
|
6
|
+
export declare class DatetimeOutputParser extends BaseOutputParser<Date> {
|
|
7
|
+
static lc_name(): string;
|
|
8
|
+
lc_namespace: string[];
|
|
9
|
+
lc_serializable: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* ISO 8601 date time standard.
|
|
12
|
+
*/
|
|
13
|
+
format: string;
|
|
14
|
+
/**
|
|
15
|
+
* Parses the given text into a Date.
|
|
16
|
+
* If the parsing fails, throws an OutputParserException.
|
|
17
|
+
* @param text The text to parse.
|
|
18
|
+
* @returns A date object.
|
|
19
|
+
*/
|
|
20
|
+
parse(text: string): Promise<Date>;
|
|
21
|
+
/**
|
|
22
|
+
* Provides instructions on the expected format of the response for the
|
|
23
|
+
* CommaSeparatedListOutputParser.
|
|
24
|
+
* @returns A string containing instructions on the expected format of the response.
|
|
25
|
+
*/
|
|
26
|
+
getFormatInstructions(): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BaseOutputParser, OutputParserException, } from "@langchain/core/output_parsers";
|
|
2
|
+
/**
|
|
3
|
+
* Class to parse the output of an LLM call to a date.
|
|
4
|
+
* @augments BaseOutputParser
|
|
5
|
+
*/
|
|
6
|
+
export class DatetimeOutputParser extends BaseOutputParser {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: ["langchain", "output_parsers"]
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: true
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* ISO 8601 date time standard.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(this, "format", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: "YYYY-MM-DDTHH:mm:ssZ"
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
static lc_name() {
|
|
32
|
+
return "DatetimeOutputParser";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Parses the given text into a Date.
|
|
36
|
+
* If the parsing fails, throws an OutputParserException.
|
|
37
|
+
* @param text The text to parse.
|
|
38
|
+
* @returns A date object.
|
|
39
|
+
*/
|
|
40
|
+
async parse(text) {
|
|
41
|
+
const parsedDate = new Date(text.trim());
|
|
42
|
+
if (Number.isNaN(parsedDate.getTime())) {
|
|
43
|
+
throw new OutputParserException(`Could not parse output: ${text}`, text);
|
|
44
|
+
}
|
|
45
|
+
return parsedDate;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Provides instructions on the expected format of the response for the
|
|
49
|
+
* CommaSeparatedListOutputParser.
|
|
50
|
+
* @returns A string containing instructions on the expected format of the response.
|
|
51
|
+
*/
|
|
52
|
+
getFormatInstructions() {
|
|
53
|
+
return [
|
|
54
|
+
`Your response should be a datetime string that matches the following pattern: "${this.format}".`,
|
|
55
|
+
`Examples: 2011-10-05T14:48:00Z, 2019-01-01T00:00:00Z, 1932-04-21T04:42:23Z`,
|
|
56
|
+
`Return ONLY this string, no other words!`,
|
|
57
|
+
].join("\n\n");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
3
|
+
exports.DatetimeOutputParser = exports.HttpResponseOutputParser = exports.JsonOutputToolsParser = exports.JsonKeyOutputFunctionsParser = exports.JsonOutputFunctionsParser = exports.OutputFunctionsParser = exports.CustomListOutputParser = exports.RouterOutputParser = exports.CombiningOutputParser = exports.OutputFixingParser = exports.JsonMarkdownStructuredOutputParser = exports.AsymmetricStructuredOutputParser = exports.StructuredOutputParser = exports.RegexParser = exports.CommaSeparatedListOutputParser = exports.ListOutputParser = void 0;
|
|
4
4
|
var list_js_1 = require("./list.cjs");
|
|
5
5
|
Object.defineProperty(exports, "ListOutputParser", { enumerable: true, get: function () { return list_js_1.ListOutputParser; } });
|
|
6
6
|
Object.defineProperty(exports, "CommaSeparatedListOutputParser", { enumerable: true, get: function () { return list_js_1.CommaSeparatedListOutputParser; } });
|
|
@@ -26,3 +26,5 @@ var openai_tools_js_1 = require("../output_parsers/openai_tools.cjs");
|
|
|
26
26
|
Object.defineProperty(exports, "JsonOutputToolsParser", { enumerable: true, get: function () { return openai_tools_js_1.JsonOutputToolsParser; } });
|
|
27
27
|
var http_response_js_1 = require("./http_response.cjs");
|
|
28
28
|
Object.defineProperty(exports, "HttpResponseOutputParser", { enumerable: true, get: function () { return http_response_js_1.HttpResponseOutputParser; } });
|
|
29
|
+
var datetime_js_1 = require("./datetime.cjs");
|
|
30
|
+
Object.defineProperty(exports, "DatetimeOutputParser", { enumerable: true, get: function () { return datetime_js_1.DatetimeOutputParser; } });
|
|
@@ -8,3 +8,4 @@ export { CustomListOutputParser } from "./list.js";
|
|
|
8
8
|
export { type FunctionParameters, OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
|
|
9
9
|
export { type ParsedToolCall, JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
|
|
10
10
|
export { HttpResponseOutputParser, type HttpResponseOutputParserInput, } from "./http_response.js";
|
|
11
|
+
export { DatetimeOutputParser } from "./datetime.js";
|
|
@@ -8,3 +8,4 @@ export { CustomListOutputParser } from "./list.js";
|
|
|
8
8
|
export { OutputFunctionsParser, JsonOutputFunctionsParser, JsonKeyOutputFunctionsParser, } from "../output_parsers/openai_functions.js";
|
|
9
9
|
export { JsonOutputToolsParser, } from "../output_parsers/openai_tools.js";
|
|
10
10
|
export { HttpResponseOutputParser, } from "./http_response.js";
|
|
11
|
+
export { DatetimeOutputParser } from "./datetime.js";
|
|
@@ -18,7 +18,7 @@ class OutputFunctionsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
configurable: true,
|
|
20
20
|
writable: true,
|
|
21
|
-
value: ["langchain", "output_parsers"]
|
|
21
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(this, "lc_serializable", {
|
|
24
24
|
enumerable: true,
|
|
@@ -75,7 +75,7 @@ class JsonOutputFunctionsParser extends output_parsers_1.BaseCumulativeTransform
|
|
|
75
75
|
enumerable: true,
|
|
76
76
|
configurable: true,
|
|
77
77
|
writable: true,
|
|
78
|
-
value: ["langchain", "output_parsers"]
|
|
78
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
79
79
|
});
|
|
80
80
|
Object.defineProperty(this, "lc_serializable", {
|
|
81
81
|
enumerable: true,
|
|
@@ -158,13 +158,18 @@ class JsonKeyOutputFunctionsParser extends output_parsers_1.BaseLLMOutputParser
|
|
|
158
158
|
static lc_name() {
|
|
159
159
|
return "JsonKeyOutputFunctionsParser";
|
|
160
160
|
}
|
|
161
|
+
get lc_aliases() {
|
|
162
|
+
return {
|
|
163
|
+
attrName: "key_name",
|
|
164
|
+
};
|
|
165
|
+
}
|
|
161
166
|
constructor(fields) {
|
|
162
167
|
super(fields);
|
|
163
168
|
Object.defineProperty(this, "lc_namespace", {
|
|
164
169
|
enumerable: true,
|
|
165
170
|
configurable: true,
|
|
166
171
|
writable: true,
|
|
167
|
-
value: ["langchain", "output_parsers"]
|
|
172
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
168
173
|
});
|
|
169
174
|
Object.defineProperty(this, "lc_serializable", {
|
|
170
175
|
enumerable: true,
|
|
@@ -63,6 +63,9 @@ export declare class JsonKeyOutputFunctionsParser<T = object> extends BaseLLMOut
|
|
|
63
63
|
lc_serializable: boolean;
|
|
64
64
|
outputParser: JsonOutputFunctionsParser<object>;
|
|
65
65
|
attrName: string;
|
|
66
|
+
get lc_aliases(): {
|
|
67
|
+
attrName: string;
|
|
68
|
+
};
|
|
66
69
|
constructor(fields: {
|
|
67
70
|
attrName: string;
|
|
68
71
|
});
|
|
@@ -15,7 +15,7 @@ export class OutputFunctionsParser extends BaseLLMOutputParser {
|
|
|
15
15
|
enumerable: true,
|
|
16
16
|
configurable: true,
|
|
17
17
|
writable: true,
|
|
18
|
-
value: ["langchain", "output_parsers"]
|
|
18
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(this, "lc_serializable", {
|
|
21
21
|
enumerable: true,
|
|
@@ -71,7 +71,7 @@ export class JsonOutputFunctionsParser extends BaseCumulativeTransformOutputPars
|
|
|
71
71
|
enumerable: true,
|
|
72
72
|
configurable: true,
|
|
73
73
|
writable: true,
|
|
74
|
-
value: ["langchain", "output_parsers"]
|
|
74
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
75
75
|
});
|
|
76
76
|
Object.defineProperty(this, "lc_serializable", {
|
|
77
77
|
enumerable: true,
|
|
@@ -153,13 +153,18 @@ export class JsonKeyOutputFunctionsParser extends BaseLLMOutputParser {
|
|
|
153
153
|
static lc_name() {
|
|
154
154
|
return "JsonKeyOutputFunctionsParser";
|
|
155
155
|
}
|
|
156
|
+
get lc_aliases() {
|
|
157
|
+
return {
|
|
158
|
+
attrName: "key_name",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
156
161
|
constructor(fields) {
|
|
157
162
|
super(fields);
|
|
158
163
|
Object.defineProperty(this, "lc_namespace", {
|
|
159
164
|
enumerable: true,
|
|
160
165
|
configurable: true,
|
|
161
166
|
writable: true,
|
|
162
|
-
value: ["langchain", "output_parsers"]
|
|
167
|
+
value: ["langchain", "output_parsers", "openai_functions"]
|
|
163
168
|
});
|
|
164
169
|
Object.defineProperty(this, "lc_serializable", {
|
|
165
170
|
enumerable: true,
|
|
@@ -13,7 +13,7 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
13
13
|
enumerable: true,
|
|
14
14
|
configurable: true,
|
|
15
15
|
writable: true,
|
|
16
|
-
value: ["langchain", "output_parsers"]
|
|
16
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(this, "lc_serializable", {
|
|
19
19
|
enumerable: true,
|
|
@@ -40,11 +40,24 @@ class JsonOutputToolsParser extends output_parsers_1.BaseLLMOutputParser {
|
|
|
40
40
|
const parsedToolCalls = [];
|
|
41
41
|
for (const toolCall of clonedToolCalls) {
|
|
42
42
|
if (toolCall.function !== undefined) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
|
44
|
+
const parsedToolCall = {
|
|
45
|
+
type: toolCall.function.name,
|
|
46
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
47
|
+
};
|
|
48
|
+
// backward-compatibility with previous
|
|
49
|
+
// versions of Langchain JS, which uses `name` and `arguments`
|
|
50
|
+
Object.defineProperty(parsedToolCall, "name", {
|
|
51
|
+
get() {
|
|
52
|
+
return this.type;
|
|
53
|
+
},
|
|
47
54
|
});
|
|
55
|
+
Object.defineProperty(parsedToolCall, "arguments", {
|
|
56
|
+
get() {
|
|
57
|
+
return this.args;
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
parsedToolCalls.push(parsedToolCall);
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
return parsedToolCalls;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BaseLLMOutputParser } from "@langchain/core/output_parsers";
|
|
2
2
|
import type { ChatGeneration } from "@langchain/core/outputs";
|
|
3
3
|
export type ParsedToolCall = {
|
|
4
|
+
type: string;
|
|
5
|
+
args: Record<string, any>;
|
|
6
|
+
/** @deprecated Use `type` instead. Will be removed in 0.2.0. */
|
|
4
7
|
name: string;
|
|
8
|
+
/** @deprecated Use `args` instead. Will be removed in 0.2.0. */
|
|
5
9
|
arguments: Record<string, any>;
|
|
6
10
|
};
|
|
7
11
|
/**
|
|
@@ -10,7 +10,7 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
|
10
10
|
enumerable: true,
|
|
11
11
|
configurable: true,
|
|
12
12
|
writable: true,
|
|
13
|
-
value: ["langchain", "output_parsers"]
|
|
13
|
+
value: ["langchain", "output_parsers", "openai_tools"]
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(this, "lc_serializable", {
|
|
16
16
|
enumerable: true,
|
|
@@ -37,11 +37,24 @@ export class JsonOutputToolsParser extends BaseLLMOutputParser {
|
|
|
37
37
|
const parsedToolCalls = [];
|
|
38
38
|
for (const toolCall of clonedToolCalls) {
|
|
39
39
|
if (toolCall.function !== undefined) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
// @ts-expect-error name and arguemnts are defined by Object.defineProperty
|
|
41
|
+
const parsedToolCall = {
|
|
42
|
+
type: toolCall.function.name,
|
|
43
|
+
args: JSON.parse(toolCall.function.arguments),
|
|
44
|
+
};
|
|
45
|
+
// backward-compatibility with previous
|
|
46
|
+
// versions of Langchain JS, which uses `name` and `arguments`
|
|
47
|
+
Object.defineProperty(parsedToolCall, "name", {
|
|
48
|
+
get() {
|
|
49
|
+
return this.type;
|
|
50
|
+
},
|
|
44
51
|
});
|
|
52
|
+
Object.defineProperty(parsedToolCall, "arguments", {
|
|
53
|
+
get() {
|
|
54
|
+
return this.args;
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
parsedToolCalls.push(parsedToolCall);
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
60
|
return parsedToolCalls;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/experimental/prompts/custom_format.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/prompts/custom_format.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/prompts/custom_format.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/experimental/prompts/handlebars.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/prompts/handlebars.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/experimental/prompts/handlebars.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -853,6 +853,12 @@
|
|
|
853
853
|
"experimental/masking.cjs",
|
|
854
854
|
"experimental/masking.js",
|
|
855
855
|
"experimental/masking.d.ts",
|
|
856
|
+
"experimental/prompts/custom_format.cjs",
|
|
857
|
+
"experimental/prompts/custom_format.js",
|
|
858
|
+
"experimental/prompts/custom_format.d.ts",
|
|
859
|
+
"experimental/prompts/handlebars.cjs",
|
|
860
|
+
"experimental/prompts/handlebars.js",
|
|
861
|
+
"experimental/prompts/handlebars.d.ts",
|
|
856
862
|
"experimental/tools/pyinterpreter.cjs",
|
|
857
863
|
"experimental/tools/pyinterpreter.js",
|
|
858
864
|
"experimental/tools/pyinterpreter.d.ts",
|
|
@@ -919,6 +925,7 @@
|
|
|
919
925
|
"@tsconfig/recommended": "^1.0.2",
|
|
920
926
|
"@types/d3-dsv": "^2",
|
|
921
927
|
"@types/decamelize": "^1.2.0",
|
|
928
|
+
"@types/handlebars": "^4.1.0",
|
|
922
929
|
"@types/html-to-text": "^9",
|
|
923
930
|
"@types/js-yaml": "^4",
|
|
924
931
|
"@types/jsdom": "^21.1.1",
|
|
@@ -949,6 +956,7 @@
|
|
|
949
956
|
"fast-xml-parser": "^4.2.7",
|
|
950
957
|
"google-auth-library": "^8.9.0",
|
|
951
958
|
"googleapis": "^126.0.1",
|
|
959
|
+
"handlebars": "^4.7.8",
|
|
952
960
|
"html-to-text": "^9.0.5",
|
|
953
961
|
"ignore": "^5.2.0",
|
|
954
962
|
"ioredis": "^5.3.2",
|
|
@@ -1008,6 +1016,7 @@
|
|
|
1008
1016
|
"fast-xml-parser": "^4.2.7",
|
|
1009
1017
|
"google-auth-library": "^8.9.0",
|
|
1010
1018
|
"googleapis": "^126.0.1",
|
|
1019
|
+
"handlebars": "^4.7.8",
|
|
1011
1020
|
"html-to-text": "^9.0.5",
|
|
1012
1021
|
"ignore": "^5.2.0",
|
|
1013
1022
|
"ioredis": "^5.3.2",
|
|
@@ -1115,6 +1124,9 @@
|
|
|
1115
1124
|
"googleapis": {
|
|
1116
1125
|
"optional": true
|
|
1117
1126
|
},
|
|
1127
|
+
"handlebars": {
|
|
1128
|
+
"optional": true
|
|
1129
|
+
},
|
|
1118
1130
|
"html-to-text": {
|
|
1119
1131
|
"optional": true
|
|
1120
1132
|
},
|
|
@@ -1191,7 +1203,7 @@
|
|
|
1191
1203
|
"dependencies": {
|
|
1192
1204
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1193
1205
|
"@langchain/community": "~0.0.15",
|
|
1194
|
-
"@langchain/core": "~0.1.
|
|
1206
|
+
"@langchain/core": "~0.1.12",
|
|
1195
1207
|
"@langchain/openai": "~0.0.10",
|
|
1196
1208
|
"binary-extensions": "^2.2.0",
|
|
1197
1209
|
"expr-eval": "^2.0.2",
|
|
@@ -2631,6 +2643,16 @@
|
|
|
2631
2643
|
"import": "./experimental/masking.js",
|
|
2632
2644
|
"require": "./experimental/masking.cjs"
|
|
2633
2645
|
},
|
|
2646
|
+
"./experimental/prompts/custom_format": {
|
|
2647
|
+
"types": "./experimental/prompts/custom_format.d.ts",
|
|
2648
|
+
"import": "./experimental/prompts/custom_format.js",
|
|
2649
|
+
"require": "./experimental/prompts/custom_format.cjs"
|
|
2650
|
+
},
|
|
2651
|
+
"./experimental/prompts/handlebars": {
|
|
2652
|
+
"types": "./experimental/prompts/handlebars.d.ts",
|
|
2653
|
+
"import": "./experimental/prompts/handlebars.js",
|
|
2654
|
+
"require": "./experimental/prompts/handlebars.cjs"
|
|
2655
|
+
},
|
|
2634
2656
|
"./experimental/tools/pyinterpreter": {
|
|
2635
2657
|
"types": "./experimental/tools/pyinterpreter.d.ts",
|
|
2636
2658
|
"import": "./experimental/tools/pyinterpreter.js",
|