Skip to content

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
}

@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. 😄

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.

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.

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.

{
"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 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