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-aiThe 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.
| Prop | Type | Description |
|---|---|---|
modelUrl | string | Base URL for model artifacts from the bot integration details |
systemPrompt | string? | Custom system prompt for the bot |
modelLib | string? | WASM library URL for the trained model. Copy it from the bot integration details; when omitted it is resolved from modelSize |
modelSize | string? | Model identity that selects a fallback WASM library, for example "small", "medium", or "large" (default: "small") |
temperature | number? | Sampling temperature (default: 0.7) |
repetitionPenalty | number? | Penalty applied to repeated tokens (default: 1.1) |
ragCorpusUrl | string? | 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.
| Prop | Type | Description |
|---|---|---|
botName | string? | Display name (default: "AI Assistant") |
welcomeMessage | string? | Message shown in empty chat state |
suggestions | string[]? | 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.
| Attribute | Maps to | Value |
|---|---|---|
model-url | modelUrl | Model artifact URL |
model-lib | modelLib | WASM library URL override |
model-size | modelSize | Model size, for example "small" |
system-prompt | systemPrompt | System prompt |
temperature | temperature | Number from 0 to 2 |
top-p | topP | Top-p sampling threshold |
repetition-penalty | repetitionPenalty | Penalty on repeated tokens, default 1.1 |
rag-corpus-url | ragCorpusUrl | 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. |
thinking | enableThinking | Use "false" to disable; any other present value enables thinking |
enable-thinking | enableThinking | Presence enables thinking when the thinking attribute is absent |
max-tokens | maxTokens | Maximum generated tokens |
max-history-messages | maxHistoryMessages | Maximum non-system history messages |
stream-update-interval-ms | streamUpdateIntervalMs | Minimum visible stream update interval in milliseconds |
cache-backend | cacheBackend | Either "cache" or "indexeddb" |
worker-url | workerUrl | Dedicated WebLLM worker URL |
context-window-size | contextWindowSize | Context window override |
min-ram-gb | minRamGb | Deprecated compatibility attribute |
bot-name | botName | Widget display name |
welcome-message | welcomeMessage | Empty-state message |
suggestions | suggestions | JSON-encoded string array, for example ["Pricing", "Support"] |
primary-color | theme.primaryColor | Hex brand color |
position | theme.position | Either "bottom-right" or "bottom-left" |
rag-prompt-template | ragPromptTemplate | RAG 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.
- 01The SDK checks the browser's local runtime.
- 02Model files are fetched and cached on the device.
- 03The model is prepared for the available local runtime.
- 04The chat becomes available after the model is ready.
Requirement
