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

Open
wants to merge 81 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
996a818
chore: progress till now
KavithaSiva May 1, 2025
6c9039f
chore: progress till now
KavithaSiva May 7, 2025
a84b446
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 7, 2025
a54250f
chore: update implementation
KavithaSiva May 9, 2025
e0f0e68
chore: minor corrections
KavithaSiva May 9, 2025
9a743b6
chore: add changeset
KavithaSiva May 9, 2025
d386b30
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 9, 2025
8c4a7ec
chore: change finish_reason storage
KavithaSiva May 9, 2025
989f742
Merge branch 'langchain-orchestration-client-streaming' of github.com…
KavithaSiva May 9, 2025
db8491f
chore: update additonal properties
KavithaSiva May 9, 2025
fd37e19
chore: revert type change for additional_properties
KavithaSiva May 9, 2025
009b508
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 9, 2025
ca2c7bc
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 12, 2025
175e9b9
Update .changeset/chilly-steaks-divide.md
KavithaSiva May 14, 2025
dd0a47c
chore: address review comments
KavithaSiva May 14, 2025
13f10ce
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 14, 2025
96df564
chore: use convenience functions always
KavithaSiva May 14, 2025
5769148
chore: switch to map
KavithaSiva May 15, 2025
643a6bb
chore: add more convenience functions
KavithaSiva May 15, 2025
7503191
chore: address review comments
KavithaSiva May 18, 2025
a6cb6d7
chore: simplify function
KavithaSiva May 18, 2025
aad9a05
chore: review comment
KavithaSiva May 18, 2025
25a4a79
chore: simplify
KavithaSiva May 18, 2025
c72f742
chore: remove e2e test
KavithaSiva May 18, 2025
2a3d810
chore: add tests, minor changes
KavithaSiva May 18, 2025
f5c8473
chore: additional test for utility functions
KavithaSiva May 19, 2025
fd331ef
chore: add test for tool calls
KavithaSiva May 19, 2025
b12bc70
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 19, 2025
0be7944
chore: add tests for mapping function
KavithaSiva May 19, 2025
373ccac
Merge branch 'langchain-orchestration-client-streaming' of github.com…
KavithaSiva May 19, 2025
ffd2456
chore: fix failing test
KavithaSiva May 19, 2025
364ae6b
chore: refactor test names
KavithaSiva May 19, 2025
2d3908d
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 19, 2025
a8359cc
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 19, 2025
53666d9
Update packages/langchain/src/orchestration/client.ts
KavithaSiva May 19, 2025
a690099
chore: adapt name
KavithaSiva May 19, 2025
c24f9f5
chore: review changes
KavithaSiva May 19, 2025
acecf11
Update sample-code/src/langchain-orchestration.ts
KavithaSiva May 19, 2025
3459207
Update sample-code/src/langchain-orchestration.ts
KavithaSiva May 20, 2025
5dab701
chore: fix rename
KavithaSiva May 20, 2025
448c403
chore: address JSDoc
KavithaSiva May 20, 2025
b6191a6
chore: link BLI instead
KavithaSiva May 20, 2025
56ea273
chore: switch to hardcoded choice index
KavithaSiva May 20, 2025
dbf7174
chore: add convenience functions
KavithaSiva May 20, 2025
f82301e
chore: add convenience + tests
KavithaSiva May 20, 2025
ac9f6e8
chore: clean up generate
KavithaSiva May 20, 2025
cdb4749
chore: add callWithOptions back
KavithaSiva May 20, 2025
c073c88
Update packages/langchain/src/orchestration/util.ts
KavithaSiva May 20, 2025
58434d5
Update packages/langchain/src/orchestration/util.ts
KavithaSiva May 20, 2025
f51b1d7
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 20, 2025
64f16c7
chore: fix build
KavithaSiva May 20, 2025
1cacf75
chore: fix build
KavithaSiva May 20, 2025
0b34760
Update packages/langchain/src/orchestration/client.test.ts
KavithaSiva May 20, 2025
206067a
chore: rename
KavithaSiva May 21, 2025
4560687
chore: fix build
KavithaSiva May 21, 2025
32971bd
chore: adjust test
KavithaSiva May 21, 2025
a9fc5d9
Update packages/langchain/src/orchestration/client.test.ts
KavithaSiva May 21, 2025
46ddc01
chore: address review comment
KavithaSiva May 21, 2025
473e9d8
Merge branch 'langchain-orchestration-client-streaming' of github.com…
KavithaSiva May 21, 2025
27fc55b
chore: link BLI
KavithaSiva May 21, 2025
6b50d39
chore: cleanup tests
KavithaSiva May 21, 2025
be56c21
chore: address review comments
KavithaSiva May 22, 2025
93b6cf2
chore: review comments
KavithaSiva May 22, 2025
40da119
chore: Add snapshot tests instead
KavithaSiva May 22, 2025
cc81b03
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 22, 2025
94ceda9
chore: fix issues after merge conflict
KavithaSiva May 22, 2025
ad368c1
fix: Changes from lint
May 22, 2025
8968eb4
chore: fix tests
KavithaSiva May 22, 2025
b2ae5d0
Merge branch 'langchain-orchestration-client-streaming' of github.com…
KavithaSiva May 22, 2025
dcd5550
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 22, 2025
dd9c34f
chore: use mockInference instead of inference with resilience
KavithaSiva May 22, 2025
146825f
Update packages/langchain/src/orchestration/util.ts
KavithaSiva May 22, 2025
80f1e7d
Update packages/langchain/src/orchestration/util.ts
KavithaSiva May 22, 2025
d08f4a8
chore: review comment
KavithaSiva May 22, 2025
1eac3c7
chore: Remove test file and adapt
KavithaSiva May 22, 2025
9003b02
chore: adapt sample code
KavithaSiva May 22, 2025
92ea3b3
chore: address review comment
KavithaSiva May 22, 2025
3df806a
chore: improve comment
KavithaSiva May 22, 2025
60a4f44
Merge branch 'main' into langchain-orchestration-client-streaming
KavithaSiva May 22, 2025
b4dae2b
chore: add test for testing timeout
KavithaSiva May 22, 2025
d87c204
Merge branch 'langchain-orchestration-client-streaming' of github.com…
KavithaSiva May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/chilly-steaks-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

Check warning on line 1 in .changeset/chilly-steaks-divide.md

View workflow job for this annotation

GitHub Actions / grammar-check

[vale] reported by reviewdog 🐶 [SAP.Readability] The text is very complex! It has a grade score of >14. Raw Output: {"message": "[SAP.Readability] The text is very complex! It has a grade score of \u003e14.", "location": {"path": ".changeset/chilly-steaks-divide.md", "range": {"start": {"line": 1, "column": 1}}}, "severity": "WARNING"}
'@sap-ai-sdk/orchestration': minor
'@sap-ai-sdk/langchain': minor
---

[New Functionality] Support streaming in LangChain orchestration client.
5 changes: 4 additions & 1 deletion packages/langchain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ export type {
AzureOpenAiChatCallOptions,
ChatAzureOpenAIToolType
} from './openai/index.js';
export { OrchestrationClient } from './orchestration/index.js';
export {
OrchestrationClient,
OrchestrationMessageChunk
} from './orchestration/index.js';
export type {
OrchestrationCallOptions,
LangchainOrchestrationModuleConfig
Expand Down
202 changes: 202 additions & 0 deletions packages/langchain/src/orchestration/__snapshots__/client.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,205 @@ exports[`orchestration service client returns successful response when timeout i
"type": "constructor",
}
`;

exports[`orchestration service client supports streaming responses 1`] = `
{
"id": [
"langchain_core",
"messages",
"AIMessageChunk",
],
"kwargs": {
"additional_kwargs": {
"module_results": {
"llm": {
"choices": [
{
"delta": {
"content": "The SAP Cloud SDK is a comprehensive development toolkit designed to simplify and accelerate the creation of applications that integrate with SAP solutions, particularly those built on the SAP Business Technology Platform (BTP). It provides developers with libraries, tools, and best practices that streamline the process of connecting to SAP systems, such as S/4HANA and other services available on the SAP Cloud Platform.

Key features of the SAP Cloud SDK include:

1. **Simplified Connectivity**: The SDK offers pre-built libraries to easily interact with SAP services, providing capabilities for authentication, service consumption, and OData/REST client generation.

2. **Multi-cloud Support**: It supports multiple cloud environments, ensuring that applications remain flexible and can be deployed across various cloud providers.

3. **Best Practices and Guidelines**: The SDK includes best practices for development, ensuring high-quality, scalable, and maintainable code.

4. **Project Scaffolding and Code Samples**: Developers can quickly start their projects using provided templates and samples, accelerating the development process and reducing the learning curve.

5. **Extensive Documentation and Community Support**: Ample documentation, tutorials, and an active community help developers overcome challenges and adopt the SDK efficiently.

Overall, the SAP Cloud SDK is an essential tool for developers looking to build cloud-native applications and extensions that seamlessly integrate with SAP's enterprise solutions.",
"role": "assistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistantassistant",
},
"finish_reason": "stop",
"index": 0,
},
],
"created": 1734524005,
"id": "chatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wpchatcmpl-AfnDZfYvuE4SDplaLGF9v0PJjB0wp",
"model": "gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06",
"object": "chat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunk",
"system_fingerprint": "fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48fp_4e924a4b48",
"usage": {
"completion_tokens": 271,
"prompt_tokens": 17,
"total_tokens": 288,
},
},
"templating": [
{
"content": "Give me a short introduction of SAP Cloud SDK.",
"role": "user",
},
],
},
"request_id": "66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b66172762-8c47-4438-89e7-2689be8f370b",
},
"content": "The SAP Cloud SDK is a comprehensive development toolkit designed to simplify and accelerate the creation of applications that integrate with SAP solutions, particularly those built on the SAP Business Technology Platform (BTP). It provides developers with libraries, tools, and best practices that streamline the process of connecting to SAP systems, such as S/4HANA and other services available on the SAP Cloud Platform.

Key features of the SAP Cloud SDK include:

1. **Simplified Connectivity**: The SDK offers pre-built libraries to easily interact with SAP services, providing capabilities for authentication, service consumption, and OData/REST client generation.

2. **Multi-cloud Support**: It supports multiple cloud environments, ensuring that applications remain flexible and can be deployed across various cloud providers.

3. **Best Practices and Guidelines**: The SDK includes best practices for development, ensuring high-quality, scalable, and maintainable code.

4. **Project Scaffolding and Code Samples**: Developers can quickly start their projects using provided templates and samples, accelerating the development process and reducing the learning curve.

5. **Extensive Documentation and Community Support**: Ample documentation, tutorials, and an active community help developers overcome challenges and adopt the SDK efficiently.

Overall, the SAP Cloud SDK is an essential tool for developers looking to build cloud-native applications and extensions that seamlessly integrate with SAP's enterprise solutions.",
"id": undefined,
"invalid_tool_calls": [],
"response_metadata": {
"completion": 0,
"finish_reason": "stop",
"prompt": 0,
"token_usage": {
"completion_tokens": 271,
"prompt_tokens": 17,
"total_tokens": 288,
},
},
"tool_call_chunks": [],
"tool_calls": [],
"usage_metadata": {
"input_tokens": 17,
"output_tokens": 271,
"total_tokens": 288,
},
},
"lc": 1,
"type": "constructor",
}
`;

exports[`orchestration service client supports streaming responses with tool calls 1`] = `
{
"id": [
"langchain_core",
"messages",
"AIMessageChunk",
],
"kwargs": {
"additional_kwargs": {
"module_results": {
"llm": {
"choices": [
{
"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?

"tool_calls": [
{
"function": {
"arguments": "{"a": 2, "b": 3}",
"name": "add",
},
"id": "call_HPgxxSmD2ctYfcJ3gp1JBc7i",
"index": 0,
"type": "function",
},
{
"function": {
"arguments": "{"a": 2, "b": 3}",
"name": "multiply",
},
"id": "call_PExve0Dd9hxD8hOk4Uhr1yhO",
"index": 1,
"type": "function",
},
],
},
"finish_reason": "tool_calls",
"index": 0,
},
],
"created": 1747660479,
"id": "chatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjdchatcmpl-BYucBnhXmLZ6QGcjM6Ac76HKLibjd",
"model": "gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06gpt-4o-2024-08-06",
"object": "chat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunkchat.completion.chunk",
"system_fingerprint": "fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0fp_ee1d74bde0",
},
"templating": [
{
"content": "Add 2 and 3, and multiply 2 and 3.",
"role": "user",
},
],
},
"request_id": "b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05b851a041-7bcd-463f-881a-7cb40526bc05",
},
"content": "",
"id": undefined,
"invalid_tool_calls": [],
"response_metadata": {
"completion": 0,
"finish_reason": "tool_calls",
"prompt": 0,
},
"tool_call_chunks": [
{
"args": "{"a": 2, "b": 3}",
"id": "call_HPgxxSmD2ctYfcJ3gp1JBc7i",
"index": 0,
"name": "add",
"type": "tool_call_chunk",
},
{
"args": "{"a": 2, "b": 3}",
"id": "call_PExve0Dd9hxD8hOk4Uhr1yhO",
"index": 1,
"name": "multiply",
"type": "tool_call_chunk",
},
],
"tool_calls": [
{
"args": {
"a": 2,
"b": 3,
},
"id": "call_HPgxxSmD2ctYfcJ3gp1JBc7i",
"name": "add",
"type": "tool_call",
},
{
"args": {
"a": 2,
"b": 3,
},
"id": "call_PExve0Dd9hxD8hOk4Uhr1yhO",
"name": "multiply",
"type": "tool_call",
},
],
"usage_metadata": undefined,
},
"lc": 1,
"type": "constructor",
}
`;
114 changes: 114 additions & 0 deletions packages/langchain/src/orchestration/__snapshots__/util.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`mapOrchestrationChunkToLangChainMessageChunk should map a chunk with content to AIMessageChunk: AIMessageChunk with content 1`] = `
{
"id": [
"langchain_core",
"messages",
"AIMessageChunk",
],
"kwargs": {
"additional_kwargs": {
"module_results": {
"llm": {
"choices": [
{
"delta": {
"content": "Test content",
"role": "assistant",
"tool_calls": undefined,
},
"finish_reason": "",
"index": 0,
},
],
"created": 1634840000,
"id": "test-id",
"model": "test-model",
"object": "chat.completion.chunk",
"system_fingerprint": "fp_123",
"usage": undefined,
},
},
"request_id": "req-123",
},
"content": "Test content",
"invalid_tool_calls": [],
"response_metadata": {},
"tool_call_chunks": [],
"tool_calls": [],
"usage_metadata": undefined,
},
"lc": 1,
"type": "constructor",
}
`;

exports[`mapOrchestrationChunkToLangChainMessageChunk should map a chunk with tool call chunks to AIMessageChunk: AIMessageChunk with tool call chunks 1`] = `
{
"id": [
"langchain_core",
"messages",
"AIMessageChunk",
],
"kwargs": {
"additional_kwargs": {
"module_results": {
"llm": {
"choices": [
{
"delta": {
"content": "",
"role": "assistant",
"tool_calls": [
{
"function": {
"arguments": "",
"name": "test_function",
},
"id": "call-123",
"index": 0,
"type": "function",
},
],
},
"finish_reason": "",
"index": 0,
},
],
"created": 1634840000,
"id": "test-id",
"model": "test-model",
"object": "chat.completion.chunk",
"system_fingerprint": "fp_123",
"usage": undefined,
},
},
"request_id": "req-123",
},
"content": "",
"invalid_tool_calls": [],
"response_metadata": {},
"tool_call_chunks": [
{
"args": "",
"id": "call-123",
"index": 0,
"name": "test_function",
"type": "tool_call_chunk",
},
],
"tool_calls": [
{
"args": {},
"id": "call-123",
"name": "test_function",
"type": "tool_call",
},
],
"usage_metadata": undefined,
},
"lc": 1,
"type": "constructor",
}
`;
Loading
Loading