-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core[minor]: Runnable with message history #3437
Merged
+697
−51
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
df9a9f1
Runnable with message history
bracesproul a22855e
cr
bracesproul 66ed823
Merge branch 'main' into brace/runnable-message-history
bracesproul add083f
cr
bracesproul 05b71ea
adds withListeners method to runnables/callbacks
bracesproul 2cf91d5
added entrypoint for root listener file
bracesproul 21ce187
cr
bracesproul a8b2dbd
cr
bracesproul 48e1f7e
cr
bracesproul a56cd19
cr
bracesproul 89d689d
cr
bracesproul 9fd9eaf
Merge branch 'brace/with-listeners' of https://github.com/langchain-a…
bracesproul be79ae6
support async listeners
bracesproul ad795af
Merge branch 'brace/with-listeners' of https://github.com/langchain-a…
bracesproul b71e30d
allow for run or run and config as args to listener funcs
bracesproul b7575a4
Merge branch 'brace/with-listeners' of https://github.com/langchain-a…
bracesproul e8432ac
cr
bracesproul 00ab504
chore: lint files
bracesproul 08698aa
cr
bracesproul b055337
cr
bracesproul 8e23d5d
eslint disbale any
bracesproul a5576a8
Merge branch 'brace/with-listeners' of https://github.com/langchain-a…
bracesproul 485b915
Merge branch 'main' into brace/with-listeners
bracesproul 4394aa0
Merge branch 'main' into brace/with-listeners
bracesproul 670f4f1
update types
bracesproul 0a09cda
Merge branch 'main' into brace/with-listeners
bracesproul 3b76fc4
Merge branch 'main' into brace/runnable-message-history
bracesproul bc8cdbf
Merge branch 'main' into brace/with-listeners
bracesproul 7eb2ef9
Merge branch 'brace/with-listeners' of https://github.com/langchain-a…
bracesproul cec10ac
cr
bracesproul c9d3402
cr
bracesproul 12b2d9b
merge main
bracesproul b465628
cr
bracesproul 6df6e5d
Merge branch 'main' into brace/runnable-message-history
bracesproul dcbc640
cr
bracesproul 5e113e9
cr
bracesproul 1708764
Merge branch 'main' into brace/runnable-message-history
bracesproul 52ceeea
cr
bracesproul f3f6c79
Style
jacoblee93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading status checks…
support async listeners
commit be79ae6d056e0c46d139cd2694cde6413f60c982
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -572,9 +572,9 @@ export abstract class Runnable< | |
onEnd, | ||
onError, | ||
}: { | ||
onStart?: (run: Run) => void; | ||
onEnd?: (run: Run) => void; | ||
onError?: (run: Run) => void; | ||
onStart?: (run: Run) => void | Promise<void>; | ||
onEnd?: (run: Run) => void | Promise<void>; | ||
onError?: (run: Run) => void | Promise<void>; | ||
}): Runnable<RunInput, RunOutput, CallOptions> { | ||
// eslint-disable-next-line @typescript-eslint/no-use-before-define | ||
return new RunnableBinding<RunInput, RunOutput, CallOptions>({ | ||
|
@@ -628,7 +628,9 @@ export class RunnableBinding< | |
|
||
protected kwargs?: Partial<CallOptions>; | ||
|
||
configFactories?: Array<(config: RunnableConfig) => RunnableConfig>; | ||
configFactories?: Array< | ||
(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig> | ||
>; | ||
|
||
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>) { | ||
super(fields); | ||
|
@@ -639,12 +641,16 @@ export class RunnableBinding< | |
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
_mergeConfig(options?: Record<string, any>): Partial<CallOptions> { | ||
async _mergeConfig( | ||
options?: Record<string, any> | ||
): Promise<Partial<CallOptions>> { | ||
const config = mergeConfigs(this.config, options); | ||
return mergeConfigs( | ||
config, | ||
...(this.configFactories | ||
? this.configFactories.map((f) => f(config)) | ||
? await Promise.all( | ||
this.configFactories.map(async (f) => await f(config)) | ||
) | ||
: []) | ||
); | ||
} | ||
|
@@ -686,7 +692,7 @@ export class RunnableBinding< | |
): Promise<RunOutput> { | ||
return this.bound.invoke( | ||
input, | ||
this._mergeConfig({ ...options, ...this.kwargs }) | ||
await this._mergeConfig({ ...options, ...this.kwargs }) | ||
); | ||
} | ||
|
||
|
@@ -714,13 +720,16 @@ export class RunnableBinding< | |
batchOptions?: RunnableBatchOptions | ||
): Promise<(RunOutput | Error)[]> { | ||
const mergedOptions = Array.isArray(options) | ||
? options.map((individualOption) => | ||
this._mergeConfig({ | ||
...individualOption, | ||
...this.kwargs, | ||
}) | ||
? await Promise.all( | ||
options.map( | ||
async (individualOption) => | ||
await this._mergeConfig({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No race condition right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't believe so, no. |
||
...individualOption, | ||
...this.kwargs, | ||
}) | ||
) | ||
) | ||
: this._mergeConfig({ ...options, ...this.kwargs }); | ||
: await this._mergeConfig({ ...options, ...this.kwargs }); | ||
return this.bound.batch(inputs, mergedOptions, batchOptions); | ||
} | ||
|
||
|
@@ -730,7 +739,7 @@ export class RunnableBinding< | |
) { | ||
yield* this.bound._streamIterator( | ||
input, | ||
this._mergeConfig({ ...options, ...this.kwargs }) | ||
await this._mergeConfig({ ...options, ...this.kwargs }) | ||
); | ||
} | ||
|
||
|
@@ -740,7 +749,7 @@ export class RunnableBinding< | |
): Promise<IterableReadableStream<RunOutput>> { | ||
return this.bound.stream( | ||
input, | ||
this._mergeConfig({ ...options, ...this.kwargs }) | ||
await this._mergeConfig({ ...options, ...this.kwargs }) | ||
); | ||
} | ||
|
||
|
@@ -751,7 +760,7 @@ export class RunnableBinding< | |
): AsyncGenerator<RunOutput> { | ||
yield* this.bound.transform( | ||
generator, | ||
this._mergeConfig({ ...options, ...this.kwargs }) | ||
await this._mergeConfig({ ...options, ...this.kwargs }) | ||
); | ||
} | ||
|
||
|
@@ -779,9 +788,9 @@ export class RunnableBinding< | |
onEnd, | ||
onError, | ||
}: { | ||
onStart?: (run: Run) => void; | ||
onEnd?: (run: Run) => void; | ||
onError?: (run: Run) => void; | ||
onStart?: (run: Run) => void | Promise<void>; | ||
onEnd?: (run: Run) => void | Promise<void>; | ||
onError?: (run: Run) => void | Promise<void>; | ||
}): Runnable<RunInput, RunOutput, CallOptions> { | ||
// | ||
return new RunnableBinding<RunInput, RunOutput, CallOptions>({ | ||
|
@@ -886,9 +895,9 @@ export class RunnableEach< | |
onEnd, | ||
onError, | ||
}: { | ||
onStart?: (run: Run) => void; | ||
onEnd?: (run: Run) => void; | ||
onError?: (run: Run) => void; | ||
onStart?: (run: Run) => void | Promise<void>; | ||
onEnd?: (run: Run) => void | Promise<void>; | ||
onError?: (run: Run) => void | Promise<void>; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
}): Runnable<any, any, CallOptions> { | ||
return new RunnableEach<RunInputItem, RunOutputItem, CallOptions>({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f
->factoryMethod
or something