- smallest.ai Customer Service Chatbot
smallest.ai Customer Service Chatbot
smallest.ai Customer Service Chatbot
A TypeScript implementation of a Model Context Protocol (MCP) for customer service chatbots using smallest.ai API.
Features
- TypeScript implementation with strong typing
- Built with Bun for fast execution
- Mock API for local development without needing API credentials
- Context management for maintaining conversation state
- Support for multiple languages and communication styles
- Error handling and graceful fallbacks
Getting Started
Prerequisites
- Bun installed on your system
Installation
- Clone this repository or create a new project:
mkdir smallestai-mcp
cd smallestai-mcp
- Initialize the project:
bun init -y
- Create the project structure:
mkdir -p src/types src/config src/services src/utils
-
Copy the files from the provided implementation into the corresponding directories.
-
Install dependencies:
bun add -d typescript @types/node
Running the Project
To run the project in development mode with the mock API:
bun start
Project Structure
smallestai-mcp/
├── src/
│ ├── types/
│ │ └── index.ts # Type definitions
│ ├── config/
│ │ └── api.ts # API configuration
│ ├── services/
│ │ ├── smallest-ai.ts # API service with mock implementation
│ │ ├── translation.ts # Language adaptation service
│ │ └── storage.ts # Session storage service
│ ├── utils/
│ │ ├── context-manager.ts # Conversation context management
│ │ └── response-processor.ts # Response processing utilities
│ └── index.ts # Main application entry point
├── .env # Environment variables (create this file)
├── package.json # Project configuration
└── tsconfig.json # TypeScript configuration
Configuration
Create a .env file in the root directory with your API key (not required for mock mode):
SMALLEST_AI_API_KEY=your_api_key_here
Using the Chatbot
The main entry point for the chatbot is the customerServiceChat function in src/index.ts:
const response = await customerServiceChat(
"Hello, I'm having an issue with my recent order",
"user-session-123",
"Example Corp"
);
console.log(response);
Switching to the Real API
To use the real smallest.ai API instead of the mock implementation:
- Make sure you have a valid API key in your
.envfile - Edit
src/services/smallest-ai.tsto use the real API implementation instead of the mock
Customization
Knowledge Base
Populate the knowledge base in src/services/storage.ts with your company's products, policies, and FAQs.
Communication Style
Modify the communication styles in src/services/translation.ts to match your brand voice.
Adding Features
- Add more follow-up action types in
src/utils/response-processor.ts - Implement persistent storage in
src/services/storage.ts - Add authentication and rate limiting
Production Deployment
Before deploying to production:
- Replace the mock API with the real API implementation
- Implement proper session storage (database)
- Add comprehensive error handling and logging
- Set up monitoring and alerts