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

tiptap-bubble-ai-react

v1.1.4

Published

A React component for AI-powered text editing in TipTap using bubble menu.

Downloads

29

Readme

BubbleAI

BubbleAI is a powerful and flexible AI-powered text editing tool that can be easily integrated into your React applications. It supports multiple AI providers and allows for custom prompts to enhance your text editing experience.

Installation

npm i tiptap-bubble-ai-react

Usage

JavaScript

import { useState } from "react";
import StarterKit from "@tiptap/starter-kit";
import { BubbleMenu, EditorContent, useEditor } from "@tiptap/react";
import { BubbleAI } from "tiptap-bubble-ai-react";
import "tiptap-bubble-ai-react/dist/index.css";

const MyEditor = () => {
  const [content, setContent] = useState(
    `<p>Artificial Intelligence (AI) is transforming industries at a rapid pace. From healthcare to finance, AI is being used to automate processes and improve efficiency. One of the key areas where AI is making an impact is in data analysis.</p>`);

  const editor = useEditor({
    extensions: [StarterKit],
    content: content,
    onUpdate: ({ editor }: { editor: Editor }) => {
      setContent(editor.getHTML());
    },
  });

  const configuration = {
    OpenAI: {
      OpenAI_api_key: "your-openai-api-key",
      Model: "gpt-4o-mini",
    },
    Gemini: {
      Gemini_api_key: "your-gemini-api-key",
      Model: "gemini-1.5-flash",
    },
    prompts: {
      usePredefined: true,
      userPrompts: null
    },
  };

  return (
    <>
        <EditorContent editor={editor} />
        <BubbleMenu editor={editor}>
            <BubbleAI editor={editor} configuration={configuration} />
        </BubbleMenu>
    </>
  );
};

export default MyEditor;

TypeScript

import { useState } from "react";
import StarterKit from "@tiptap/starter-kit";
import { BubbleMenu, EditorContent, useEditor } from "@tiptap/react";
import { BubbleAI, BubbleAIConfiguration } from "tiptap-bubble-ai-react";
import "tiptap-bubble-ai-react/dist/index.css";

const MyEditor = () => {
  const [content, setContent] = useState<string>(
    `<p>Artificial Intelligence (AI) is transforming industries at a rapid pace. From healthcare to finance, AI is being used to automate processes and improve efficiency. One of the key areas where AI is making an impact is in data analysis.</p>`);

  const editor = useEditor({
    extensions: [StarterKit],
    content: content,
    onUpdate: ({ editor }: { editor: Editor }) => {
      setContent(editor.getHTML());
    },
  });

  const configuration: BubbleAIConfiguration = {
    OpenAI: {
      OpenAI_api_key: "your-openai-api-key",
      Model: "gpt-4o-mini",
    },
    Gemini: {
      Gemini_api_key: "your-gemini-api-key",
      Model: "gemini-1.5-flash",
    },
    prompts: {
      usePredefined: true,
      userPrompts: null,
    },
  };

  return (
    <>
        <EditorContent editor={editor} />
        <BubbleMenu editor={editor}>
            <BubbleAI editor={editor} configuration={configuration} />
        </BubbleMenu>
    </>
  );
};

export default MyEditor;

Configuration

The BubbleAIConfiguration object allows you to customize behavior of BubbleAI. Here's a breakdown of its properties:

interface BubbleAIConfiguration {
  OpenAI?: {
    OpenAI_api_key: string;
    Model: string;
  };
  Gemini?: {
    Gemini_api_key: string;
    Model: string;
  };
  prompts: {
    usePredefined: boolean;
    userPrompts: Prompt[] | null;
  };
}

interface Prompt {
  text: string;
  prompt: string;
  options?: string[];
}
  • OpenAI (optional): Configuration for OpenAI integration.

    • OpenAI_api_key: Your OpenAI API key.
    • Model: The OpenAI model to use (e.g., 'gpt-4o-mini').
  • Gemini (optional): Configuration for Gemini integration.

    • Gemini_api_key: Your Gemini API key.
    • Model: The Gemini model to use (e.g., 'gemini-1.5-flash').
  • prompts: Configuration for AI prompts.

    • usePredefined: Set to true to use predefined prompts, false to use custom prompts.
    • userPrompts: An array of custom prompts (only used when usePredefined is false). An Example of it can be seen below for reference.
    prompts: {
      usePredefined: false,
      userPrompts:  [
            {
                text: "Improve Writing",
                prompt:
                    "Refine and enhance the clarity, structure, and flow of the following text:",
            },
            {
                text: "Fix Grammar and Spelling",
                prompt:
                    "Identify and correct grammatical errors, punctuation issues, and spelling mistakes in the following text:",
            },
            {
                text: "Change Tone To",
                prompt: "Modify the tone of the following text to [desired tone]:",
                options: ["Professional", "Straightforward", "Friendly"],
            },
        ],
    },

Components

BubbleMenu

The BubbleMenu component is a container for the BubbleAI functionality. It should wrap the BubbleAI component.

Props:

  • editor: The editor instance (required)

BubbleAI

The BubbleAI component provides the AI-powered text editing functionality.

Props:

  • editor: The editor instance (required)
  • configuration: The BubbleAIConfiguration object (required)

Troubleshooting

When using BubbleAI with Vite, you may encounter certain errors related to missing Node.js polyfills. This is because Vite, doesn't include some Node.js core modules by default.

Common Errors

  1. Uncaught TypeError: util.inherits is not a function
  2. Uncaught ReferenceError: process is not defined

Solution: Using vite-plugin-node-polyfills

To resolve these issues, you can use the vite-plugin-node-polyfills package. This plugin adds the necessary polyfills for Node.js core modules in your Vite project.

  1. Install the plugin:

    npm install vite-plugin-node-polyfills --save-dev
  2. Update your vite.config.ts (or vite.config.js) file:

    import { defineConfig } from 'vite'
    import react from '@vitejs/plugin-react'
    import { nodePolyfills } from 'vite-plugin-node-polyfills'
    
    export default defineConfig({
      plugins: [
        react(),
        nodePolyfills(),
      ],
    })

Note

BubbleAI provides a powerful way to enhance your text editing experience with AI capabilities. By following this documentation, you should be able to integrate BubbleAI into your React applications.