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

polyglot-sdk

v1.0.4

Published

Polyglot is a powerful and flexible TypeScript SDK for interacting with multiple Language Model APIs.

Downloads

269

Readme

Polyglot-SDK Banner

Polyglot SDK

Polyglot is a powerful and flexible TypeScript SDK for interacting with multiple Language Model APIs. It provides a unified interface for various LLMs, along with advanced features like streaming responses, caching, middleware support, and error handling.

Features

  • Multi-model Support: Easily integrate and switch between different LLM providers (supports Claude, ChatGPT, Mistral, and Gemini).
  • Streaming Responses: Get real-time responses from supported models.
  • Caching Layer: Improve performance with built-in caching for repeated queries.
  • Middleware System: Customize request/response processing with a flexible middleware system.
  • Robust Error Handling: Automatically retry on transient errors and provide clear error messages.
  • TypeScript Support: Full TypeScript support for improved developer experience.
  • Extensible Architecture: Easily add new models or extend functionality.
  • Rate Limiting: Built-in rate limiting to prevent API quota exhaustion.

Installation

npm install polyglot-sdk

Quick Start

import { Polyglot, Models, ModelConfig } from "polyglot-sdk";

const polyglot = new Polyglot();

const claudeConfig: ModelConfig = {
  apiKey: "your-claude-api-key",
  model: "claude-3-5-sonnet-20240620",
};
polyglot.addModel("claude", new Models.ClaudeModel(claudeConfig));

async function getResponse() {
  const messages = [{ role: "user", content: "Hello, how are you?" }];
  const response = await polyglot.generateResponse("claude", messages);
  console.log(response.content);
}

getResponse();

Supported Platforms and Models

| Platform | Supported Models | | ------------------ | ------------------------------------------------------------------------------------------------------ | | Claude (Anthropic) | claude-3-5-sonnet-20240620, claude-3-opus-20240229, claude-3-sonnet-20240229, claude-3-haiku-20240307 | | ChatGPT (OpenAI) | gpt-4o, gpt-4o-mini, gpt-4-turbo, gpt-3.5-turbo | | Mistral AI | open-mistral-nemo, mistral-small-latest, mistral-medium-latest, mistral-large-latest, codestral-latest | | Google Gemini | gemini-1.5-pro, gemini-1.5-flash, gemini-1.0-pro |

Advanced Usage

Streaming Responses

const stream = polyglot.generateStreamingResponse("claude", messages);
stream.on("data", (chunk) => console.log("Received chunk:", chunk.toString()));
stream.on("end", () => console.log("Stream ended"));

Using Middleware

polyglot.use(async (messages, next) => {
  console.log("Sending messages:", messages);
  const response = await next(messages);
  console.log("Received response:", response);
  return response;
});

Caching

Caching is enabled by default. To disable:

const response = await polyglot.generateResponse("claude", messages, {
  useCache: false,
});

Switching Models

You can easily switch between different models of the same platform:

const chatgptModel = polyglot.getModel("chatgpt");
chatgptModel.setModel("gpt-4-turbo");

API Reference

For detailed API reference, please refer to the TypeScript definitions in the types.ts file.

License

This project is licensed under the MIT License.