0.0.39 • Published 2 months ago

@ai-on/ui v0.0.39

Weekly downloads
-
License
GLP-3.0
Repository
github
Last release
2 months ago

AI-ON UI

Official Documentation

Documentation

A ChatGPT-like (Multi) Chatbot Snippet

This npm module allows you to add a chatGPT-like chatbot UI widget to your website or application. Built with Solid.js, this widget provides a seamless way to interact with multiple chatbots at once. Users can easily create integrations through simple props.

Build with JSX, Integrate with any framework

Built on top of solid.js and web components, this widget can be integrated with any framework, and yet it leverages the power of JSX to provide a seamless developer experience.

Demo (various themes)

Lofi Dark Light Cupcake Emerald Synthwave Bumblebee Autumn

... and many others you can use from DaisyUI. Just add ?aion_theme=THEME_NAME query parameter to the url.

LT;DR

Minimal implementation Using OpenAI Provider.

<html>
    <script type="module">

    import renderer, { Providers } from 'https://cdn.jsdelivr.net/npm/@ai-on/ui';
        
        if (!renderer) {
            console.error("renderer not found");
        }

        const initialProps = {
            ...Providers['OpenAiProvider']({
                apiKey: 'your-open-ai-key-here',
                maxLength: 12000,
                model: 'gpt-3.5-turbo',
                stream: true
            }),
            allowConversations: true, // Allow users to create and delete new threads
            bots: [{
                name: 'ChatGpt',
                description: 'ChatGpt',
                instructions: 'Your are a helpful assistant', // Instructions to be passed as "system prompt",
                suggestions: ['What is the meaning of life?', 'What is the best programming language?', 'What is the best programming language?'],
                introMessage: 'Hello, my name is ChatGpt. How can I help you today?'
            }],
            conversations: []
        }

        renderer(initialProps)

    </script>
    <body>
    <div id="aion-ui" width="100%" height="100%" ></div>
    </body>
</html>

Please, note that it is not recommended to use this provider in production as your api key would be visible. For production, we recommend using other Providers, or implementing your own that comunicates with your backend.

Features

  • Multi-Chatbot: :robot: :robot: Easily integrate multiple chatbots into your UI, but you can also use it with a single chatbot
  • Out-of-the-box Themes: :paintbrush: Choose from a variety of built-in themes from DaisyUI or create your own by cutomizing this widget
  • Responsive: :iphone: This widget is responsive and mobile-friendly.
  • Customizable: :wrench: Customize the look and feel of the chatbot widget with a familiar toolkit for modern web developers: Tailwind CSS and JSX
  • Small Bundle: :ant: The entire codebase is ~250kb, and ~50kb gzipped. This means that your users will have a fast experience, even on slow connections.
  • Easy to use: :sparkles: Simply add the widget to your project and pass in the props. You don't have to worry about managing the state, or even leaking css to the rest of your application. It's all encapsulated in the widget.
  • Built with Solid.js: :computer: Built with Solid.js, this widget can be integrated with any framework. Plus, you get JSX with no version conflicts with other frameworks.
  • Bateries Included: :link: This widget comes with OpenAI Integration provider. If you want to enhance your chatbot capabilities even further with user management, automatic memory management and interacting with your custom knowledge base, AION Provider is also included. You can also easily integrate your own chatbot provider. More built-in providers coming soon.
  • Open Source: :octocat: Under GNU GPL v3.0 license, this widget is open source and free to use. You can also contribute to the project by submitting a pull request.

Installation

NPM

npm install @ai-on/ui

Yarn

yarn add @ai-on/ui

CDN

<script src="https://cdn.jsdelivr.net/npm/@ai-on/ui" type="module"></script>

Usage

If you imported the module using NPM or Yarn, you can import the module like so:

import renderer , { Providers } from '@ai-on/ui';
// {... rest of your code here ...}

If you imported the module using CDN, you can import the module like so, in your <script>tag:

<script src="https://cdn.jsdelivr.net/npm/@ai-on/ui"  type="module"> // Import the module here if you are using CDN
    import renderer, { Providers } from '@ai-on/ui'; // note that it is a ESM (ES Module), so you can to import it inside the script tag
    // {... rest of your code here ...}
</script>

Then, you can pass in the props to the widget like so:

const initialProps = {
    onSendMessage: async ({ message, conversation }, stream) => {
        // Implement your logic when user sends a message here  || or use an existing provider
    },
    onCreateConversation: ({conversation}) => { 
        // Implement your logic for when user creates a new conversation here || or use an existing provider
    },
    onDeleteConversation: ({convvesation}) => { 
        // Implement your logic for when user deletes a conversation here || or use an existing provider
    },
     onInit: ({setSelectedConversation, setConversations, setBots, setShowConversations, setShowDetails, setShowRegenerate}) => { 
        // Implement your logic for when the widget is initialized here. You can use the setters to update the state of the widget upon initialization || or use an existing provider
    },
    placeholder: "Type your message here...",
    regenerateLimitText: "It looks like I were unable to answer you message. Please try again with a different question.",
    botTypingCaption: "Typing...",
    allowConversations: true,
    hideHeader: false,
    bots: [ // List your available chatbots here
        {
            name: "Bot 1",
            description: "Bot 1 description",
            id: 1,
            introMessage: "Hello, my name is bot 1. How can I help you today?",
            suggestions: ["What's franch for 'bread'?", 'How are you doing? (answer as joey from friends)', 'What is the meaning of life?']
        },
        {
            name: "Bot 2",
            description: "Bot 2 description",
            id: 2,
            introMessage: "Hello, my name is bot 2. How can I help you today?",
            suggestions: ["What's english for 'pão'?", 'How are you doing? (answer as chewbaca from star wars)', 'Why does the universe exists?']
        }
    ],
    conversations: [ // List your conversations here
        {
            title: "Thread 1",
            description: "Description from thread 1",
            id: 1,
            messages: messages,
            bot: bots[0],
            updatedAt: new Date("2023-06-20")
        },
        {
            title: "Thread 2",
            description: "Descrição longa da conversa 2, adicionando mais contexto e informações",
            id: 2,
            messages: messages,
            bot: bots[1],
            updatedAt: new Date("2023-06-20")
        },
    ]
};

renderer(initialProps);

And, finally, you can render the widget like so in your html file:

<body>
    <!-- ... Rest of your html code here ... -->
    <!-- This is where the widget will be rendered. Please, note that the it's id should be 'aion-ui' -->
    <div id="aion-ui" width="100%" height="100%" ></div> 
</body>

Props

PropTypeDescriptionRequiredDefaultExample
onSendMessageFunctionCallback function that is called when the user sends a message.YesN/Aasync ({ message, conversation }, stream) => { // Implement your logic when user sends a message here }
onCreateConversationFunctionCallback function that is called when the user creates a new conversation.YesN/Aasync () => { // Implement your logic for when user creates a new conversation here }
onDeleteConversationFunctionCallback function that is called when the user deletes a conversation.YesN/Aasync () => { // Implement your logic for when user deletes a conversation here }
placeholderStringPlaceholder text for the input field.No"Type your message here...""Type your message here..."
regenerateLimitTextStringText that is shown when the user reaches the limit of message regenerations.No"It looks like I were unable to answer you message. Please try again with a different question.""It looks like I were unable to answer you message. Please try again with a different question."
botTypingCaptionStringText that is shown when the bot is typing.No"Typing...""Typing..."
allowConversationsBooleanWhether or not the user can create and delete conversations.Notruetrue
botsArrayList of bots that are available to the user.YesN/A[ bot ]
bot.nameStringName of the bot.YesN/A"Bot 1"
bot.descriptionStringDescription of the bot.YesN/A"Bot 1 description"
bot.idNumberId of the bot.YesN/A1
bot.introMessageStringIntro message of the bot.YesN/A"Hello, my name is bot 1. How can I help you today?"
bot.suggestionsArrayList of suggestions that are shown to the user when the bot is typing.YesN/A["What's franch for 'bread'?", 'How are you doing? (answer as joey from friends)', 'What is the meaning of life?']
conversationsArrayList of conversations that are available to the user.YesN/A[ conversation ]
conversation.titleStringTitle of the conversation.YesN/A"Thread 1"
conversation.descriptionStringDescription of the conversation.YesN/A"Description from thread 1"
conversation.idNumberId of the conversation.YesN/A1
conversation.botObjectBot that is associated with the conversation.YesN/Abot
conversation.updatedAtDateDate of the last message in the conversation.YesN/AupdatedAt: new Date("2023-06-20")
conversation.messagesArrayList of messages that are available in the conversation.YesN/A[ message ]
message.idNumberId of the message.YesN/A1
message.textStringText of the message.YesN/A"Hello, my name is bot 1. How can I help you today?"
message.createdAtDateDate of the message.YesN/Anew Date("2023-06-20")
message.authorStringAuthor of the message.YesN/AEnum: ["user", "chatbot"]

License

GNU GPLv3 ©

Author

Made with ❤️ by AI-ON Team 👋🏽 Get in touch!

0.0.37

2 months ago

0.0.38

2 months ago

0.0.39

2 months ago

0.0.31

2 months ago

0.0.32

2 months ago

0.0.33

2 months ago

0.0.34

2 months ago

0.0.35

2 months ago

0.0.36

2 months ago

0.0.30

2 months ago

0.0.29

9 months ago

0.0.28

9 months ago

0.0.27

9 months ago

0.0.26

9 months ago

0.0.25

10 months ago

0.0.24

10 months ago

0.0.23

10 months ago

0.0.22

10 months ago

0.0.21

10 months ago

0.0.20

10 months ago

0.0.19

10 months ago

0.0.18

10 months ago

0.0.17

10 months ago

0.0.16

10 months ago

0.0.15

10 months ago

0.0.14

10 months ago

0.0.13

10 months ago

0.0.12

10 months ago

0.0.11

10 months ago

0.0.10

10 months ago

0.0.9

10 months ago

0.0.8

10 months ago

0.0.7

10 months ago

0.0.6

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago