Skip to content

Latest commit

 

History

History
136 lines (94 loc) · 3.53 KB

README.md

File metadata and controls

136 lines (94 loc) · 3.53 KB

Langbase SDK

The AI SDK for building declarative and composable AI-powered LLM products.

Documentation

Check the Langbase SDK documentation for more details.

The following examples are for reference only. Prefer docs for the latest information.

Getting Started with langbase SDK

Installation

First, install the langbase package using npm or yarn:

npm install langbase

or

pnpm add langbase

or

yarn add langbase

Usage

You can langbase.pipe.run() to generate or stream from a Pipe.

Check our SDK documentation for more details.

Example projects

Check the following examples:

Node.js Example Code

Node.js Examples

Add a .env file with your LANGBASE API key

# Add your Langbase API key here: https://langbase.com/docs/api-reference/api-keys
LANGBASE_API_KEY="your-api-key"

Generate text langbase.pipe.run()

Set the stream to false. For more, check the API reference of langbase.pipe.run()

import 'dotenv/config';
import {Langbase} from 'langbase';

// 1. Initiate the Langbase.
const langbase = new Langbase({
    // Make sure you have a .env file with LANGBASE_API_KEY.
    apiKey: process.env.LANGBASE_API_KEY!,
});

async function main() {
    // 2. Run the pipe with a question.
    const response = await langbase.pipe.run({
        stream: false,
        name: 'summary' // pipe name to run
        messages: [
            {
                role: 'user',
                content: 'Who is an AI Engineer?',
            },
        ],
    });

    // 3. Print the response.
    console.log('response: ', response);
}

main();

Set the stream to true. For more, check the API reference of langbase.pipe.run()

import 'dotenv/config';
import {getRunner, Langbase} from 'langbase';

// 1. Initiate the Langbase.
const langbase = new Langbase({
    // Make sure you have a .env file with LANGBASE_API_KEY.
    apiKey: process.env.LANGBASE_API_KEY!,
});

async function main() {
    const userMsg = 'Who is an AI Engineer?';

    // 2. Run the pipe with a question.
    const {****stre**am**} = await langbase.pipe.run({
        stream: true,
        name: 'summary', // pipe name to run
        messages: [{role: 'user', content: userMsg}],
    });

    // 3. Get the runner and listen to the content.
    const runner = getRunner(stream);

    // 4. Print the response.
    runner.on('content', content => {
        process.stdout.write(content);
    });
}

main();

Check out more examples in the docs