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

hf-tgi-api-helper

v1.0.5

Published

A lightweight utility library providing built-in functions to easily interact with HuggingFace Text Generation Inference (TGI) APIs, enabling seamless text generation and model inference.

Downloads

12

Readme

hf-tgi-api-helper

npm version npm downloads license

A simple npm package to interact with Hugging Face's Text Generation Inference (TGI) model. It provides easy-to-use functions for generating, summarizing, and rephrasing text using the TGI model API.

Features

  • Generate Text: Interact with the TGI model to generate text based on a prompt.
  • Summarize Emails: Provide a summary of email content.
  • Rephrase Emails: Rephrase email content for professionalism and conciseness.

Installation

Install the package via npm:

npm install hf-tgi-api-helper

Usage

1. Generate Text

You can use the generateText function to send a prompt and system prompt to the TGI model and receive generated text.

const { generateText } = require('hf-tgi-api-helper');

(async () => {
  const result = await generateText('Translate this text to French:', 'Bonjour, comment allez-vous?');
  console.log(result); // "Hello, how are you?"
})();

2. Summarize an Email

You can summarize email content using the summarizeEmail function. The system prompt defaults to "Summarize the following email:" but can be customized.

const { summarizeEmail } = require('hf-tgi-api-helper');

(async () => {
  const summary = await summarizeEmail('Dear John, I hope this email finds you well...');
  console.log(summary); // "Summary of the email content..."
})();

3. Rephrase an Email

Use the rephraseEmail function to rephrase email content for conciseness and professionalism. The system prompt defaults to "Rephrase the following email to be more concise and professional:" but can be customized.

const { rephraseEmail } = require('hf-tgi-api-helper');

(async () => {
  const rephrased = await rephraseEmail('Dear Sir, I am writing to inquire...');
  console.log(rephrased); // "Dear Sir, I would like to inquire..."
})();

API Reference

generateText(prompt, systemPrompt, config, url)

  • Description: Interact with the TGI model to generate text.
  • Parameters:
    • prompt (string): The main user input.
    • systemPrompt (string): A predefined system prompt (e.g., "Translate this text to French:").
    • config (object, optional): Configuration options for the TGI model, including:
      • max_new_tokens (number, default: 50): Maximum number of tokens to generate.
      • temperature (number, default: 0.7): Controls randomness in generation (higher = more random).
    • url (string, optional): URL of the TGI server. Defaults to the TGI_SERVER_URL environment variable.
  • Returns: Promise<string> — The generated text.

summarizeEmail(emailContent, systemPrompt, config, url)

  • Description: Summarize email content using the TGI model.
  • Parameters:
    • emailContent (string): The content of the email to summarize.
    • systemPrompt (string, optional): Custom system prompt (default: "Summarize the following email:").
    • config (object, optional): Configuration options (same as generateText).
    • url (string, optional): URL of the TGI server. Defaults to the TGI_SERVER_URL environment variable.
  • Returns: Promise<string> — The summarized email.

rephraseEmail(emailContent, systemPrompt, config, url)

  • Description: Rephrase email content for conciseness and professionalism using the TGI model.
  • Parameters:
    • emailContent (string): The content of the email to rephrase.
    • systemPrompt (string, optional): Custom system prompt (default: "Rephrase the following email to be more concise and professional:").
    • config (object, optional): Configuration options (same as generateText).
    • url (string, optional): URL of the TGI server. Defaults to the TGI_SERVER_URL environment variable.
  • Returns: Promise<string> — The rephrased email.

Environment Variables

  • TGI_SERVER_URL: The URL of the TGI model server. This can be overridden by passing a custom URL to the functions.