Skip to content

Commit

Permalink
core[patch]: Export Runnable history (#3514)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Dec 4, 2023
1 parent a862e9e commit f62ff21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
25 changes: 13 additions & 12 deletions langchain-core/src/runnables/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ type GetSessionHistoryCallable = (
...args: Array<any>
) => Promise<BaseChatMessageHistory | BaseListChatMessageHistory>;

export interface RunnableWithMessageHistoryInputs<RunInput, RunOutput>
extends Omit<
RunnableBindingArgs<RunInput, RunOutput, BaseCallbackConfig>,
"bound"
> {
runnable: Runnable<RunInput, RunOutput>;
getMessageHistory: GetSessionHistoryCallable;
inputMessagesKey?: string;
outputMessagesKey?: string;
historyMessagesKey?: string;
}

export class RunnableWithMessageHistory<
RunInput,
RunOutput
Expand All @@ -38,18 +50,7 @@ export class RunnableWithMessageHistory<

getMessageHistory: GetSessionHistoryCallable;

constructor(
fields: Omit<
RunnableBindingArgs<RunInput, RunOutput, BaseCallbackConfig>,
"bound"
> & {
runnable: Runnable<RunInput, RunOutput>;
getMessageHistory: GetSessionHistoryCallable;
inputMessagesKey?: string;
outputMessagesKey?: string;
historyMessagesKey?: string;
}
) {
constructor(fields: RunnableWithMessageHistoryInputs<RunInput, RunOutput>) {
let historyChain: Runnable = new RunnableLambda({
func: (input, options) => this._enterHistory(input, options ?? {}),
}).withConfig({ runName: "loadHistory" });
Expand Down
4 changes: 4 additions & 0 deletions langchain-core/src/runnables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export type { RunnableConfig, getCallbackMangerForConfig } from "./config.js";
export { RunnablePassthrough, RunnableAssign } from "./passthrough.js";
export { type RouterInput, RouterRunnable } from "./router.js";
export { RunnableBranch, type Branch, type BranchLike } from "./branch.js";
export {
type RunnableWithMessageHistoryInputs,
RunnableWithMessageHistory,
} from "./history.js";

1 comment on commit f62ff21

@vercel
Copy link

@vercel vercel bot commented on f62ff21 Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.