Skip to content

Commit

Permalink
Add tags to all callback handler methods (langchain-ai#1847)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos authored Jul 3, 2023
1 parent 5510b44 commit faaf78e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
30 changes: 20 additions & 10 deletions langchain/src/callbacks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ abstract class BaseCallbackHandlerMethodsClass {
*/
idx: NewTokenIndices,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -63,7 +64,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleLLMError?(
err: Error,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -72,7 +74,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleLLMEnd?(
output: LLMResult,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand Down Expand Up @@ -106,7 +109,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleChainError?(
err: Error,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -115,7 +119,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleChainEnd?(
outputs: ChainValues,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -136,7 +141,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleToolError?(
err: Error,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -145,13 +151,15 @@ abstract class BaseCallbackHandlerMethodsClass {
handleToolEnd?(
output: string,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

handleText?(
text: string,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -161,7 +169,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleAgentAction?(
action: AgentAction,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;

/**
Expand All @@ -171,7 +180,8 @@ abstract class BaseCallbackHandlerMethodsClass {
handleAgentEnd?(
action: AgentFinish,
runId: string,
parentRunId?: string
parentRunId?: string,
tags?: string[]
): Promise<void> | void;
}

Expand Down
34 changes: 24 additions & 10 deletions langchain/src/callbacks/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class BaseRunManager {
this.handlers.map((handler) =>
consumeCallback(async () => {
try {
await handler.handleText?.(text, this.runId, this._parentRunId);
await handler.handleText?.(
text,
this.runId,
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
`Error in handler ${handler.constructor.name}, handleText: ${err}`
Expand Down Expand Up @@ -96,7 +101,8 @@ export class CallbackManagerForLLMRun
token,
idx,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -118,7 +124,8 @@ export class CallbackManagerForLLMRun
await handler.handleLLMError?.(
err,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -140,7 +147,8 @@ export class CallbackManagerForLLMRun
await handler.handleLLMEnd?.(
output,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand Down Expand Up @@ -178,7 +186,8 @@ export class CallbackManagerForChainRun
await handler.handleChainError?.(
err,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -200,7 +209,8 @@ export class CallbackManagerForChainRun
await handler.handleChainEnd?.(
output,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -222,7 +232,8 @@ export class CallbackManagerForChainRun
await handler.handleAgentAction?.(
action,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -244,7 +255,8 @@ export class CallbackManagerForChainRun
await handler.handleAgentEnd?.(
action,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand Down Expand Up @@ -282,7 +294,8 @@ export class CallbackManagerForToolRun
await handler.handleToolError?.(
err,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand All @@ -304,7 +317,8 @@ export class CallbackManagerForToolRun
await handler.handleToolEnd?.(
output,
this.runId,
this._parentRunId
this._parentRunId,
this.tags
);
} catch (err) {
console.error(
Expand Down

0 comments on commit faaf78e

Please sign in to comment.