step 04

SDK integration

Embed your trained bot on any website. Pick the integration option that fits your stack.

01

Get your integration details

Go to your bot in Dashboard → Bots. Once your bot is trained and active, the dashboard provides one install snippet for its selected active model. The snippet contains a concrete model URL and the matching Small, Medium, or Large size. Other active models have Playground links for testing.

The current SDK loads exactly the modelUrl and modelSize configured in the integration. It does not select a size based on device RAM or automatically switch models. If you train multiple sizes, you can test them in the Playground, but public installation currently follows the single generated snippet.

The unreleased SDK source supports built-in presets for modelSize "minicpm5-1b" and "minicpm5-2b", which load shared grounded checkpoints with no modelUrl or modelLib. Your own trained bot should always use the modelUrl and modelLib from its integration details.

02

Option 1: script tag

The simplest integration. Add a single script tag to your HTML. No build tools, no framework dependencies.

index.html

<script type="module">
  import { mount } from 'https://cdn.jsdelivr.net/npm/kanha-ai@0.1.10/dist/widget.js';

  mount('#chat', {
    modelUrl: 'YOUR_MODEL_URL',  // from the bot integration details
    modelSize: 'small',          // matches the trained model size
    systemPrompt: 'You are a helpful assistant for...',
    botName: 'My Bot'
  });
</script>

Or use the Web Component when you want a setup with no custom JavaScript.

index.html: web component

<script type="module" src="https://cdn.jsdelivr.net/npm/kanha-ai@0.1.10/dist/widget.js"></script>

<kanha-bot
  model-url="YOUR_MODEL_URL"
  model-size="small"
  system-prompt="You are a helpful assistant for..."
  bot-name="My Bot"
  welcome-message="Ask me anything"
  suggestions='["Pricing", "Support"]'
  primary-color="#0d9488"
  position="bottom-right"
></kanha-bot>

The CDN URL is pinned to version 0.1.10. Browsers cache the unversioned file aggressively, so an unpinned URL can keep serving an old widget build long after a fix ships. Copy the snippet again after each SDK release to move up.

03

Option 2: npm and React

For React apps, install the SDK via npm for full TypeScript support and tree-shaking.

terminal

npm install kanha-ai

The drop-in widget renders a floating chat button and panel.

App.tsx: drop-in widget

import { KanhaBot } from 'kanha-ai';

function App() {
  return (
    <KanhaBot
      modelUrl="YOUR_MODEL_URL"
      modelSize="small"
      systemPrompt="You are a helpful assistant for..."
      botName="My Bot"
    />
  );
}

The headless hook lets you build your own UI.

CustomChat.tsx: headless hook

import { useKanhaChat } from 'kanha-ai';

function CustomChat() {
  const { messages, setInput, send, isLoading, mode } = useKanhaChat({
    modelUrl: 'YOUR_MODEL_URL',
    modelSize: 'small',
    systemPrompt: 'You are a helpful assistant...'
  });

  // Build your own chat UI using messages, send(), etc.
}

04

Configuration

Shared runtime options

The mount function, React widget, and useKanhaChat hook accept these camelCase runtime options. Web Component mappings are listed separately below.

PropTypeDescription
modelUrlstringBase URL for model artifacts from the bot integration details
systemPromptstring?Custom system prompt for the bot
modelLibstring?WASM library URL for the trained model. Copy it from the bot integration details; when omitted it is resolved from modelSize
modelSizestring?Model identity that selects a fallback WASM library, for example "small", "medium", or "large" (default: "small")
temperaturenumber?Sampling temperature (default: 0.7)
repetitionPenaltynumber?Penalty applied to repeated tokens (default: 1.1)
ragCorpusUrlstring?Grounds answers in your site content and shows source links. Questions your pages do not cover get a plain not-covered reply, and figures your pages do not contain are withheld. Copied from your bot's integration details.

Widget UI props for mount and React

The mount function and KanhaBot accept these UI props in addition to the runtime options. The headless useKanhaChat hook does not render a widget and does not use them.

PropTypeDescription
botNamestring?Display name (default: "AI Assistant")
welcomeMessagestring?Message shown in empty chat state
suggestionsstring[]?Starter prompt suggestions
theme{ primaryColor?, position? }Widget color and positioning

Web Component attributes

The <kanha-bot> element reads these HTML attributes. Color and position map to fields inside the JavaScript theme object; there is no theme attribute.

AttributeMaps toValue
model-urlmodelUrlModel artifact URL
model-libmodelLibWASM library URL override
model-sizemodelSizeModel size, for example "small"
system-promptsystemPromptSystem prompt
temperaturetemperatureNumber from 0 to 2
top-ptopPTop-p sampling threshold
repetition-penaltyrepetitionPenaltyPenalty on repeated tokens, default 1.1
rag-corpus-urlragCorpusUrlGrounds answers in your site content and shows source links. Questions your pages do not cover get a plain not-covered reply, and figures your pages do not contain are withheld. Copied from your bot's integration details.
thinkingenableThinkingUse "false" to disable; any other present value enables thinking
enable-thinkingenableThinkingPresence enables thinking when the thinking attribute is absent
max-tokensmaxTokensMaximum generated tokens
max-history-messagesmaxHistoryMessagesMaximum non-system history messages
stream-update-interval-msstreamUpdateIntervalMsMinimum visible stream update interval in milliseconds
cache-backendcacheBackendEither "cache" or "indexeddb"
worker-urlworkerUrlDedicated WebLLM worker URL
context-window-sizecontextWindowSizeContext window override
min-ram-gbminRamGbDeprecated compatibility attribute
bot-namebotNameWidget display name
welcome-messagewelcomeMessageEmpty-state message
suggestionssuggestionsJSON-encoded string array, for example ["Pricing", "Support"]
primary-colortheme.primaryColorHex brand color
positiontheme.positionEither "bottom-right" or "bottom-left"
rag-prompt-templateragPromptTemplateRAG context template

Retrieval callbacks cannot be encoded as HTML attributes. Assign the element’s onRetrieveContext JavaScript property when using a custom retrieval function.

05

How local execution works

The SDK loads the trained model on the visitor’s device. Once ready, questions are answered locally without a per-message inference request.

  1. 01The SDK checks the browser's local runtime.
  2. 02Model files are fetched and cached on the device.
  3. 03The model is prepared for the available local runtime.
  4. 04The chat becomes available after the model is ready.

Requirement

Browsers and devices differ, and model size and available resources affect local execution. If an environment needs additional compatibility work, work with Kanha and we will adapt the runtime or delivery path.