langchain 0.0.102 → 0.0.104
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/chains/openai_functions.cjs +1 -0
- package/chains/openai_functions.d.ts +1 -0
- package/chains/openai_functions.js +1 -0
- package/chat_models/baiduwenxin.cjs +1 -0
- package/chat_models/baiduwenxin.d.ts +1 -0
- package/chat_models/baiduwenxin.js +1 -0
- package/dist/agents/agent.d.ts +2 -2
- package/dist/agents/chat_convo/index.cjs +2 -2
- package/dist/agents/chat_convo/index.d.ts +2 -2
- package/dist/agents/chat_convo/index.js +3 -3
- package/dist/agents/openai/index.cjs +4 -4
- package/dist/agents/openai/index.d.ts +2 -2
- package/dist/agents/openai/index.js +5 -5
- package/dist/base_language/index.cjs +8 -1
- package/dist/base_language/index.d.ts +7 -8
- package/dist/base_language/index.js +8 -1
- package/dist/callbacks/base.d.ts +29 -29
- package/dist/callbacks/handlers/tracer.cjs +38 -8
- package/dist/callbacks/handlers/tracer.d.ts +10 -6
- package/dist/callbacks/handlers/tracer.js +39 -9
- package/dist/callbacks/handlers/tracer_langchain.cjs +1 -1
- package/dist/callbacks/handlers/tracer_langchain.d.ts +3 -3
- package/dist/callbacks/handlers/tracer_langchain.js +2 -2
- package/dist/callbacks/manager.cjs +82 -22
- package/dist/callbacks/manager.d.ts +28 -4
- package/dist/callbacks/manager.js +80 -21
- package/dist/chains/base.cjs +26 -14
- package/dist/chains/base.d.ts +7 -4
- package/dist/chains/base.js +27 -15
- package/dist/chains/conversational_retrieval_chain.cjs +3 -3
- package/dist/chains/conversational_retrieval_chain.d.ts +2 -2
- package/dist/chains/conversational_retrieval_chain.js +3 -3
- package/dist/chains/llm_chain.cjs +1 -1
- package/dist/chains/llm_chain.js +1 -1
- package/dist/chains/openai_functions/index.cjs +14 -0
- package/dist/chains/openai_functions/index.d.ts +4 -0
- package/dist/chains/openai_functions/index.js +4 -0
- package/dist/chains/openai_functions/openapi.cjs +28 -10
- package/dist/chains/openai_functions/openapi.js +28 -10
- package/dist/chains/openai_functions/structured_output.cjs +93 -0
- package/dist/chains/openai_functions/structured_output.d.ts +30 -0
- package/dist/chains/openai_functions/structured_output.js +87 -0
- package/dist/chat_models/anthropic.cjs +2 -5
- package/dist/chat_models/anthropic.d.ts +2 -3
- package/dist/chat_models/anthropic.js +3 -6
- package/dist/chat_models/baiduwenxin.cjs +348 -0
- package/dist/chat_models/baiduwenxin.d.ts +114 -0
- package/dist/chat_models/baiduwenxin.js +344 -0
- package/dist/chat_models/base.cjs +13 -5
- package/dist/chat_models/base.d.ts +9 -9
- package/dist/chat_models/base.js +14 -6
- package/dist/chat_models/googlevertexai.cjs +3 -3
- package/dist/chat_models/googlevertexai.d.ts +6 -6
- package/dist/chat_models/googlevertexai.js +4 -4
- package/dist/chat_models/openai.cjs +30 -15
- package/dist/chat_models/openai.d.ts +6 -4
- package/dist/chat_models/openai.js +31 -16
- package/dist/client/langchainplus.cjs +48 -53
- package/dist/client/langchainplus.d.ts +4 -3
- package/dist/client/langchainplus.js +46 -54
- package/dist/document_loaders/web/apify_dataset.cjs +19 -0
- package/dist/document_loaders/web/apify_dataset.d.ts +14 -1
- package/dist/document_loaders/web/apify_dataset.js +19 -0
- package/dist/embeddings/openai.cjs +18 -3
- package/dist/embeddings/openai.d.ts +1 -0
- package/dist/embeddings/openai.js +18 -3
- package/dist/experimental/autogpt/agent.cjs +3 -3
- package/dist/experimental/autogpt/agent.d.ts +2 -2
- package/dist/experimental/autogpt/agent.js +4 -4
- package/dist/experimental/autogpt/prompt.cjs +8 -8
- package/dist/experimental/autogpt/prompt.d.ts +3 -3
- package/dist/experimental/autogpt/prompt.js +9 -9
- package/dist/llms/base.cjs +16 -8
- package/dist/llms/base.d.ts +5 -5
- package/dist/llms/base.js +17 -9
- package/dist/llms/googlevertexai.cjs +3 -1
- package/dist/llms/googlevertexai.js +3 -1
- package/dist/llms/openai-chat.cjs +23 -4
- package/dist/llms/openai-chat.d.ts +1 -0
- package/dist/llms/openai-chat.js +23 -4
- package/dist/llms/openai.cjs +19 -4
- package/dist/llms/openai.d.ts +1 -0
- package/dist/llms/openai.js +19 -4
- package/dist/load/import_map.cjs +3 -1
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/memory/base.cjs +35 -9
- package/dist/memory/base.d.ts +9 -2
- package/dist/memory/base.js +32 -7
- package/dist/memory/chat_memory.cjs +1 -1
- package/dist/memory/chat_memory.js +2 -2
- package/dist/memory/motorhead_memory.cjs +1 -1
- package/dist/memory/motorhead_memory.js +2 -2
- package/dist/memory/summary.cjs +1 -1
- package/dist/memory/summary.d.ts +4 -4
- package/dist/memory/summary.js +2 -2
- package/dist/memory/zep.cjs +4 -4
- package/dist/memory/zep.js +6 -6
- package/dist/output_parsers/combining.cjs +15 -3
- package/dist/output_parsers/combining.d.ts +6 -1
- package/dist/output_parsers/combining.js +15 -3
- package/dist/output_parsers/fix.cjs +6 -0
- package/dist/output_parsers/fix.d.ts +1 -0
- package/dist/output_parsers/fix.js +6 -0
- package/dist/output_parsers/list.cjs +6 -0
- package/dist/output_parsers/list.d.ts +1 -0
- package/dist/output_parsers/list.js +6 -0
- package/dist/output_parsers/regex.cjs +35 -5
- package/dist/output_parsers/regex.d.ts +13 -0
- package/dist/output_parsers/regex.js +35 -5
- package/dist/prompts/base.cjs +1 -1
- package/dist/prompts/base.d.ts +2 -2
- package/dist/prompts/base.js +2 -2
- package/dist/prompts/chat.cjs +3 -3
- package/dist/prompts/chat.d.ts +15 -15
- package/dist/prompts/chat.js +4 -4
- package/dist/prompts/template.cjs +3 -2
- package/dist/prompts/template.js +3 -2
- package/dist/schema/index.cjs +89 -32
- package/dist/schema/index.d.ts +59 -19
- package/dist/schema/index.js +83 -26
- package/dist/stores/message/dynamodb.d.ts +3 -3
- package/dist/stores/message/in_memory.d.ts +4 -4
- package/dist/stores/message/in_memory.js +1 -1
- package/dist/stores/message/momento.d.ts +3 -3
- package/dist/stores/message/redis.d.ts +3 -3
- package/dist/stores/message/redis.js +1 -1
- package/dist/stores/message/upstash_redis.cjs +1 -9
- package/dist/stores/message/upstash_redis.d.ts +3 -3
- package/dist/stores/message/upstash_redis.js +1 -9
- package/dist/stores/message/utils.cjs +8 -7
- package/dist/stores/message/utils.d.ts +3 -3
- package/dist/stores/message/utils.js +9 -8
- package/dist/tools/base.cjs +5 -2
- package/dist/tools/base.d.ts +4 -2
- package/dist/tools/base.js +6 -3
- package/dist/types/openai-types.d.ts +6 -5
- package/dist/util/@cfworker/json-schema/index.cjs +17 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +1 -0
- package/dist/util/@cfworker/json-schema/index.js +1 -0
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +43 -0
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +1 -0
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +39 -0
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +169 -0
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +12 -0
- package/dist/util/@cfworker/json-schema/src/dereference.js +165 -0
- package/dist/util/@cfworker/json-schema/src/format.cjs +139 -0
- package/dist/util/@cfworker/json-schema/src/format.d.ts +2 -0
- package/dist/util/@cfworker/json-schema/src/format.js +136 -0
- package/dist/util/@cfworker/json-schema/src/index.cjs +24 -0
- package/dist/util/@cfworker/json-schema/src/index.d.ts +8 -0
- package/dist/util/@cfworker/json-schema/src/index.js +8 -0
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +11 -0
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +2 -0
- package/dist/util/@cfworker/json-schema/src/pointer.js +6 -0
- package/dist/util/@cfworker/json-schema/src/types.cjs +2 -0
- package/dist/util/@cfworker/json-schema/src/types.d.ts +72 -0
- package/dist/util/@cfworker/json-schema/src/types.js +1 -0
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +28 -0
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +6 -0
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +24 -0
- package/dist/util/@cfworker/json-schema/src/validate.cjs +808 -0
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +3 -0
- package/dist/util/@cfworker/json-schema/src/validate.js +804 -0
- package/dist/util/@cfworker/json-schema/src/validator.cjs +44 -0
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +10 -0
- package/dist/util/@cfworker/json-schema/src/validator.js +40 -0
- package/dist/util/azure.cjs +44 -0
- package/dist/util/azure.d.ts +30 -0
- package/dist/util/azure.js +40 -0
- package/dist/vectorstores/singlestore.cjs +69 -5
- package/dist/vectorstores/singlestore.d.ts +21 -5
- package/dist/vectorstores/singlestore.js +69 -5
- package/dist/vectorstores/typesense.cjs +9 -8
- package/dist/vectorstores/typesense.d.ts +5 -4
- package/dist/vectorstores/typesense.js +9 -8
- package/package.json +18 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chains/openai_functions/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/openai_functions/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chains/openai_functions/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/chat_models/baiduwenxin.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/baiduwenxin.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/chat_models/baiduwenxin.js'
|
package/dist/agents/agent.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BaseLanguageModel } from "../base_language/index.js";
|
|
|
2
2
|
import { CallbackManager, Callbacks } from "../callbacks/manager.js";
|
|
3
3
|
import { LLMChain } from "../chains/llm_chain.js";
|
|
4
4
|
import { BasePromptTemplate } from "../prompts/base.js";
|
|
5
|
-
import { AgentAction, AgentFinish, AgentStep,
|
|
5
|
+
import { AgentAction, AgentFinish, AgentStep, BaseMessage, ChainValues } from "../schema/index.js";
|
|
6
6
|
import { Serializable } from "../load/serializable.js";
|
|
7
7
|
import { StructuredTool, Tool } from "../tools/base.js";
|
|
8
8
|
import { AgentActionOutputParser, AgentInput, SerializedAgent, StoppingMethod } from "./types.js";
|
|
@@ -139,7 +139,7 @@ export declare abstract class Agent extends BaseSingleActionAgent {
|
|
|
139
139
|
/**
|
|
140
140
|
* Construct a scratchpad to let the agent continue its thought process
|
|
141
141
|
*/
|
|
142
|
-
constructScratchPad(steps: AgentStep[]): Promise<string |
|
|
142
|
+
constructScratchPad(steps: AgentStep[]): Promise<string | BaseMessage[]>;
|
|
143
143
|
private _plan;
|
|
144
144
|
/**
|
|
145
145
|
* Decide what to do given some input.
|
|
@@ -46,8 +46,8 @@ class ChatConversationalAgent extends agent_js_1.Agent {
|
|
|
46
46
|
async constructScratchPad(steps) {
|
|
47
47
|
const thoughts = [];
|
|
48
48
|
for (const step of steps) {
|
|
49
|
-
thoughts.push(new index_js_1.
|
|
50
|
-
thoughts.push(new index_js_1.
|
|
49
|
+
thoughts.push(new index_js_1.AIMessage(step.action.log));
|
|
50
|
+
thoughts.push(new index_js_1.HumanMessage((0, template_js_1.renderTemplate)(prompt_js_1.TEMPLATE_TOOL_RESPONSE, "f-string", {
|
|
51
51
|
observation: step.observation,
|
|
52
52
|
})));
|
|
53
53
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
2
2
|
import { ChatPromptTemplate } from "../../prompts/chat.js";
|
|
3
|
-
import { AgentStep,
|
|
3
|
+
import { AgentStep, BaseMessage } from "../../schema/index.js";
|
|
4
4
|
import { Tool } from "../../tools/base.js";
|
|
5
5
|
import { Optional } from "../../types/type-utils.js";
|
|
6
6
|
import { Agent, AgentArgs, OutputParserArgs } from "../agent.js";
|
|
@@ -29,7 +29,7 @@ export declare class ChatConversationalAgent extends Agent {
|
|
|
29
29
|
llmPrefix(): string;
|
|
30
30
|
_stop(): string[];
|
|
31
31
|
static validateTools(tools: Tool[]): void;
|
|
32
|
-
constructScratchPad(steps: AgentStep[]): Promise<
|
|
32
|
+
constructScratchPad(steps: AgentStep[]): Promise<BaseMessage[]>;
|
|
33
33
|
static getDefaultOutputParser(fields?: OutputParserArgs & {
|
|
34
34
|
toolNames: string[];
|
|
35
35
|
}): AgentActionOutputParser;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LLMChain } from "../../chains/llm_chain.js";
|
|
2
2
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
3
3
|
import { renderTemplate } from "../../prompts/template.js";
|
|
4
|
-
import {
|
|
4
|
+
import { AIMessage, HumanMessage, } from "../../schema/index.js";
|
|
5
5
|
import { Agent } from "../agent.js";
|
|
6
6
|
import { ChatConversationalAgentOutputParserWithRetries } from "./outputParser.js";
|
|
7
7
|
import { PREFIX_END, DEFAULT_PREFIX, DEFAULT_SUFFIX, TEMPLATE_TOOL_RESPONSE, } from "./prompt.js";
|
|
@@ -43,8 +43,8 @@ export class ChatConversationalAgent extends Agent {
|
|
|
43
43
|
async constructScratchPad(steps) {
|
|
44
44
|
const thoughts = [];
|
|
45
45
|
for (const step of steps) {
|
|
46
|
-
thoughts.push(new
|
|
47
|
-
thoughts.push(new
|
|
46
|
+
thoughts.push(new AIMessage(step.action.log));
|
|
47
|
+
thoughts.push(new HumanMessage(renderTemplate(TEMPLATE_TOOL_RESPONSE, "f-string", {
|
|
48
48
|
observation: step.observation,
|
|
49
49
|
})));
|
|
50
50
|
}
|
|
@@ -15,11 +15,11 @@ function parseOutput(message) {
|
|
|
15
15
|
toolInput: function_call.arguments
|
|
16
16
|
? JSON.parse(function_call.arguments)
|
|
17
17
|
: {},
|
|
18
|
-
log: message.
|
|
18
|
+
log: message.content,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
return { returnValues: { output: message.
|
|
22
|
+
return { returnValues: { output: message.content }, log: message.content };
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
class OpenAIAgent extends agent_js_1.Agent {
|
|
@@ -79,13 +79,13 @@ class OpenAIAgent extends agent_js_1.Agent {
|
|
|
79
79
|
}
|
|
80
80
|
async constructScratchPad(steps) {
|
|
81
81
|
return steps.flatMap(({ action, observation }) => [
|
|
82
|
-
new index_js_1.
|
|
82
|
+
new index_js_1.AIMessage("", {
|
|
83
83
|
function_call: {
|
|
84
84
|
name: action.tool,
|
|
85
85
|
arguments: JSON.stringify(action.toolInput),
|
|
86
86
|
},
|
|
87
87
|
}),
|
|
88
|
-
new index_js_1.
|
|
88
|
+
new index_js_1.FunctionMessage(observation, action.tool),
|
|
89
89
|
]);
|
|
90
90
|
}
|
|
91
91
|
async plan(steps, inputs, callbackManager) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CallbackManager } from "../../callbacks/manager.js";
|
|
2
2
|
import { BasePromptTemplate } from "../../prompts/base.js";
|
|
3
|
-
import { AgentAction, AgentFinish, AgentStep,
|
|
3
|
+
import { AgentAction, AgentFinish, AgentStep, BaseMessage, ChainValues } from "../../schema/index.js";
|
|
4
4
|
import { StructuredTool } from "../../tools/base.js";
|
|
5
5
|
import { Agent, AgentArgs } from "../agent.js";
|
|
6
6
|
import { AgentInput } from "../types.js";
|
|
@@ -21,6 +21,6 @@ export declare class OpenAIAgent extends Agent {
|
|
|
21
21
|
constructor(input: Omit<OpenAIAgentInput, "outputParser">);
|
|
22
22
|
static createPrompt(_tools: StructuredTool[], fields?: OpenAIAgentCreatePromptArgs): BasePromptTemplate;
|
|
23
23
|
static fromLLMAndTools(llm: BaseLanguageModel, tools: StructuredTool[], args?: OpenAIAgentCreatePromptArgs & Pick<AgentArgs, "callbacks">): OpenAIAgent;
|
|
24
|
-
constructScratchPad(steps: AgentStep[]): Promise<string |
|
|
24
|
+
constructScratchPad(steps: AgentStep[]): Promise<string | BaseMessage[]>;
|
|
25
25
|
plan(steps: Array<AgentStep>, inputs: ChainValues, callbackManager?: CallbackManager): Promise<AgentAction | AgentFinish>;
|
|
26
26
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AIMessage, FunctionMessage, } from "../../schema/index.js";
|
|
2
2
|
import { Agent } from "../agent.js";
|
|
3
3
|
import { PREFIX } from "./prompt.js";
|
|
4
4
|
import { ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, } from "../../prompts/chat.js";
|
|
@@ -12,11 +12,11 @@ function parseOutput(message) {
|
|
|
12
12
|
toolInput: function_call.arguments
|
|
13
13
|
? JSON.parse(function_call.arguments)
|
|
14
14
|
: {},
|
|
15
|
-
log: message.
|
|
15
|
+
log: message.content,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
|
-
return { returnValues: { output: message.
|
|
19
|
+
return { returnValues: { output: message.content }, log: message.content };
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export class OpenAIAgent extends Agent {
|
|
@@ -76,13 +76,13 @@ export class OpenAIAgent extends Agent {
|
|
|
76
76
|
}
|
|
77
77
|
async constructScratchPad(steps) {
|
|
78
78
|
return steps.flatMap(({ action, observation }) => [
|
|
79
|
-
new
|
|
79
|
+
new AIMessage("", {
|
|
80
80
|
function_call: {
|
|
81
81
|
name: action.tool,
|
|
82
82
|
arguments: JSON.stringify(action.toolInput),
|
|
83
83
|
},
|
|
84
84
|
}),
|
|
85
|
-
new
|
|
85
|
+
new FunctionMessage(observation, action.tool),
|
|
86
86
|
]);
|
|
87
87
|
}
|
|
88
88
|
async plan(steps, inputs, callbackManager) {
|
|
@@ -39,9 +39,16 @@ class BaseLangChain extends serializable_js_1.Serializable {
|
|
|
39
39
|
writable: true,
|
|
40
40
|
value: void 0
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(this, "metadata", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: void 0
|
|
47
|
+
});
|
|
42
48
|
this.verbose = params.verbose ?? getVerbosity();
|
|
43
49
|
this.callbacks = params.callbacks;
|
|
44
50
|
this.tags = params.tags ?? [];
|
|
51
|
+
this.metadata = params.metadata ?? {};
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
exports.BaseLangChain = BaseLangChain;
|
|
@@ -53,7 +60,7 @@ class BaseLanguageModel extends BaseLangChain {
|
|
|
53
60
|
* Keys that the language model accepts as call options.
|
|
54
61
|
*/
|
|
55
62
|
get callKeys() {
|
|
56
|
-
return ["stop", "timeout", "signal"];
|
|
63
|
+
return ["stop", "timeout", "signal", "tags", "metadata", "callbacks"];
|
|
57
64
|
}
|
|
58
65
|
constructor({ callbacks, callbackManager, ...params }) {
|
|
59
66
|
super({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CallbackManager, Callbacks } from "../callbacks/manager.js";
|
|
1
|
+
import { BaseMessage, BasePromptValue, LLMResult } from "../schema/index.js";
|
|
2
|
+
import { BaseCallbackConfig, CallbackManager, Callbacks } from "../callbacks/manager.js";
|
|
3
3
|
import { AsyncCaller, AsyncCallerParams } from "../util/async_caller.js";
|
|
4
4
|
import { Serializable } from "../load/serializable.js";
|
|
5
5
|
export type SerializedLLM = {
|
|
@@ -10,6 +10,7 @@ export interface BaseLangChainParams {
|
|
|
10
10
|
verbose?: boolean;
|
|
11
11
|
callbacks?: Callbacks;
|
|
12
12
|
tags?: string[];
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Base class for language models, chains, tools.
|
|
@@ -21,6 +22,7 @@ export declare abstract class BaseLangChain extends Serializable implements Base
|
|
|
21
22
|
verbose: boolean;
|
|
22
23
|
callbacks?: Callbacks;
|
|
23
24
|
tags?: string[];
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
24
26
|
get lc_attributes(): {
|
|
25
27
|
[key: string]: undefined;
|
|
26
28
|
} | undefined;
|
|
@@ -37,7 +39,7 @@ export interface BaseLanguageModelParams extends AsyncCallerParams, BaseLangChai
|
|
|
37
39
|
*/
|
|
38
40
|
callbackManager?: CallbackManager;
|
|
39
41
|
}
|
|
40
|
-
export interface BaseLanguageModelCallOptions {
|
|
42
|
+
export interface BaseLanguageModelCallOptions extends BaseCallbackConfig {
|
|
41
43
|
/**
|
|
42
44
|
* Stop tokens to use for this call.
|
|
43
45
|
* If not provided, the default stop tokens for the model will be used.
|
|
@@ -50,12 +52,9 @@ export interface BaseLanguageModelCallOptions {
|
|
|
50
52
|
/**
|
|
51
53
|
* Abort signal for this call.
|
|
52
54
|
* If provided, the call will be aborted when the signal is aborted.
|
|
55
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|
|
53
56
|
*/
|
|
54
57
|
signal?: AbortSignal;
|
|
55
|
-
/**
|
|
56
|
-
* Tags to attach to this call.
|
|
57
|
-
*/
|
|
58
|
-
tags?: string[];
|
|
59
58
|
}
|
|
60
59
|
/**
|
|
61
60
|
* Base class for language models.
|
|
@@ -74,7 +73,7 @@ export declare abstract class BaseLanguageModel extends BaseLangChain implements
|
|
|
74
73
|
constructor({ callbacks, callbackManager, ...params }: BaseLanguageModelParams);
|
|
75
74
|
abstract generatePrompt(promptValues: BasePromptValue[], options?: string[] | this["CallOptions"], callbacks?: Callbacks): Promise<LLMResult>;
|
|
76
75
|
abstract predict(text: string, options?: string[] | this["CallOptions"], callbacks?: Callbacks): Promise<string>;
|
|
77
|
-
abstract predictMessages(messages:
|
|
76
|
+
abstract predictMessages(messages: BaseMessage[], options?: string[] | this["CallOptions"], callbacks?: Callbacks): Promise<BaseMessage>;
|
|
78
77
|
abstract _modelType(): string;
|
|
79
78
|
abstract _llmType(): string;
|
|
80
79
|
private _encoding?;
|
|
@@ -36,9 +36,16 @@ export class BaseLangChain extends Serializable {
|
|
|
36
36
|
writable: true,
|
|
37
37
|
value: void 0
|
|
38
38
|
});
|
|
39
|
+
Object.defineProperty(this, "metadata", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: void 0
|
|
44
|
+
});
|
|
39
45
|
this.verbose = params.verbose ?? getVerbosity();
|
|
40
46
|
this.callbacks = params.callbacks;
|
|
41
47
|
this.tags = params.tags ?? [];
|
|
48
|
+
this.metadata = params.metadata ?? {};
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
/**
|
|
@@ -49,7 +56,7 @@ export class BaseLanguageModel extends BaseLangChain {
|
|
|
49
56
|
* Keys that the language model accepts as call options.
|
|
50
57
|
*/
|
|
51
58
|
get callKeys() {
|
|
52
|
-
return ["stop", "timeout", "signal"];
|
|
59
|
+
return ["stop", "timeout", "signal", "tags", "metadata", "callbacks"];
|
|
53
60
|
}
|
|
54
61
|
constructor({ callbacks, callbackManager, ...params }) {
|
|
55
62
|
super({
|
package/dist/callbacks/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentAction, AgentFinish,
|
|
1
|
+
import { AgentAction, AgentFinish, BaseMessage, ChainValues, LLMResult } from "../schema/index.js";
|
|
2
2
|
import { Serializable, Serialized, SerializedNotImplemented } from "../load/serializable.js";
|
|
3
3
|
import { SerializedFields } from "../load/map_keys.js";
|
|
4
4
|
type Error = any;
|
|
@@ -16,7 +16,7 @@ declare abstract class BaseCallbackHandlerMethodsClass {
|
|
|
16
16
|
* Called at the start of an LLM or Chat Model run, with the prompt(s)
|
|
17
17
|
* and the run ID.
|
|
18
18
|
*/
|
|
19
|
-
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[]): Promise<void> | void;
|
|
19
|
+
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void> | void;
|
|
20
20
|
/**
|
|
21
21
|
* Called when an LLM/ChatModel in `streaming` mode produces a new token
|
|
22
22
|
*/
|
|
@@ -27,57 +27,57 @@ declare abstract class BaseCallbackHandlerMethodsClass {
|
|
|
27
27
|
* idx.completion is the index of the completion that produced the token
|
|
28
28
|
* (if multiple completions per prompt are requested)
|
|
29
29
|
*/
|
|
30
|
-
idx: NewTokenIndices, runId: string, parentRunId?: string): Promise<void> | void;
|
|
30
|
+
idx: NewTokenIndices, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
31
31
|
/**
|
|
32
32
|
* Called if an LLM/ChatModel run encounters an error
|
|
33
33
|
*/
|
|
34
|
-
handleLLMError?(err: Error, runId: string, parentRunId?: string): Promise<void> | void;
|
|
34
|
+
handleLLMError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
35
35
|
/**
|
|
36
36
|
* Called at the end of an LLM/ChatModel run, with the output and the run ID.
|
|
37
37
|
*/
|
|
38
|
-
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string): Promise<void> | void;
|
|
38
|
+
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
39
39
|
/**
|
|
40
40
|
* Called at the start of a Chat Model run, with the prompt(s)
|
|
41
41
|
* and the run ID.
|
|
42
42
|
*/
|
|
43
|
-
handleChatModelStart?(llm: Serialized, messages:
|
|
43
|
+
handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void> | void;
|
|
44
44
|
/**
|
|
45
45
|
* Called at the start of a Chain run, with the chain name and inputs
|
|
46
46
|
* and the run ID.
|
|
47
47
|
*/
|
|
48
|
-
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
48
|
+
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void> | void;
|
|
49
49
|
/**
|
|
50
50
|
* Called if a Chain run encounters an error
|
|
51
51
|
*/
|
|
52
|
-
handleChainError?(err: Error, runId: string, parentRunId?: string): Promise<void> | void;
|
|
52
|
+
handleChainError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
53
53
|
/**
|
|
54
54
|
* Called at the end of a Chain run, with the outputs and the run ID.
|
|
55
55
|
*/
|
|
56
|
-
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string): Promise<void> | void;
|
|
56
|
+
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
57
57
|
/**
|
|
58
58
|
* Called at the start of a Tool run, with the tool name and input
|
|
59
59
|
* and the run ID.
|
|
60
60
|
*/
|
|
61
|
-
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
61
|
+
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void> | void;
|
|
62
62
|
/**
|
|
63
63
|
* Called if a Tool run encounters an error
|
|
64
64
|
*/
|
|
65
|
-
handleToolError?(err: Error, runId: string, parentRunId?: string): Promise<void> | void;
|
|
65
|
+
handleToolError?(err: Error, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
66
66
|
/**
|
|
67
67
|
* Called at the end of a Tool run, with the tool output and the run ID.
|
|
68
68
|
*/
|
|
69
|
-
handleToolEnd?(output: string, runId: string, parentRunId?: string): Promise<void> | void;
|
|
70
|
-
handleText?(text: string, runId: string, parentRunId?: string): Promise<void> | void;
|
|
69
|
+
handleToolEnd?(output: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
70
|
+
handleText?(text: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
71
71
|
/**
|
|
72
72
|
* Called when an agent is about to execute an action,
|
|
73
73
|
* with the action and the run ID.
|
|
74
74
|
*/
|
|
75
|
-
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string): Promise<void> | void;
|
|
75
|
+
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
76
76
|
/**
|
|
77
77
|
* Called when an agent finishes execution, before it exits.
|
|
78
78
|
* with the final output and the run ID.
|
|
79
79
|
*/
|
|
80
|
-
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string): Promise<void> | void;
|
|
80
|
+
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string, tags?: string[]): Promise<void> | void;
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Base interface for callbacks. All methods are optional. If a method is not
|
|
@@ -136,61 +136,61 @@ export declare abstract class BaseCallbackHandler extends BaseCallbackHandlerMet
|
|
|
136
136
|
* Called at the start of an LLM or Chat Model run, with the prompt(s)
|
|
137
137
|
* and the run ID.
|
|
138
138
|
*/
|
|
139
|
-
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
139
|
+
handleLLMStart?(llm: Serialized, prompts: string[], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined): void | Promise<void>;
|
|
140
140
|
/**
|
|
141
141
|
* Called when an LLM/ChatModel in `streaming` mode produces a new token
|
|
142
142
|
*/
|
|
143
|
-
handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
143
|
+
handleLLMNewToken?(token: string, idx: NewTokenIndices, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
144
144
|
/**
|
|
145
145
|
* Called if an LLM/ChatModel run encounters an error
|
|
146
146
|
*/
|
|
147
|
-
handleLLMError?(err: any, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
147
|
+
handleLLMError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
148
148
|
/**
|
|
149
149
|
* Called at the end of an LLM/ChatModel run, with the output and the run ID.
|
|
150
150
|
*/
|
|
151
|
-
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
151
|
+
handleLLMEnd?(output: LLMResult, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
152
152
|
/**
|
|
153
153
|
* Called at the start of a Chat Model run, with the prompt(s)
|
|
154
154
|
* and the run ID.
|
|
155
155
|
*/
|
|
156
|
-
handleChatModelStart?(llm: Serialized, messages:
|
|
156
|
+
handleChatModelStart?(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string | undefined, extraParams?: Record<string, unknown> | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined): void | Promise<void>;
|
|
157
157
|
/**
|
|
158
158
|
* Called at the start of a Chain run, with the chain name and inputs
|
|
159
159
|
* and the run ID.
|
|
160
160
|
*/
|
|
161
|
-
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
161
|
+
handleChainStart?(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined): void | Promise<void>;
|
|
162
162
|
/**
|
|
163
163
|
* Called if a Chain run encounters an error
|
|
164
164
|
*/
|
|
165
|
-
handleChainError?(err: any, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
165
|
+
handleChainError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
166
166
|
/**
|
|
167
167
|
* Called at the end of a Chain run, with the outputs and the run ID.
|
|
168
168
|
*/
|
|
169
|
-
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
169
|
+
handleChainEnd?(outputs: ChainValues, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
170
170
|
/**
|
|
171
171
|
* Called at the start of a Tool run, with the tool name and input
|
|
172
172
|
* and the run ID.
|
|
173
173
|
*/
|
|
174
|
-
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
174
|
+
handleToolStart?(tool: Serialized, input: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined, metadata?: Record<string, unknown> | undefined): void | Promise<void>;
|
|
175
175
|
/**
|
|
176
176
|
* Called if a Tool run encounters an error
|
|
177
177
|
*/
|
|
178
|
-
handleToolError?(err: any, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
178
|
+
handleToolError?(err: any, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
179
179
|
/**
|
|
180
180
|
* Called at the end of a Tool run, with the tool output and the run ID.
|
|
181
181
|
*/
|
|
182
|
-
handleToolEnd?(output: string, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
183
|
-
handleText?(text: string, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
182
|
+
handleToolEnd?(output: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
183
|
+
handleText?(text: string, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
184
184
|
/**
|
|
185
185
|
* Called when an agent is about to execute an action,
|
|
186
186
|
* with the action and the run ID.
|
|
187
187
|
*/
|
|
188
|
-
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
188
|
+
handleAgentAction?(action: AgentAction, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
189
189
|
/**
|
|
190
190
|
* Called when an agent finishes execution, before it exits.
|
|
191
191
|
* with the final output and the run ID.
|
|
192
192
|
*/
|
|
193
|
-
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined): void | Promise<void>;
|
|
193
|
+
handleAgentEnd?(action: AgentFinish, runId: string, parentRunId?: string | undefined, tags?: string[] | undefined): void | Promise<void>;
|
|
194
194
|
};
|
|
195
195
|
}
|
|
196
196
|
export {};
|
|
@@ -45,9 +45,12 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
45
45
|
}
|
|
46
46
|
return parentRun.child_execution_order + 1;
|
|
47
47
|
}
|
|
48
|
-
async handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags) {
|
|
48
|
+
async handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata) {
|
|
49
49
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
50
50
|
const start_time = Date.now();
|
|
51
|
+
const finalExtraParams = metadata
|
|
52
|
+
? { ...extraParams, metadata }
|
|
53
|
+
: extraParams;
|
|
51
54
|
const run = {
|
|
52
55
|
id: runId,
|
|
53
56
|
name: llm.id[llm.id.length - 1],
|
|
@@ -65,15 +68,18 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
65
68
|
child_runs: [],
|
|
66
69
|
child_execution_order: execution_order,
|
|
67
70
|
run_type: "llm",
|
|
68
|
-
extra:
|
|
71
|
+
extra: finalExtraParams ?? {},
|
|
69
72
|
tags: tags || [],
|
|
70
73
|
};
|
|
71
74
|
this._startTrace(run);
|
|
72
75
|
await this.onLLMStart?.(run);
|
|
73
76
|
}
|
|
74
|
-
async handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags) {
|
|
77
|
+
async handleChatModelStart(llm, messages, runId, parentRunId, extraParams, tags, metadata) {
|
|
75
78
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
76
79
|
const start_time = Date.now();
|
|
80
|
+
const finalExtraParams = metadata
|
|
81
|
+
? { ...extraParams, metadata }
|
|
82
|
+
: extraParams;
|
|
77
83
|
const run = {
|
|
78
84
|
id: runId,
|
|
79
85
|
name: llm.id[llm.id.length - 1],
|
|
@@ -91,7 +97,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
91
97
|
child_runs: [],
|
|
92
98
|
child_execution_order: execution_order,
|
|
93
99
|
run_type: "llm",
|
|
94
|
-
extra:
|
|
100
|
+
extra: finalExtraParams ?? {},
|
|
95
101
|
tags: tags || [],
|
|
96
102
|
};
|
|
97
103
|
this._startTrace(run);
|
|
@@ -125,7 +131,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
125
131
|
await this.onLLMError?.(run);
|
|
126
132
|
await this._endTrace(run);
|
|
127
133
|
}
|
|
128
|
-
async handleChainStart(chain, inputs, runId, parentRunId, tags) {
|
|
134
|
+
async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata) {
|
|
129
135
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
130
136
|
const start_time = Date.now();
|
|
131
137
|
const run = {
|
|
@@ -145,7 +151,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
145
151
|
child_execution_order: execution_order,
|
|
146
152
|
run_type: "chain",
|
|
147
153
|
child_runs: [],
|
|
148
|
-
extra: {},
|
|
154
|
+
extra: metadata ? { metadata } : {},
|
|
149
155
|
tags: tags || [],
|
|
150
156
|
};
|
|
151
157
|
this._startTrace(run);
|
|
@@ -179,7 +185,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
179
185
|
await this.onChainError?.(run);
|
|
180
186
|
await this._endTrace(run);
|
|
181
187
|
}
|
|
182
|
-
async handleToolStart(tool, input, runId, parentRunId, tags) {
|
|
188
|
+
async handleToolStart(tool, input, runId, parentRunId, tags, metadata) {
|
|
183
189
|
const execution_order = this._getExecutionOrder(parentRunId);
|
|
184
190
|
const start_time = Date.now();
|
|
185
191
|
const run = {
|
|
@@ -199,7 +205,7 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
199
205
|
child_execution_order: execution_order,
|
|
200
206
|
run_type: "tool",
|
|
201
207
|
child_runs: [],
|
|
202
|
-
extra: {},
|
|
208
|
+
extra: metadata ? { metadata } : {},
|
|
203
209
|
tags: tags || [],
|
|
204
210
|
};
|
|
205
211
|
this._startTrace(run);
|
|
@@ -248,6 +254,18 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
248
254
|
});
|
|
249
255
|
await this.onAgentAction?.(run);
|
|
250
256
|
}
|
|
257
|
+
async handleAgentEnd(action, runId) {
|
|
258
|
+
const run = this.runMap.get(runId);
|
|
259
|
+
if (!run || run?.run_type !== "chain") {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
run.events.push({
|
|
263
|
+
name: "agent_end",
|
|
264
|
+
time: Date.now(),
|
|
265
|
+
kwargs: { action },
|
|
266
|
+
});
|
|
267
|
+
await this.onAgentEnd?.(run);
|
|
268
|
+
}
|
|
251
269
|
async handleText(text, runId) {
|
|
252
270
|
const run = this.runMap.get(runId);
|
|
253
271
|
if (!run || run?.run_type !== "chain") {
|
|
@@ -260,5 +278,17 @@ class BaseTracer extends base_js_1.BaseCallbackHandler {
|
|
|
260
278
|
});
|
|
261
279
|
await this.onText?.(run);
|
|
262
280
|
}
|
|
281
|
+
async handleLLMNewToken(token, idx, runId) {
|
|
282
|
+
const run = this.runMap.get(runId);
|
|
283
|
+
if (!run || run?.run_type !== "llm") {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
run.events.push({
|
|
287
|
+
name: "new_token",
|
|
288
|
+
time: Date.now(),
|
|
289
|
+
kwargs: { token, idx },
|
|
290
|
+
});
|
|
291
|
+
await this.onLLMNewToken?.(run);
|
|
292
|
+
}
|
|
263
293
|
}
|
|
264
294
|
exports.BaseTracer = BaseTracer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { KVMap, BaseRun } from "langchainplus-sdk/schemas";
|
|
2
|
-
import { AgentAction,
|
|
2
|
+
import { AgentAction, AgentFinish, BaseMessage, ChainValues, LLMResult } from "../../schema/index.js";
|
|
3
3
|
import { Serialized } from "../../load/serializable.js";
|
|
4
|
-
import { BaseCallbackHandler, BaseCallbackHandlerInput } from "../base.js";
|
|
4
|
+
import { BaseCallbackHandler, BaseCallbackHandlerInput, NewTokenIndices } from "../base.js";
|
|
5
5
|
export type RunType = "llm" | "chain" | "tool";
|
|
6
6
|
export interface Run extends BaseRun {
|
|
7
7
|
id: string;
|
|
@@ -27,18 +27,20 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
27
27
|
protected _startTrace(run: Run): void;
|
|
28
28
|
protected _endTrace(run: Run): Promise<void>;
|
|
29
29
|
protected _getExecutionOrder(parentRunId: string | undefined): number;
|
|
30
|
-
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[]): Promise<void>;
|
|
31
|
-
handleChatModelStart(llm: Serialized, messages:
|
|
30
|
+
handleLLMStart(llm: Serialized, prompts: string[], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap): Promise<void>;
|
|
31
|
+
handleChatModelStart(llm: Serialized, messages: BaseMessage[][], runId: string, parentRunId?: string, extraParams?: KVMap, tags?: string[], metadata?: KVMap): Promise<void>;
|
|
32
32
|
handleLLMEnd(output: LLMResult, runId: string): Promise<void>;
|
|
33
33
|
handleLLMError(error: Error, runId: string): Promise<void>;
|
|
34
|
-
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
34
|
+
handleChainStart(chain: Serialized, inputs: ChainValues, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap): Promise<void>;
|
|
35
35
|
handleChainEnd(outputs: ChainValues, runId: string): Promise<void>;
|
|
36
36
|
handleChainError(error: Error, runId: string): Promise<void>;
|
|
37
|
-
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[]): Promise<void>;
|
|
37
|
+
handleToolStart(tool: Serialized, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: KVMap): Promise<void>;
|
|
38
38
|
handleToolEnd(output: string, runId: string): Promise<void>;
|
|
39
39
|
handleToolError(error: Error, runId: string): Promise<void>;
|
|
40
40
|
handleAgentAction(action: AgentAction, runId: string): Promise<void>;
|
|
41
|
+
handleAgentEnd(action: AgentFinish, runId: string): Promise<void>;
|
|
41
42
|
handleText(text: string, runId: string): Promise<void>;
|
|
43
|
+
handleLLMNewToken(token: string, idx: NewTokenIndices, runId: string): Promise<void>;
|
|
42
44
|
onLLMStart?(run: Run): void | Promise<void>;
|
|
43
45
|
onLLMEnd?(run: Run): void | Promise<void>;
|
|
44
46
|
onLLMError?(run: Run): void | Promise<void>;
|
|
@@ -49,5 +51,7 @@ export declare abstract class BaseTracer extends BaseCallbackHandler {
|
|
|
49
51
|
onToolEnd?(run: Run): void | Promise<void>;
|
|
50
52
|
onToolError?(run: Run): void | Promise<void>;
|
|
51
53
|
onAgentAction?(run: Run): void | Promise<void>;
|
|
54
|
+
onAgentEnd?(run: Run): void | Promise<void>;
|
|
52
55
|
onText?(run: Run): void | Promise<void>;
|
|
56
|
+
onLLMNewToken?(run: Run): void | Promise<void>;
|
|
53
57
|
}
|