code: def create_chatbot(project_name, name, chatbot):
      if name is None:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Missing field",
              'Missing "name" field for chatbot',
          )
  
      model_name = chatbot.get("model_name", None)
      agent_name = chatbot.get("agent_name", None)
      if model_name is None and agent_name is None:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Missing field",
              'Must include either "model_name" or "agent_name" field for chatbot',
          )
  
      session_controller = SessionController()
  
      if "database_id" not in chatbot:
          if "db_params" in chatbot and "db_engine" in chatbot:
              db_name = chatbot["name"] + "_db"
  
              # try to drop
              existing_db = (
                  session_controller.integration_controller.get(db_name)
              )
              if existing_db:
                  # drop
                  session_controller.integration_controller.delete(
                      db_name
                  )
  
              database_id = (
                  session_controller.integration_controller.add(
                      db_name,
                      chatbot["db_engine"],
                      chatbot["db_params"],
                  )
              )
  
          else:
              return http_error(
                  HTTPStatus.BAD_REQUEST,
                  "Missing field",
                  'Missing "database_id" or ("db_engine" and "database_param") fields for chatbot',
              )
      else:
          database_id = chatbot.get("database_id", None)
  
      is_running = chatbot.get("is_running", False)
      params = chatbot.get("params", {})
  
      chatbot_controller = ChatBotController()
  
      # Chatbot can't already exist.
      # TODO all checks should be inside of controller
  
      try:
          existing_chatbot = chatbot_controller.get_chatbot(
              name, project_name=project_name
          )
      except ValueError:
          # Project must exist.
          return http_error(
              HTTPStatus.NOT_FOUND,
              "Project not found",
              f"Project with name {project_name} does not exist",
          )
      if existing_chatbot is not None:
          return http_error(
              HTTPStatus.CONFLICT,
              "Chatbot already exists",
              f"Chatbot with name {name} already exists. Please use a different name",
          )
  
      # Model and agent need to exist.
      agents_controller = AgentsController()
      if agent_name is not None:
          agent = agents_controller.get_agent(agent_name, project_name)
          if agent is None:
              return http_error(
                  HTTPStatus.NOT_FOUND,
                  "Agent not found",
                  f"Agent with name {agent_name} not found",
              )
          model_name = agent.model_name
  
      model_name_no_version, version = Predictor.get_name_and_version(
          model_name
      )
      try:
          session_controller.model_controller.get_model(
              model_name_no_version,
              version=version,
              project_name=project_name,
          )
      except PredictorRecordNotFound:
          return http_error(
              HTTPStatus.NOT_FOUND,
              "Model not found",
              f"Model with name {model_name} not found",
          )
  
      created_chatbot = chatbot_controller.add_chatbot(
          name,
          project_name,
          model_name=model_name,
          agent_name=agent_name,
          database_id=database_id,
          is_running=is_running,
          params=params,
      )
      return created_chatbot.as_dict(), HTTPStatus.CREATED
  
file_path: mindsdb/mindsdb/api/http/namespaces/chatbots.py
imports: from http import HTTPStatus
  from flask import request
  from flask_restx import Resource
  from mindsdb.api.http.namespaces.configs.projects import ns_conf
  from mindsdb.api.executor.controllers.session_controller import SessionController
  from mindsdb.api.http.utils import http_error
  from mindsdb.interfaces.agents.agents_controller import AgentsController
  from mindsdb.interfaces.chatbot.chatbot_controller import ChatBotController
  from mindsdb.interfaces.model.functions import PredictorRecordNotFound
  from mindsdb.interfaces.storage.db import Predictor
label_desc: Use image node_id 1 for calling a global function with example usage: create_chatbot(project_name, name, chatbot) and returns: created_chatbot,  HTTPStatus, http_error, http_error, http_error, http_error, http_error, http_error, http_error