From 1d3f19763d09bf361b11da3b6bf8ec5471329353 Mon Sep 17 00:00:00 2001 From: Lauren Hirata Singh Date: Tue, 13 May 2025 11:36:45 -0700 Subject: [PATCH] add js sample code back --- docs/docs/cloud/quick_start.md | 35 ++++++++ .../langgraph-platform/local-server.md | 82 ++++++++++++++++--- 2 files changed, 106 insertions(+), 11 deletions(-) diff --git a/docs/docs/cloud/quick_start.md b/docs/docs/cloud/quick_start.md index c9c47e04c..70c918368 100644 --- a/docs/docs/cloud/quick_start.md +++ b/docs/docs/cloud/quick_start.md @@ -115,6 +115,41 @@ You can now test the API: print("\n\n") ``` +=== "JavaScript SDK" + + 1. Install the LangGraph JS SDK + + ```shell + npm install @langchain/langgraph-sdk + ``` + + 1. Send a message to the assistant (threadless run): + + ```js + const { Client } = await import("@langchain/langgraph-sdk"); + + const client = new Client({ apiUrl: "your-deployment-url", apiKey: "your-langsmith-api-key" }); + + const streamResponse = client.runs.stream( + null, // Threadless run + "agent", // Assistant ID + { + input: { + "messages": [ + { "role": "user", "content": "What is LangGraph?"} + ] + }, + streamMode: "messages", + } + ); + + for await (const chunk of streamResponse) { + console.log(`Receiving new event of type: ${chunk.event}...`); + console.log(JSON.stringify(chunk.data)); + console.log("\n\n"); + } + ``` + === "Rest API" ```bash diff --git a/docs/docs/tutorials/langgraph-platform/local-server.md b/docs/docs/tutorials/langgraph-platform/local-server.md index f83d19534..f882b4ca7 100644 --- a/docs/docs/tutorials/langgraph-platform/local-server.md +++ b/docs/docs/tutorials/langgraph-platform/local-server.md @@ -18,11 +18,19 @@ pip install --upgrade "langgraph-cli[inmem]" ## 2. Create a LangGraph app 🌱 -Create a new app from the [`new-langgraph-project` template](https://github.com/langchain-ai/new-langgraph-project). This template demonstrates a simple chatbot that maintains chat memory, which allows for coherent conversations across multiple interactions. +Create a new app from the [`new-langgraph-project` template](https://github.com/langchain-ai/new-langgraph-project) or [`new-langgraphjs-projec` template](https://github.com/langchain-ai/new-langgraphjs-project). This template demonstrates a simple chatbot that maintains chat memory, which allows for coherent conversations across multiple interactions. -```shell -langgraph new path/to/your/app --template new-langgraph-project -``` +=== "Python server" + + ```shell + langgraph new path/to/your/app --template new-langgraph-project + ``` + +=== "Node server" + + ```shell + langgraph new path/to/your/app --template new-langgraphjs-project + ``` !!! tip "Additional templates" @@ -32,10 +40,19 @@ langgraph new path/to/your/app --template new-langgraph-project In the root of your new LangGraph app, install the dependencies in `edit` mode so your local changes are used by the server: -```shell -cd path/to/your/app -pip install -e . -``` +=== "Python server" + + ```shell + cd path/to/your/app + pip install -e . + ``` + +=== "Node server" + + ```shell + cd path/to/your/app + yarn install + ``` ## 4. Create a `.env` file @@ -49,9 +66,16 @@ LANGSMITH_API_KEY=lsv2... Start the LangGraph API server locally: -```shell -langgraph dev -``` +=== "Python server" + + ```shell + langgraph dev + ``` +=== "Node server" + + ```shell + npx @langchain/langgraph-cli dev + ``` Sample output: @@ -151,6 +175,42 @@ For a LangGraph Server running on a custom host/port, update the baseURL paramet print(chunk.data) print("\n\n") ``` + +=== "Javascript SDK" + + 1. Install the LangGraph JS SDK: + + ```shell + npm install @langchain/langgraph-sdk + ``` + + 1. Send a message to the assistant (threadless run): + + ```js + const { Client } = await import("@langchain/langgraph-sdk"); + + // only set the apiUrl if you changed the default port when calling langgraph dev + const client = new Client({ apiUrl: "http://localhost:2024"}); + + const streamResponse = client.runs.stream( + null, // Threadless run + "agent", // Assistant ID + { + input: { + "messages": [ + { "role": "user", "content": "What is LangGraph?"} + ] + }, + streamMode: "messages-tuple", + } + ); + + for await (const chunk of streamResponse) { + console.log(`Receiving new event of type: ${chunk.event}...`); + console.log(JSON.stringify(chunk.data)); + console.log("\n\n"); + } + ``` === "Rest API"