2.0.0 • Published 6 months ago

akool-react-sdk v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Akool SDK

A React component library for integrating AI-powered video chat avatars into your web applications.

Features

  • 🎥 Real-time AI video streaming
  • 💬 Interactive chat interface
  • 🎭 Customizable avatar personalities
  • 🌐 WebSocket-based communication
  • 🔊 Voice synthesis support
  • 🎨 Tailwind-styled components

Installation

npm install akool-react-sdk

Quick Start

import { VideoChatProvider, ChatWidget } from 'akool-react-sdk'
import 'akool-react-sdk/dist/style.css'

const App = () => {
  return (
    <VideoChatProvider openapiToken="your-openapi-token">
      <ChatWidget title="My Avatar" personality="You are a helpful assistant." />
    </VideoChatProvider>
  )
}

Customization

You can customize the avatar's personality and other properties by passing props to the ChatWidget component.

<ChatWidget title="My Avatar" personality="You are a helpful assistant." />

API

Components

VideoChatProvider

The main context provider that handles video streaming and chat functionality.

Props

PropTypeDefaultDescription
openapiTokenstringrequiredYour Akool API token
avatarIdstring'dvp_Tristan_cloth2_1080P'ID of the avatar to use
openapiHoststring'https://openapi.akool.com'API host URL
languagestring'en'Chat language
voiceIdstring'Xb7hH8MSUJpSbSDYk0k2'Voice synthesis ID
voiceUrlstring''Custom voice URL
videoSourcestring | RefObject'akool-remote-video'Video element reference

ChatWidget

A pre-built chat interface component with video display.

Props

PropTypeDefaultDescription
titlestring'Akool Streaming AI'Chat widget title
personalitystring'You are a helpful assistant.'AI personality prompt

Usage Examples

Basic Implementation

import { VideoChatProvider, ChatWidget } from 'akool-react-sdk'

const App = () => {
  return (
    <VideoChatProvider openapiToken="your-openapi-token">
      <ChatWidget title="My Avatar" personality="You are a helpful assistant." />
    </VideoChatProvider>
  )
}

Advanced Usage

Using the useVideoChat Hook

import { useVideoChat } from 'akool-react-sdk'

function CustomChatInterface() {
  const { 
    sendMessage, 
    messages, 
    isVideoAvailable,
    startStreaming,
    closeStreaming 
  } = useVideoChat()

  // Custom implementation
}

Misc

Suppose you want the avatar to speak your formatted response. You can use the sendMessage function to send a message to the avatar.

sendMessage({
  question: 'your query that you gave to your llm(ChatGPT, claude, etc)',
  modeType: 1,
  answer: 'response from your llm',
})

this will send the response to the avatar and it will speak the response.

For using our llm, you can use the sendMessage function to send a message to the avatar.

sendMessage({
  question: 'your query that you gave to your llm(ChatGPT, claude, etc)',
  modeType: 2,
  content: 'your llm prompt',
})

if you are implmenting your custom solution make sure to call the closeStreaming function when the user leaves the chat / when session ends.

General Guidelines

  1. To use the sdk, you need to have a valid openapi token. You can get the token using client id and secret which you can get from Akool Dashboard. Once you have the client id and secret refer to Akool OpenAPI Documentation to get the token. Here is a curl request to get the token:
curl -X POST https://openapi.akool.com/api/v1/auth/token \
-H "Content-Type: application/json" \
-d '{"clientId":"your-client-id","clientSecret":"your-client-secret"}'
  1. To use useChat hook, you must wrap your component with VideoChatProvider and pass the openapiToken to it.

  2. If you are using useChat hook, you must call closeStreaming function when the user leaves the chat / when session ends.

  3. If you are using ChatWidget component and it is not working, please check if you have added the akool-react-sdk/dist/style.css to your project.

Requirements

  • React 16.8.0 or higher
  • React DOM 16.8.0 or higher

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

License

MIT

Support

For support, please visit Akool AI or create an issue in our GitHub repository.

2.0.0

6 months ago

1.5.0

6 months ago

1.4.0

6 months ago

1.3.2

6 months ago

1.3.1

6 months ago

1.3.0

6 months ago

1.2.0

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago