Langbase SDK
The AI framework for building declarative and composable AI-powered LLM products.
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 generateText
or streamText
based on the type of a pipe.
import 'dotenv/config';
import {Pipe} from 'langbase';
const pipeStreamOff = new Pipe({
apiKey: process.env.PIPE_LESS_WORDY!,
});
const result = await pipeStreamOff.generateText({
messages: [{role: 'user', content: 'Who is Ahmad Awais?'}],
});
console.log(result.completion);
const pipeStreaming = new Pipe({
apiKey: process.env.PIPE_LESS_WORDY_STREAM!,
});
const stream = await pipeStreaming.streamText({
messages: [{role: 'user', content: 'Who is Ahmad Awais?'}],
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}