Skip to content

cristianglezm/vue-chatbot-widget

Repository files navigation

vue ChatBot Widget

cd pkg NPM Version GitHub package.json version (branch)

The ChatBotWidget is designed to enhance your web application. It empowers users to specify actions, retrieve information from documents using a basic Retrieval-Augmented Generation (RAG) system, and access text-to-audio features for an improved and inclusive user experience.

⚠️ Important

Warning: The default chatbot model has not yet been trained for production use. Some features may be limited or not function as expected. For best results, consider using a custom model or adapting the configuration to meet your needs.

Features

  1. Agent Capabilities Leverages agent functionality to interpret and perform user-specified actions effectively.
  2. Simple RAG (Retrieval-Augmented Generation) System Integrates a basic RAG system, allowing the chatbot to consult external documents to enhance responses.
  3. Local / Remote it lets you use a local or remote server compatible with OpenAI API.
  4. Text-to-Audio Conversion Generates audio for text responses, providing an accessible and interactive user experience. Includes options for manual playback or automatic audio generation after responses.

Installation

You can install the package from npm.

npm i @cristianglezm/vue-chatbot-widget

If you plan to use all the components you will need to initizalize the pinia store and add ChatBotPlugin into the app.

// app main.ts
import { createApp } from 'vue'
import { createPinia } from 'pinia';
// import the plugin
import ChatBotPlugin from '@cristianglezm/vue-chatbot-widget';
import './style.css'

import App from './App.vue'

const app = createApp(App);
const pinia = createPinia();
// registers the pinia store
app.use(pinia);
// and the ChatBot components
app.use(ChatBotPlugin, { pinia });
app.mount('#app')

If you plan to only use a component you can just call initStores({ pinia }) instead.

// app main.ts
import { createApp } from 'vue'
import { createPinia } from 'pinia';
import { initStores } from '@cristianglezm/vue-chatbot-widget';
import './style.css'

import App from './App.vue'

const app = createApp(App);
const pinia = createPinia();
// registers the pinia store
app.use(pinia);
// init stores for the chatbot components.
initStores({ pinia });
app.mount('#app')

Usage

  1. Using System Only

This method configures the chatbot with a system message.

<script setup>
import { onMounted } from 'vue';
import { ChatBotWidget } from '@cristianglezm/vue-chatbot-widget';
import mitt from 'mitt';
// emitter to be able to load models from outside the chatbot.
const emitter = mitt();
// onMounted(() => {
//    emitter.emit('ChatBotWidget#loadChatBotModel'); // load the llm
//    emitter.emit('ChatBotWidget#loadKokoroModel'); // load the tts
// });
// no need to pass emitter if not needed.
</script>
<template>
  <ChatBotWidget
    :emitter="emitter"
    :system="'You are a helpful assistant to assist the user.'"
    :greetings="'Hello! How can I assist you today?'"
  />
</template>
  1. Using Chat Template Only

If you want to use a custom chat template (from @huggingface/jinja), specify it using the :chat-template prop.

When tools and documents are provided, they will be injected into the chat template, to be able to use tools you will need to provide your own executor function. the chat template should have a tools|tojson and a for doc in documents, review the chat_template in main.ts

<script setup>
import { ChatBotWidget, chat_template } from '@cristianglezm/vue-chatbot-widget';

const tools = [
    {
        "name": "makeFlower",
        "description": "Makes a flower",
        "parameters": {}
    },
    {
        "name": "mutate",
        "description": "Mutates a flower given the ID",
        "parameters": {
            "id": {
                "description": "Flower ID",
                "type": "int",
                "required": true
            }
        }
    }
];
const documents = [
    {
        "title":"title to use as embeddings and key to get the content with a tool",
        "content":"information for the user"
    },
];
</script>
<template>
  <ChatBotWidget
    :greetings="'Hello! How can I assist you today?'"
    :chat-template="chat_template"
    :tools="tools"
    :documents="documents"
    :executor="parseAndExecCommand"
  />
</template>

Props

Prop Type Description
emitter Object Mitt event bus to be able to load the model from outside the ChatBotWidget.
system String Predefined system message for chatbot behavior.
greetings String Initial message displayed to the user.
chat-template String Custom @huggingface/jinja template for chatbot interaction.
tools Array Array of tools available for chatbot execution.
documents Array Array of documents injected into the chat template.
executor Function Function responsible for parsing and executing commands.
editable Boolean Enables or disables the editable mode.
config Object Custom configuration object for additional settings.
emitter.emit('ChatBotWidget#loadChatBotModel'); // load the llm
emitter.emit('ChatBotWidget#loadKokoroModel'); // load the tts

refer to src/component/chatbotwidget.vue

Constributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

This library is distributed under the Apache 2.0. See License for more information.

The Monaspace font is distributed under the STL Open Font License. See License for more information.

About

A simple vue chatbot with tts

Topics

Resources

License

Apache-2.0, OFL-1.1 licenses found

Licenses found

Apache-2.0
LICENSE.md
OFL-1.1
LICENSE-monaspace-font.md

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 2

  •  
  •