Skip to content

Commit 4faf733

Browse files
Merge branch 'upstash-vector-namespace-feature' of https://github.com/fahreddinozcan/langchainjs-upstash into upstash-vector-namespace-feature
2 parents c687250 + b8e3f57 commit 4faf733

File tree

31 files changed

+250
-116
lines changed

31 files changed

+250
-116
lines changed

.github/workflows/build-examples.yml

-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,5 @@ jobs:
3838
node-version: 18.x
3939
- name: Install dependencies
4040
run: yarn install --immutable
41-
- name: Build Core
42-
run: yarn turbo:command build --filter=@langchain/core
43-
- name: Build all except LangChain Community & Examples
44-
run: yarn turbo:command build --filter=!examples --filter=!@langchain/community --filter=!core_docs --filter=!api_refs --filter=!create-langchain-integration
45-
- name: Build LangChain Community
46-
run: yarn turbo:command build --filter=@langchain/community
4741
- name: Build examples
4842
run: yarn turbo:command build --filter=examples

.github/workflows/test-exports.yml

+18-45
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,9 @@ jobs:
3434
- name: Install dependencies
3535
run: yarn install --immutable
3636

37-
- name: Build "@langchain/community"
38-
run: yarn workspace @langchain/community build
37+
- name: Build dependencies
38+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
3939
shell: bash
40-
env:
41-
SKIP_API_DOCS: true
42-
- name: Build LangChain
43-
run: yarn workspace langchain build
44-
shell: bash
45-
env:
46-
SKIP_API_DOCS: true
4740

4841
- name: Test esbuild exports
4942
run: docker compose -f environment_tests/docker-compose.yml run test-exports-esbuild
@@ -60,16 +53,9 @@ jobs:
6053
- name: Install dependencies
6154
run: yarn install --immutable
6255

63-
- name: Build "@langchain/community"
64-
run: yarn workspace @langchain/community build
65-
shell: bash
66-
env:
67-
SKIP_API_DOCS: true
68-
- name: Build LangChain
69-
run: yarn workspace langchain build
56+
- name: Build dependencies
57+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
7058
shell: bash
71-
env:
72-
SKIP_API_DOCS: true
7359

7460
- name: Test esm exports
7561
run: docker compose -f environment_tests/docker-compose.yml run test-exports-esm
@@ -86,16 +72,9 @@ jobs:
8672
- name: Install dependencies
8773
run: yarn install --immutable
8874

89-
- name: Build "@langchain/community"
90-
run: yarn workspace @langchain/community build
91-
shell: bash
92-
env:
93-
SKIP_API_DOCS: true
94-
- name: Build LangChain
95-
run: yarn workspace langchain build
75+
- name: Build dependencies
76+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
9677
shell: bash
97-
env:
98-
SKIP_API_DOCS: true
9978

10079
- name: Test cjs exports
10180
run: docker compose -f environment_tests/docker-compose.yml run test-exports-cjs
@@ -111,11 +90,10 @@ jobs:
11190
cache: "yarn"
11291
- name: Install dependencies
11392
run: yarn install --immutable
114-
- name: Build
115-
run: yarn workspace langchain build
93+
94+
- name: Build dependencies
95+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
11696
shell: bash
117-
env:
118-
SKIP_API_DOCS: true
11997

12098
- name: Test cf exports
12199
run: docker compose -f environment_tests/docker-compose.yml run test-exports-cf
@@ -131,11 +109,10 @@ jobs:
131109
cache: "yarn"
132110
- name: Install dependencies
133111
run: yarn install --immutable
134-
- name: Build
135-
run: yarn workspace langchain build
112+
113+
- name: Build dependencies
114+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
136115
shell: bash
137-
env:
138-
SKIP_API_DOCS: true
139116

140117
- name: Test vercel exports
141118
run: docker compose -f environment_tests/docker-compose.yml run test-exports-vercel
@@ -151,11 +128,10 @@ jobs:
151128
cache: "yarn"
152129
- name: Install dependencies
153130
run: yarn install --immutable
154-
- name: Build
155-
run: yarn workspace langchain build
131+
132+
- name: Build dependencies
133+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
156134
shell: bash
157-
env:
158-
SKIP_API_DOCS: true
159135

160136
- name: Test vite exports
161137
run: docker compose -f environment_tests/docker-compose.yml run test-exports-vite
@@ -171,11 +147,10 @@ jobs:
171147
cache: "yarn"
172148
- name: Install dependencies
173149
run: yarn install --immutable
174-
- name: Build
175-
run: yarn workspace langchain build
150+
151+
- name: Build dependencies
152+
run: yarn build --filter=langchain --filter=@langchain/anthropic --filter=@langchain/community --filter=@langchain/openai
176153
shell: bash
177-
env:
178-
SKIP_API_DOCS: true
179154

180155
- name: Test compiling exports with tsc
181156
run: docker compose -f environment_tests/docker-compose.yml run test-exports-tsc
@@ -194,8 +169,6 @@ jobs:
194169
# - name: Build
195170
# run: yarn workspace langchain build
196171
# shell: bash
197-
# env:
198-
# SKIP_API_DOCS: true
199172

200173
# - name: Test bun exports
201174
# run: docker compose -f environment_tests/docker-compose.yml run test-exports-bun

.github/workflows/unit-tests-langchain-community.yml

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,5 @@ jobs:
5050
cache: "yarn"
5151
- name: Install dependencies
5252
run: yarn install --immutable
53-
- name: Build
54-
run: yarn run build --filter=@langchain/community
5553
- name: Test
5654
run: yarn run test:unit:ci --filter=@langchain/community

.github/workflows/unit-tests-langchain-core.yml

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,5 @@ jobs:
4949
cache: "yarn"
5050
- name: Install dependencies
5151
run: yarn install --immutable
52-
- name: Build
53-
run: yarn run build --filter=@langchain/core
5452
- name: Test
5553
run: yarn run test:unit:ci --filter=@langchain/core

.github/workflows/unit-tests-langchain-integrations.yml

-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,5 @@ jobs:
5151
cache: "yarn"
5252
- name: Install dependencies
5353
run: yarn install --immutable
54-
- name: Build
55-
run: yarn run build --filter=!@langchain/community --filter=!@langchain/core --filter=!langchain --filter=!api_refs --filter=!core_docs --filter=!create-langchain-integration --filter=!examples
5654
- name: Test
5755
run: yarn run test:unit:ci --filter=!@langchain/community --filter=!@langchain/core --filter=!langchain --filter=!api_refs --filter=!core_docs --filter=!create-langchain-integration --filter=!examples

.github/workflows/unit-tests-langchain.yml

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ jobs:
5050
cache: "yarn"
5151
- name: Install dependencies
5252
run: yarn install --immutable
53-
- name: Build
54-
run: yarn run build --filter=langchain
5553
- name: Test
5654
run: yarn run test:unit:ci --filter=langchain
5755
env:

docs/api_refs/typedoc_plugins/hide_underscore_lc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const SCRIPT_HTML = `<script>
2323
const VERSION_DROPDOWN_HTML = `<div class="version-select">
2424
<select id="version-dropdown" onchange="window.location.href=this.value;">
2525
<option selected value="">v0.2</option>
26-
<option value="https://v01.v02.api.js.langchain.com/">v0.1</option>
26+
<option value="https://v01.api.js.langchain.com/">v0.1</option>
2727
</select>
2828
</div>`;
2929

docs/core_docs/docs/how_to/index.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ All of LangChain components can easily be extended to support your own versions.
190190
- [How to: stream agentic data to the client](/docs/how_to/stream_agent_client)
191191
- [How to: stream structured output to the client](/docs/how_to/stream_tool_client)
192192

193+
### Multimodal
194+
195+
- [How to: pass multimodal data directly to models](/docs/how_to/multimodal_inputs/)
196+
- [How to: use multimodal prompts](/docs/how_to/multimodal_prompts/)
197+
193198
## Use cases
194199

195200
These guides cover use-case specific details.

docs/core_docs/docs/tutorials/llm_chain.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
"id": "fedf6f13",
313313
"metadata": {},
314314
"source": [
315-
"Next, we can create the PromptTemplate. This will be a combination of the `systemTemplate` as well as a simpler template for where the put the text"
315+
"Next, we can create the PromptTemplate. This will be a combination of the `systemTemplate` as well as a simpler template for where to put the text"
316316
]
317317
},
318318
{

docs/core_docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"eslint-plugin-react": "^7.30.1",
6565
"eslint-plugin-react-hooks": "^4.6.0",
6666
"glob": "^10.3.10",
67-
"prettier": "^2.7.1",
67+
"prettier": "^2.8.3",
6868
"rimraf": "^5.0.1",
6969
"supabase": "^1.148.6",
7070
"swc-loader": "^0.2.3",

langchain-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@langchain/core",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "Core LangChain.js abstractions and schemas",
55
"type": "module",
66
"engines": {

langchain-core/src/runnables/base.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export abstract class Runnable<
825825
): AsyncGenerator<StreamEvent> {
826826
const eventStreamer = new EventStreamCallbackHandler({
827827
...streamOptions,
828-
autoClose: false,
828+
autoClose: true,
829829
});
830830
const config = ensureConfig(options);
831831
const runId = config.runId ?? uuidv4();
@@ -845,18 +845,14 @@ export abstract class Runnable<
845845
// add each chunk to the output stream
846846
const outerThis = this;
847847
async function consumeRunnableStream() {
848-
try {
849-
const runnableStream = await outerThis.stream(input, config);
850-
const tappedStream = eventStreamer.tapOutputIterable(
851-
runId,
852-
runnableStream
853-
);
854-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
855-
for await (const _ of tappedStream) {
856-
// Just iterate so that the callback handler picks up events
857-
}
858-
} finally {
859-
await eventStreamer.writer.close();
848+
const runnableStream = await outerThis.stream(input, config);
849+
const tappedStream = eventStreamer.tapOutputIterable(
850+
runId,
851+
runnableStream
852+
);
853+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
854+
for await (const _ of tappedStream) {
855+
// Just iterate so that the callback handler picks up events
860856
}
861857
}
862858
const runnableStreamConsumePromise = consumeRunnableStream();

langchain-core/src/tracers/event_stream.ts

+16
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ export class EventStreamCallbackHandler extends BaseTracer {
277277
} finally {
278278
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
279279
tappedPromiseResolver!();
280+
// Don't delete from the map to keep track of which runs have been tapped.
280281
}
281282
} else {
282283
// otherwise just pass through
@@ -596,4 +597,19 @@ export class EventStreamCallbackHandler extends BaseTracer {
596597
runInfo
597598
);
598599
}
600+
601+
async onRunCreate(run: Run): Promise<void> {
602+
if (this.rootId === undefined) {
603+
this.rootId = run.id;
604+
}
605+
}
606+
607+
async onRunUpdate(run: Run): Promise<void> {
608+
if (run.id === this.rootId && this.autoClose) {
609+
const pendingPromises = [...this.tappedPromises.values()];
610+
void Promise.all(pendingPromises).finally(() => {
611+
void this.writer.close();
612+
});
613+
}
614+
}
599615
}

langchain/src/agents/tests/create_tool_calling_agent.int.test.ts

+39
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,42 @@ test("createToolCallingAgent works", async () => {
3939
// an investigation into why such a short generation was returned.
4040
expect(result.output.length).toBeGreaterThan(10);
4141
});
42+
43+
test("createToolCallingAgent stream events works", async () => {
44+
const prompt = ChatPromptTemplate.fromMessages([
45+
["system", "You are a helpful assistant"],
46+
["placeholder", "{chat_history}"],
47+
["human", "{input}"],
48+
["placeholder", "{agent_scratchpad}"],
49+
]);
50+
const llm = new ChatOpenAI({
51+
modelName: "gpt-4o",
52+
temperature: 0,
53+
});
54+
const agent = await createToolCallingAgent({
55+
llm,
56+
tools,
57+
prompt,
58+
});
59+
const agentExecutor = new AgentExecutor({
60+
agent,
61+
tools,
62+
});
63+
const input = "what is the current weather in SF?";
64+
const eventStream = agentExecutor.streamEvents(
65+
{
66+
input,
67+
},
68+
{
69+
version: "v2",
70+
}
71+
);
72+
73+
for await (const event of eventStream) {
74+
const eventType = event.event;
75+
console.log("Event type: ", eventType);
76+
if (eventType === "on_chat_model_stream") {
77+
console.log("Content: ", event.data);
78+
}
79+
}
80+
});

libs/create-langchain-integration/.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
"no-process-env": 2,
3030
"no-instanceof/no-instanceof": 2,
3131
"@typescript-eslint/explicit-module-boundary-types": 0,
32+
"@typescript-eslint/no-explicit-any": "warn",
3233
"@typescript-eslint/no-empty-function": 0,
3334
"@typescript-eslint/no-shadow": 0,
3435
"@typescript-eslint/no-empty-interface": 0,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json.schemastore.org/prettierrc",
3+
"printWidth": 80,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"semi": true,
7+
"singleQuote": false,
8+
"quoteProps": "as-needed",
9+
"jsxSingleQuote": false,
10+
"trailingComma": "es5",
11+
"bracketSpacing": true,
12+
"arrowParens": "always",
13+
"requirePragma": false,
14+
"insertPragma": false,
15+
"proseWrap": "preserve",
16+
"htmlWhitespaceSensitivity": "css",
17+
"vueIndentScriptAndStyle": false,
18+
"endOfLine": "lf"
19+
}

libs/create-langchain-integration/helpers/git.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,29 @@ function isInGitRepository(): boolean {
77
try {
88
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
99
return true;
10-
} catch (_) {}
10+
} catch (_) {
11+
// no-op
12+
}
1113
return false;
1214
}
1315

1416
function isInMercurialRepository(): boolean {
1517
try {
1618
execSync("hg --cwd . root", { stdio: "ignore" });
1719
return true;
18-
} catch (_) {}
20+
} catch (_) {
21+
// no-op
22+
}
1923
return false;
2024
}
2125

2226
function isDefaultBranchSet(): boolean {
2327
try {
2428
execSync("git config init.defaultBranch", { stdio: "ignore" });
2529
return true;
26-
} catch (_) {}
30+
} catch (_) {
31+
// no-op
32+
}
2733
return false;
2834
}
2935

@@ -54,7 +60,9 @@ export function tryGitInit(root: string): boolean {
5460
if (didInit) {
5561
try {
5662
fs.rmSync(path.join(root, ".git"), { recursive: true, force: true });
57-
} catch (_) {}
63+
} catch (_) {
64+
// no-op
65+
}
5866
}
5967
return false;
6068
}

0 commit comments

Comments
 (0)