DLC Chatbot API Documentation

Introduction

The DLC Chatbot API provides a simple interface for interacting with our document-based chatbot system. You can use this API to integrate the chatbot into your own applications, websites, or services.

All API endpoints are prefixed with /api and return JSON responses.

Authentication

Currently, the API does not require authentication. However, we recommend implementing appropriate authentication in production environments.

Endpoints

The following endpoints are available:

Status Check

GET /api/status

Check if the API is running.

Response

{
  "message": "DLC Chatbot API is online",
  "status": "active"
}

Send a Message

POST /api/chat

Send a question to the chatbot. If no session_id is provided, a new session will be created.

Request Body

{
  "question": "What services does DLC offer?",
  "session_id": "optional-session-id"
}
Parameter Type Required Description
question string Yes The user's question for the chatbot
session_id string No Session ID to continue an existing conversation

Response

{
  "answer": "DLC offers consultancy services in artificial intelligence and machine learning...",
  "session_id": "550e8400-e29b-41d4-a716-446655440000"
}

Create a Session

POST /api/sessions

Create a new chat session.

Response

{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "created_at": "2023-10-15T14:30:22.123456"
}

List Sessions

GET /api/sessions

Get a list of all chat sessions.

Response

{
  "sessions": [
    {
      "session_id": "550e8400-e29b-41d4-a716-446655440000",
      "created_at": "2023-10-15T14:30:22.123456"
    },
    {
      "session_id": "550e8400-e29b-41d4-a716-446655440001",
      "created_at": "2023-10-15T15:45:10.987654"
    }
  ]
}

Get Session History

GET /api/sessions/{session_id}/history

Get the chat history for a specific session.

Path Parameters

Parameter Type Description
session_id string The ID of the session to retrieve history for

Response

{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "history": [
    {
      "timestamp": "2023-10-15T14:30:30.123456",
      "question": "What services does DLC offer?",
      "answer": "DLC offers consultancy services in artificial intelligence and machine learning..."
    },
    {
      "timestamp": "2023-10-15T14:31:15.987654",
      "question": "When was DLC founded?",
      "answer": "DLC was founded in 2020 by a team of AI researchers..."
    }
  ]
}

Code Examples

JavaScript/Fetch

// Send a question to the chatbot
async function askQuestion(question, sessionId = null) {
  const response = await fetch('/api/chat', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      question: question,
      session_id: sessionId
    })
  });
  
  return await response.json();
}

// Example usage
askQuestion('What services does DLC offer?')
  .then(data => {
    console.log('Answer:', data.answer);
    console.log('Session ID:', data.session_id);
  })
  .catch(error => console.error('Error:', error));

Python/Requests

import requests

def ask_question(question, session_id=None):
    """Send a question to the chatbot API"""
    payload = {
        "question": question
    }
    
    if session_id:
        payload["session_id"] = session_id
    
    response = requests.post(
        "http://localhost:8000/api/chat",
        json=payload
    )
    
    return response.json()

# Example usage
result = ask_question("What services does DLC offer?")
print("Answer:", result["answer"])
print("Session ID:", result["session_id"])