npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@latitude-data/sdk

v1.0.0-beta.6

Published

Latitude SDK for Typescript

Downloads

466

Readme

@latitude-data/sdk

Welcome to the Latitude SDK for TypeScript! This SDK is designed to help developers and product teams integrate Latitude's powerful AI features into their applications with ease. Latitude is a platform that simplifies prompt management, testing, and provides valuable insights into AI performance.

🌟 Features

  • Collaborative prompt manager: Work together on prompts with your team.
  • Advanced features: Support for parameters, snippets, logic, and more.
  • Version control: Keep track of different prompt versions.
  • API + SDKs: Easy integration with your applications.
  • Built-in observability: Monitor and evaluate AI performance.
  • Batch or real-time evaluations: Assess prompt performance across various scenarios.
  • Open-source: Driven by the community.

⚡ Quick Start

Installation

To install the SDK, use npm, yarn, or pnpm:

npm install @latitude-data/sdk

or

yarn add @latitude-data/sdk

or

pnpm add @latitude-data/sdk

Usage

Importing the SDK

First, import the necessary classes and types from the SDK:

import { Latitude, Message, StreamChainResponse } from '@latitude-data/sdk'

Initializing the SDK

Create an instance of the Latitude class by providing your API key and optionally a project ID and gateway configuration:

const sdk = new Latitude('your-api-key', {
  projectId: 123, // optional
  gateway: {
    host: 'your-gateway-hostname',
    port: 443,
    ssl: true,
  },
})

Running a Prompt

To run a prompt, use the run method. You can provide a path, project ID, version UUID, parameters, and callbacks for handling events, completion, and errors:

sdk.prompts.run('path/to/prompt', {
  projectId: 123, // optional, defaults to the projectId provided during initialization
  versionUuid: 'version-uuid', // optional, defaults to the live version
  parameters: { key: 'value' }, // optional, depends on whether the prompt expects parameters
  stream: true, // optional, depends on whether you want all events through SSEs or the final event as JSON
  onEvent: ({ event, data }) => {
    console.log('Event:', event, 'Data:', data)
  },
  onFinished: (data: StreamChainResponse) => {
    console.log('Finished:', data)
  },
  onError: (error: Error) => {
    console.error('Error:', error)
  },
})

Chatting with a Prompt

To chat with a prompt, use the chat method. Provide the prompt UUID, an array of messages, and optional callbacks for handling events, completion, and errors:

const messages: Message[] = [
  { role: 'user', content: 'Hello, how are you?' },
  { role: 'assistant', content: 'I am fine, thank you!' },
]

sdk.prompts.chat('prompt-uuid', messages, {
  stream: true, // optional, depends on whether you want all events through SSEs or the final event as JSON
  onEvent: ({ event, data }) => {
    console.log('Event:', event, 'Data:', data)
  },
  onFinished: (data: StreamChainResponse) => {
    console.log('Finished:', data)
  },
  onError: (error: Error) => {
    console.error('Error:', error)
  },
})

Handling Stream Responses

The SDK handles server-sent events (SSE) streams internally. You can provide callbacks to handle events, completion, and errors as shown in the examples above.

Error Handling

Both the run and chat methods accept an onError callback to handle any errors that occur during the request or stream processing.

onError: (error: Error) => {
  console.error('Error:', error)
}

Publish a new version

If you have publish permissions you can do:

pnpm version patch && pnpm build && pnpm publish

That's it! You are now ready to integrate Latitude's powerful AI features into your TypeScript application using the Latitude SDK. For more detailed information and advanced usage, please refer to the official documentation.