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

llm-distillery

v1.1.0

Published

Use LLMs to run map-reduce summarization tasks on large documents until a target token size is met.

Downloads

708

Readme

🍶 LLM Distillery

Use LLMs to distill large texts down to a manageable size by utilizing a map-reduce approach. This ensures that the text fits within a specified token limit, which is crucial when interfacing with Large Language Models (LLMs) in downstreams tasks.


Features

  • Text Distillation: Reduces the size of text based on token count without losing the essence of the content.
  • Chunking and Summarization: Uses the semantic-chunking library to intelligently split text into manageable chunks that are then summarized.
  • Customizable Parameters: Allows fine-tuning of various parameters like target token size, API base URL, and chunking thresholds.

Getting Started

Prerequisites

  • Node.js installed on your system.
  • An API key for running inference of OpenAI API compatible LLM models (together.ai, etc.).

Installation

Add this lib to your code page via npm install

npm install llm-distillery

Basic Usage

The llmDistillery function can be imported and used in your Node.js applications as follows:

import { llmDistillery } from 'llm-distillery';

const text = "Your long text here...";
const options = {
    targetTokenSize: 2048,                          // adjust as needed
    baseUrl: "<openai-api-compatible-url-endpoint>" // example: https://api.together.xyz/v1
    apiKey: "<your_llm_api_key>",
    llmModel: "<llm_model>",                        // example: meta-llama/Llama-3-70b-chat-hf (Llama 3 model name on together.ai)
    stopTokens: ["<|eot_id|>"],                     // stop tokens for Llama 3
    logging: true                                   // set to true for verbose logging
};

llmDistillery(text, options)
    .then(processedText => console.log(processedText))
    .catch(error => console.error(error));

Options Object Parameters

  • targetTokenSize: Desired token size limit for distilled text. (default: 2048)
  • baseUrl: The base URL for the OpenAI API compatible endpoint. (default: "https://api.together.xyz/v1")
  • apiKey: Your API key for accessing LLM endpoint.
  • llmModel: The model identifier of the LLM for your chosen endpoint. (default: "meta-llama/Llama-3-70b-chat-hf" on together.ai)
  • stopTokens: Array representing stopping tokens for LLM responses based on your chosen model. (default ["<|eot_id|>"])
  • maxDistillationLoops: Maximum number of iterations while running distillation (default: 5)
  • tokenizerModel: Tokenizer model used to calculate token sizes. (See table below for options; default "Xenova/paraphrase-multilingual-MiniLM-L12-v2")
  • chunkingThreshold: Threshold for segmenting text into chunks for summarization and distillation. Can be a number between 0 and 1. A lower number will result in greater distillation for each iteration, and will be faster. (default .25)
  • llmContextLength: Context length for the large language model (LLM) you are using. It denotes the maximum number of tokens the LLM can accept when generating chunk summaries. (default 4096, but most LLM's have larger default windows. Llama 3's context window is 8k),
  • llmMaxGenLength: Maximum generation length for the large language model (LLM) you are using. It denotes the maximum number of tokens the LLM can generate in a single response. (default 2048),
  • llmApiRateLimit: Delay in milliseconds between API calls to your chosen LLM provider. This helps to manage the rate at which requests are sent, ensuring that your application does not overload the service or exceed usage policies. (default 500; set to 0 to disable)
  • logging: Enable logging to monitor the various stages of distillation, compression percentages of the original text, etc. (default false)

Tokenizer Models

| model name | |----------------------------------------------| | Xenova/all-MiniLM-L6-v2 | | Xenova/paraphrase-multilingual-MiniLM-L12-v2 | | Xenova/bert-base-uncased | | Xenova/gpt2 | | Xenova/roberta-base | | Xenova/all-distilroberta-v1 | | Xenova/multilingual-e5-large | | Xenova/bert-base-multilingual-uncased | | Xenova/xlm-roberta-base | | BAAI/bge-base-en-v1.5 |

NOTE 🚨 The initial run of llm-distillery might take a moment as the Tokenizer Model will be downloaded and saved to this package's cache directory.