Skip to content

Commit

Permalink
Set userId in Langchain Callback handler
Browse files Browse the repository at this point in the history
  • Loading branch information
marcklingen committed Oct 12, 2023
1 parent 1a76edf commit 8cd9be5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion langfuse-langchain/src/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ type KeyParams = {
secretKey: string;
} & LangfuseOptions;

type ConstructorParams = RootParams | KeyParams;
type ConstructorParams = (RootParams | KeyParams) & {
userId?: string;
};

export class CallbackHandler extends BaseCallbackHandler {
name = "CallbackHandler";
Expand All @@ -33,6 +35,7 @@ export class CallbackHandler extends BaseCallbackHandler {
observationId?: string;
rootObservationId?: string;
topLevelObservationId?: string;
userId?: string;

constructor(params: ConstructorParams) {
super();
Expand All @@ -43,6 +46,7 @@ export class CallbackHandler extends BaseCallbackHandler {
} else {
this.langfuse = new Langfuse({ ...params, persistence: "memory" });
}
this.userId = params.userId;
}

async flushAsync(): Promise<any> {
Expand Down Expand Up @@ -161,6 +165,7 @@ export class CallbackHandler extends BaseCallbackHandler {
id: runId,
name: serialized.id.at(-1)?.toString(),
metadata: this.joinTagsAndMetaData(tags, metadata),
userId: this.userId,
});
this.traceId = runId;
}
Expand Down

0 comments on commit 8cd9be5

Please sign in to comment.