Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

langbase

Package Overview
Dependencies
Maintainers
0
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

langbase

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

  • 0.2.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
405
increased by44.13%
Maintainers
0
Weekly downloads
 
Created
Source

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.

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 Pipe API key

# Add your Pipe API key here.
LANGBASE_PIPE_API_KEY="pipe_12345`"

Generate text generateText()

For more check the API reference of generateText()

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

// 1. Initiate the Pipe.
const pipe = new Pipe({
	// Make sure you have a .env file with any pipe you wanna use.
	// As a demo we're using a pipe that has less wordy responses.
	apiKey: process.env.LANGBASE_PIPE_API_KEY!,
});

// 3. Generate the text by asking a question.
const result = await pipe.generateText({
	messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
});

// 4. Done: You got the generated completion.
console.log(result.completion);

Stream text streamText()

For more check the API reference of streamText()

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

// 1. Initiate the Pipe.
const pipe = new Pipe({
	// Make sure you have a .env file with any pipe you wanna use.
	// As a demo we're using a pipe that has less wordy responses.
	apiKey: process.env.LANGBASE_PIPE_API_KEY!,
});

// 2. Generate a stream by asking a question
const stream = await pipe.streamText({
	messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
});

// 3. Print the stream
for await (const chunk of stream) {
	// Streaming text part — a single word or several.
	const textPart = chunk.choices[0]?.delta?.content || '';

	// Demo: Print the stream — you can use it however.
	process.stdout.write(textPart);
}

Check out more examples in the docs

Keywords

FAQs

Package last updated on 28 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc