Skip to content

Commit

Permalink
Add transform to required methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 16, 2023
1 parent 1876e31 commit 1c6b5b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions langchain-core/src/runnables/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface RunnableInterface<
input: RunInput,
options?: Partial<CallOptions>
): Promise<IterableReadableStreamInterface<RunOutput>>;

transform(
generator: AsyncGenerator<RunInput>,
options: Partial<CallOptions>
): AsyncGenerator<RunOutput>;
}

export type RunnableFunc<RunInput, RunOutput> = (
Expand Down
13 changes: 13 additions & 0 deletions langchain-core/src/runnables/tests/runnable_interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ interface RunnableInterfaceV0<RunInput, RunOutput, CallOptions = any> {
input: RunInput,
options?: Partial<CallOptions>
): Promise<IterableReadableStreamV0<RunOutput>>;

transform(
generator: AsyncGenerator<RunInput>,
options: Partial<CallOptions>
): AsyncGenerator<RunOutput>;
}

class IterableReadableStreamV0<T> extends ReadableStream<T> {
Expand Down Expand Up @@ -222,6 +227,14 @@ class RunnableV0
): Promise<IterableReadableStreamV0<any>> {
throw new Error("Not implemented");
}

// eslint-disable-next-line require-yield
async *transform(
_generator: AsyncGenerator<StringPromptValueV0>,
_options: Partial<any>
): AsyncGenerator<AIMessageV0> {
throw new Error("Not implemented");
}
}

test("Pipe with a class that implements a runnable interface", async () => {
Expand Down

0 comments on commit 1c6b5b2

Please sign in to comment.