Skip to main content

JavaScript Library

Similar to our Python library, we offer a client to track experiments in JavaScript/TypeScript.

  • Log metrics from your Node server and display them in interactive plots on W&B
  • Debug LLM applications with interactive traces
  • Debug LangChain.js usage

This library is compatible with Node and modern JS run times.

You can find the source code for the JavaScript client in the Github repository.

info

Our JavaScript integration is still in Beta, if you run into issues please let us know!

Installation

npm install @wandb/sdk
# or ...
yarn add @wandb/sdk

### Usage

TypeScript/ESM:

import wandb from '@wandb/sdk'

async function track() {
await wandb.init({config: {test: 1}});
wandb.log({acc: 0.9, loss: 0.1});
wandb.log({acc: 0.91, loss: 0.09});
await wandb.finish();
}

await track()
caution

We spawn a separate MessageChannel to process all api calls async. This will cause your script to hang if you don't call await wandb.finish().

Node/CommonJS:

const wandb = require('@wandb/sdk').default;

We're currently missing a lot of the functionality found in our Python SDK, but basic logging functionality is available. We'll be adding additional features like Tables soon.

Authentication and Settings

In node environments we look for process.env.WANDB_API_KEY and prompt for it's input if we have a TTY. In non-node environments we look for sessionStorage.getItem("WANDB_API_KEY"). Additional settings can be found here.

Integrations

Our Python integrations are widely used by our community, and we hope to build out more JavaScript integrations to help LLM app builders leverage whatever tool they want.

If you have any requests for additional integrations, we'd love you to open an issue with details about the request.

## LangChain.js

This library integrates with the popular library for building LLM applications, LangChain.js version >= 0.0.75.

### Usage

import {WandbTracer} from '@wandb/sdk/integrations/langchain';

const wbTracer = await WandbTracer.init({project: 'langchain-test'});
// run your langchain workloads...
chain.call({input: "My prompt"}, wbTracer)
await WandbTracer.finish();
caution

We spawn a seperate MessageChannel to process all api calls async. This will cause your script to hang if you don't call await WandbTracer.finish().

See this test for a more detailed example.

Was this page helpful?👍👎