Easy-to-integrate JavaScript widget for AI conversations
The Conversation Widget is a self-contained JavaScript plugin that provides a complete AI chat interface. It can be easily integrated into any website with just a few lines of code.
Add the widget script to your HTML page:
<script src="conversation-widget.js"></script> <div id="my-chat-widget"></div>
Initialize the widget with your configuration:
See the widget in action with different themes:
{
apiUrl: 'https://your-domain.com/api/v1/llm', // Your API endpoint (normalized LLM API)
apiKey: 'your-api-key', // Your API key
containerId: 'widget-container' // HTML element ID
}
{
// API Configuration
apiUrl: 'https://your-domain.com/api/v1/llm', // Normalized LLM API endpoint
apiKey: 'your-api-key',
defaultModel: 'openai/gpt-3.5-turbo',
temperature: 0.7,
maxTokens: 1000,
systemPrompt: 'You are a helpful assistant.',
// UI Configuration
containerId: 'widget-container',
theme: 'dark', // 'dark' or 'light'
showSettings: true,
maxHeight: '500px',
// Behavior Configuration
maxHistoryLength: 20,
autoResize: true,
showTokenCount: true,
// Callbacks
onLoad: (widget) => { /* widget loaded */ },
onMessage: (message, role) => { /* new message */ },
onError: (error) => { /* error occurred */ }
}
// Initialize widget
const widget = new ConversationWidget({
apiUrl: 'https://your-api.com/api/v1/llm', // Normalized LLM API endpoint
apiKey: 'your-api-key',
containerId: 'chat-widget'
});
// Programmatic control
widget.setSystemPrompt('You are a coding assistant.');
widget.setModel('openai/gpt-4');
widget.addMessage('user', 'Hello!');
widget.clearConversation();
// Get conversation history
const history = widget.getConversationHistory();
import { useEffect, useRef } from 'react';
function ChatWidget() {
const containerRef = useRef(null);
useEffect(() => {
if (containerRef.current) {
new ConversationWidget({
containerId: containerRef.current.id,
theme: 'light',
onMessage: (message, role) => {
// Handle messages in React
}
});
}
}, []);
return <div id="chat-widget" ref={containerRef}></div>;
}
<template>
<div id="chat-widget"></div>
</template>
<script>
export default {
mounted() {
new ConversationWidget({
containerId: 'chat-widget',
theme: 'light'
});
}
}
</script>
// Dark theme (default) theme: 'dark' // Light theme theme: 'light'
You can override the widget's default styles with custom CSS:
/* Custom styling for the widget */
.conversation-widget {
border-radius: 15px !important;
box-shadow: 0 4px 20px rgba(0,0,0,0.3) !important;
}
.widget-header h3 {
color: #your-color !important;
}
The widget uses API key authentication. Make sure your domain is registered in the Jobsolve portal.
If you get a 401 error, your domain needs to be registered in the Jobsolve portal to enable chat functionality.
The widget communicates with the normalized LLM API endpoint:
POST /api/v1/llm/respond
Headers:
Content-Type: application/json
x-api-key: your-api-key
Body:
{
"messages": [...],
"model": "openai/gpt-3.5-turbo",
"temperature": 0.7,
"max_tokens": 1000,
"stream": false
}
Response:
{
"provider": "openrouter",
"model": "openai/gpt-3.5-turbo",
"finish_reason": "stop",
"usage": {
"prompt_tokens": 123,
"completion_tokens": 45,
"total_tokens": 168
},
"message": {
"role": "assistant",
"content": "Response text here..."
}
}
Here's a complete HTML page example:
My Website with AI Chat
Welcome to My Website
This is my website content...
Problem: "This domain is not authorized for chat usage"
Solution: Register your domain in the Jobsolve portal
Problem: Widget doesn't appear on the page
Solution: Check that the container ID exists and the script is loaded
Problem: "Failed to fetch" errors
Solution: Verify your API URL and key are correct
For additional help or questions about the Conversation Widget: