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
Maintainers
Readme
hf-tgi-api-helper
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 theTGI_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 asgenerateText
).url
(string
, optional): URL of the TGI server. Defaults to theTGI_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 asgenerateText
).url
(string
, optional): URL of the TGI server. Defaults to theTGI_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.