Shoulder.dev Logo Shoulder.dev

What is Standalone Bot API?

The Standalone Bot API is a component of the GenAI Stack, an open-source project developed by Docker, which provides a conversational AI interface for interacting with various services and applications. The API allows developers to build standalone bots that can answer questions and perform tasks using natural language processing and machine learning models.

Why is Standalone Bot API important?

The Standalone Bot API is important because it enables developers to create custom bots that can interact with users in a conversational way, without the need for complex integrations or extensive knowledge of natural language processing and machine learning. This can save time and resources, as well as improve the user experience by providing more personalized and efficient interactions.

Endpoints

The Standalone Bot API offers both non-streaming and SSE (Server-Sent Events) streaming endpoints for handling user requests and returning responses.

Non-streaming Endpoint

The non-streaming endpoint is used for handling simple requests and returning single responses. It accepts POST requests with a JSON payload containing the user’s query and returns a JSON response with the bot’s response.

const axios = require('axios');
      
      const apiUrl = 'http://localhost:3000/api/v1/bot';
      
      const askQuestion = async (question) => {
      const response = await axios.post(apiUrl, { question });
      return response.data.answer;
      };
      
      const question = 'What is the capital city of France?';
      const answer = await askQuestion(question);
      console.log(answer); // 'Paris'
      

SSE Streaming Endpoint

The SSE streaming endpoint is used for handling more complex requests and returning multiple responses over time. It accepts POST requests with a JSON payload containing the user’s query and returns a Server-Sent Event stream with the bot’s responses.

const EventSource = require('eventsource');
      
      const apiUrl = 'http://localhost:3000/api/v1/bot/stream';
      
      const askQuestion = (question) => {
      const source = new EventSource(apiUrl);
      
      source.onmessage = (event) => {
      const response = JSON.parse(event.data);
      console.log(response.answer);
      };
      
      source.send(JSON.stringify({ question }));
      };
      
      const question = 'Tell me a joke';
      askQuestion(question);
      

Usage

To use the Standalone Bot API, you need to have the GenAI Stack installed and running on your local machine. You can then make requests to the API using your preferred HTTP client or library.

For more information on installing and configuring the GenAI Stack, please refer to the official documentation.

Source

For more information about the Standalone Bot API, please refer to the GitHub repository.

Explanation