2.0.0 • Published 5 months ago

hf-tgi-api-helper v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

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.
@ai-sdk/openai@codemirror/lang-javascript@codemirror/lang-python@codemirror/state@codemirror/theme-one-dark@codemirror/view@hookform/resolvers@nanostores/react@radix-ui/react-accordion@radix-ui/react-alert-dialog@radix-ui/react-aspect-ratio@radix-ui/react-avatar@radix-ui/react-checkbox@radix-ui/react-collapsible@radix-ui/react-context-menu@radix-ui/react-dialog@radix-ui/react-dropdown-menu@radix-ui/react-hover-card@radix-ui/react-icons@radix-ui/react-label@radix-ui/react-menubar@radix-ui/react-navigation-menu@radix-ui/react-popover@radix-ui/react-progress@radix-ui/react-radio-group@radix-ui/react-scroll-area@radix-ui/react-select@radix-ui/react-separator@radix-ui/react-slider@radix-ui/react-slot@radix-ui/react-switch@radix-ui/react-tabs@radix-ui/react-toast@radix-ui/react-toggle@radix-ui/react-toggle-group@radix-ui/react-tooltip@radix-ui/react-visually-hidden@vercel/analytics@vercel/blob@vercel/postgresaibcrypt-tsclass-variance-authorityclassnamesclsxcmdkcodemirrordate-fnsdiff-match-patchdotenvdrizzle-ormembla-carousel-reactfast-deep-equalframer-motiongeistinput-otplucide-reactnanoidnextnext-authnext-themesorderedmappostgresprosemirror-example-setupprosemirror-inputrulesprosemirror-markdownprosemirror-modelprosemirror-schema-basicprosemirror-schema-listprosemirror-stateprosemirror-viewreactreact-day-pickerreact-domreact-hook-formreact-markdownreact-resizable-panelsrechartsremark-gfmserver-onlysonnerswrtailwind-mergetailwindcss-animateusehooks-tsvaulzod@biomejs/biome@tailwindcss/typography@types/d3-scale@types/node@types/pdf-parse@types/react@types/react-domdrizzle-kiteslinteslint-config-nexteslint-config-prettiereslint-import-resolver-typescripteslint-plugin-tailwindcsspostcsstailwindcsstsxtypescriptvercel
2.0.0

5 months ago

1.0.5

9 months ago

1.0.4

9 months ago