npm package: @optimaxer/web-text
Description: Welcome to the @optimaxer/web-text documentation! This library is a powerful tool designed to bring the benefits of generative AI directly to your web applications. By leveraging a small language model that runs on the end user's device, @optimaxer/web-te
Latest version: 1.3.6

# @optimaxer/web-text

Welcome to the @optimaxer/web-text documentation! This library is a powerful tool designed to bring the benefits of generative AI directly to your web applications. By leveraging a small language model that runs on the end user's device, @optimaxer/web-text allows you to generate high-quality texts with ease. Whether you're looking to create concise summaries, compelling titles, or even entire text sections, this library offers a flexible and efficient solution. Our goal is to simplify the tasks of your employees, reducing their workload and increasing productivity through intelligent text generation.

## Overview

@optimaxer/web-text is a generative AI library that harnesses the power of a small language model to create various types of text content. The library is designed to operate directly within the user's browser, ensuring quick and secure processing without relying on external servers. This makes it an ideal choice for applications where privacy, speed, and ease of integration are crucial.

### Key Features:

- **Text Summarization:** Automatically condense long documents or articles into brief, coherent summaries that capture the essence of the content.
- **Title Generation:** Generate attention-grabbing titles for articles, reports, or other content, tailored to the context and tone of the text.
- **Custom Text Sections:** Users have the freedom to generate their own text sections, enabling creative and context-specific content creation.

By integrating @optimaxer/web-text into your applications, you can provide users with a powerful tool that simplifies content creation, streamlines workflows, and enhances overall productivity.

> ### ⚠️ Warning
> Due to the restrictions of the Firefox browser, these libraries and functionalities may not work well on Firefox. Please note this limitation.

## Quickstart

### Getting Started with @optimaxer/web-text Library

Getting started with @optimaxer/web-text is straightforward. Follow these steps to integrate the library into your project and start generating text content:

### Step 1: Install the Library

```bash
npm install @optimaxer/web-text
```

This command will add the library to your project's dependencies.

## Step 2: Setting Up the Text Generator

Once the library is installed, you need to set up the Text Generator component. This step involves initializing the Text Generator with the appropriate configurations, including the Small Language Model.

### 1. Import the Text Generator component:

```javascript
import { TextGenerator } from '@optimaxer/web-text';
```

## Step 2: Setting Up the Text Generator

You need to specify the model and engine for the form. For example, if you are using `gemma` as your model and `mediapipe` as your embedding engine, you can set it up like this:

```javascript
const textGenerator = await textGenerator.setup({
  model: 'gemma',
  inferenceEngine: 'mediapipe',
  mode: 'local'
});
```
## Info

When using the setup function, it's important to select compatible model names and inference engines.

### If you choose `webllm` as the inference engine:
- The available models are: `phi`, `gemma`, `gemma2`

### If you choose `mediapipe` as the inference engine:
- The available models are: `gemma`, `gemma-cpu`, `gemma-gpu`

Make sure to select the appropriate combination of model and engine to ensure that the setup function executes successfully.

## Step 3: Generating Text

Now that everything is set up, you can start generating text. Here's how:

### Generate a Summary

To generate a concise summary of a long text, use the `generateSummary` method. The second parameter specifies the desired length of the summary:

```javascript
const summary = await textGenerator.value.generateSummary('Your long text here', 50);
```

### Parameters:

- **Input Text (string):** The main text that you want to summarize. This parameter is required and should contain the content that needs to be condensed.
- **Number of Words (number, optional):** This optional parameter allows you to specify the desired length of the summary in terms of the number of words. If not provided, the function will generate a summary based on the default settings, balancing conciseness and content coverage.

This command will return a summary that captures the key points of the provided text, making it easier for users to digest large amounts of information quickly.

## Generate a Title

Creating an attention-grabbing title is just as easy. The `generateTitle` method can be used to generate a title based on the given text content:

```javascript
const title = await textGenerator.value.generateTitle('Your text here');
```

### Parameters:

- **Input Text (string):** This parameter is required and decided on which the title is created.

This function is particularly useful for content management systems, blog post generators, or any application where creating compelling titles is essential.

## Generate a Custom Text Section

If you need to create a more personalized or context-specific section of text, you can use the `generateText` method:

```javascript
const customText = textGenerator.generateText('Your text here', 'Your custom text type');
```

### Parameters:

- **Input Text (string):** The text that serves as the basis for the generated content. This is the core content from which the custom text will be derived.
- **Custom Text Type (string):** This parameter specifies the type of custom text you want to generate. It could be an abstract, order note, subtitle, or any other defined category. This ensures that the generated content is contextually relevant to the specific use case.
- **Number of Words (number, optional):** An optional parameter that defines the length of the custom text in terms of the number of words. If not specified, the function will use default settings to create a text section of appropriate length.

> 💡
> When using the `generateText` function, it's important to define the `customTextType` in a clear and easily understandable manner. Using simple and specific terms like "abstract," "order note," or "subtitle" helps the text generator produce content that closely aligns with your intended output. Avoid overly complex or ambiguous text types, as this could lead to less accurate or relevant generated text. Keeping it straightforward ensures the best results for your custom text sections.