Skip to content

Commit 6692700

Browse files
author
tomfrenken
committed
override super method, remove cast
1 parent 87ac9ad commit 6692700

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

packages/langchain/src/orchestration/chat.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
mapLangchainMessagesToOrchestrationMessages,
88
mapOutputToChatResult
99
} from './util.js';
10+
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base';
11+
import type { Runnable, RunnableLike } from '@langchain/core/runnables';
1012
import type { CustomRequestConfig } from '@sap-ai-sdk/core';
1113
import type { OrchestrationMessageChunk } from './orchestration-message-chunk.js';
1214
import type { ChatResult } from '@langchain/core/outputs';
@@ -40,14 +42,21 @@ export class OrchestrationClient extends BaseChatModel<
4042
}
4143

4244
/**
43-
* Decisions:
44-
* bind only supports ParsedCallOptions, we don't support arbitrary LLM options, only tool calls & default BaseLanguageModelCallOptions, e.g. stop ✅
45-
* this aligns with other vendors' client designs (e.g. openai, google) ✅
46-
* inputParams are a seperate call option, history = history ✅
47-
* Module results are part of our own message type, which extends AI Message to work with all other langchain functionality. ✅.
48-
*
49-
* For timeout, we need to apply our own middleware, it is not handled by langchain. ✅.
45+
* Create a new runnable sequence that runs each individual runnable in series,
46+
* piping the output of one runnable into another runnable or runnable-like.
47+
* @param coerceable - A runnable, function, or object whose values are functions or runnables.
48+
* @returns A new runnable sequence.
5049
*/
50+
override pipe<NewRunOutput>(
51+
coerceable: RunnableLike<OrchestrationMessageChunk, NewRunOutput>
52+
): Runnable<BaseLanguageModelInput, Exclude<NewRunOutput, Error>, OrchestrationCallOptions> {
53+
// Delegate to the superclass pipe method and narrow the type.
54+
return super.pipe(coerceable) as Runnable<
55+
BaseLanguageModelInput,
56+
Exclude<NewRunOutput, Error>,
57+
OrchestrationCallOptions
58+
>;
59+
}
5160

5261
override async _generate(
5362
messages: BaseMessage[],

sample-code/src/langchain-orchestration.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { StringOutputParser } from '@langchain/core/output_parsers';
22
import { OrchestrationClient } from '@sap-ai-sdk/langchain';
3-
import type { BaseLanguageModelInput } from '@langchain/core/language_models/base';
4-
import type { Runnable } from '@langchain/core/runnables';
5-
import type { OrchestrationCallOptions } from '@sap-ai-sdk/langchain';
63

74
/**
85
* Ask GPT about the capital of France, as part of a chain.
@@ -35,7 +32,7 @@ export async function invokeChain(): Promise<string> {
3532
const parser = new StringOutputParser();
3633

3734
// chain together template, client, and parser
38-
const llmChain = client.pipe(parser) as Runnable<BaseLanguageModelInput, string, OrchestrationCallOptions>;
35+
const llmChain = client.pipe(parser);
3936

4037
// invoke the chain
4138
return llmChain.invoke('My Message History', callOptions);

0 commit comments

Comments
 (0)