Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Support LangChain orchestration client streaming #711

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

Merged
merged 84 commits into from
May 23, 2025

Conversation

KavithaSiva
Copy link
Contributor

@KavithaSiva KavithaSiva commented May 7, 2025

Context

Closes SAP/ai-sdk-js-backlog#259.

What this PR does and why it is needed

This PR introduces streaming support for Langchain Orchestration client.

Usage:

const orchestrationConfig: LangchainOrchestrationModuleConfig = {
  llm: {
    model_name: 'gpt-4o'
  },
  templating: {
    template: [
      {
        role: 'user',
        content: 'Write a 100 word explanation about {{?topic}}'
      }
    ]
  }
};

const client = new OrchestrationClient(orchestrationConfig);
const stream =  client.stream([], {
  inputParams: {
    topic: 'SAP Cloud SDK and its capabilities'
  },
  signal: controller.signal
});

for await (const chunk of stream) {
 //Access the streamed chunk here
}

packages/langchain/src/orchestration/util.ts Outdated Show resolved Hide resolved
@KavithaSiva KavithaSiva marked this pull request as ready for review May 12, 2025 07:57
@KavithaSiva
Copy link
Contributor Author

KavithaSiva commented May 12, 2025

Adding more tests in a follow-up PR.

Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

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

Suggestions for improvement. Also please do implement tests already in this PR to avoid changes later in case they don't work as expected. 😄

.changeset/chilly-steaks-divide.md Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/util.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/util.ts Outdated Show resolved Hide resolved
sample-code/src/langchain-orchestration.ts Outdated Show resolved Hide resolved
Co-authored-by: Zhongpin Wang <zhongpin.wang@sap.com>
sample-code/src/index.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/util.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ZhongpinWang ZhongpinWang left a comment

Choose a reason for hiding this comment

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

I see refactoring needed for the big *_streamResponseChunks function. It would make the code more readable and testable.

packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/client.ts Outdated Show resolved Hide resolved
sample-code/src/langchain-orchestration.ts Outdated Show resolved Hide resolved
Copy link
Member

@tomfrenken tomfrenken left a comment

Choose a reason for hiding this comment

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

Looks like a lot was already considered, still there are some pointers from my side left.

I will continue reviewing the tests.

sample-code/src/server.ts Outdated Show resolved Hide resolved
sample-code/src/langchain-orchestration.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/util.ts Outdated Show resolved Hide resolved
packages/langchain/src/orchestration/util.ts Show resolved Hide resolved
generationInfo: { ...tokenIndices }
});

// Notify the run manager about the new token, some parameters are undefined as they are implicitly read from the context.
Copy link
Member

Choose a reason for hiding this comment

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

I would put it as a comment right above this line. Doesn't need to be user-facing, but for us to maintain in the future.

KavithaSiva and others added 6 commits May 22, 2025 14:59
{
"delta": {
"content": "",
"role": "assistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistant",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some properties are concatenated multiple times, as concat() in AIMessageChunk does not have these properties. We need to custom handle these properties during concatenation. Will handle this in a follow-up BLI: https://github.com/SAP/ai-sdk-js-backlog/issues/322.

I don't think this is a blocker for the streaming feature. What do the others think?

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, but could also be a contribution to LangChain itself (as part of that follow-up ticket), as they hint as concat being the "standard" way to chain chunks together, and it's clearly flawed.

@KavithaSiva KavithaSiva requested a review from tomfrenken May 22, 2025 14:20
@KavithaSiva KavithaSiva dismissed ZhongpinWang’s stale review May 22, 2025 14:21

Changes addressed.

Copy link
Member

@tomfrenken tomfrenken left a comment

Choose a reason for hiding this comment

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

A few minor comments, but overall LGTM!

{
"delta": {
"content": "",
"role": "assistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistant",
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, but could also be a contribution to LangChain itself (as part of that follow-up ticket), as they hint as concat being the "standard" way to chain chunks together, and it's clearly flawed.

KavithaSiva and others added 3 commits May 23, 2025 11:25
….test.ts

Co-authored-by: Tom Frenken <54979414+tomfrenken@users.noreply.github.com>
@KavithaSiva KavithaSiva merged commit 7574dd1 into main May 23, 2025
10 checks passed
@KavithaSiva KavithaSiva deleted the langchain-orchestration-client-streaming branch May 23, 2025 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.