class_docstr: Handles CRUD operations at the database level for Chatbots
class_docstr_tok: ["Handles","CRUD","operations","at","the","database","level","for","Chatbots"]
docstr: Adds a chatbot to the database.
  
  Parameters:
      name (str): The name of the new chatbot
      project_name (str): The containing project
      model_name (str): The name of the existing ML model the chatbot will use
      agent_name (str): The name of the existing agent the chatbot will use
      database_id (int): The ID of the existing database the chatbot will use
      is_running (bool): Whether or not to start the chatbot right after creation
      params: (Dict[str, str]): Parameters to use when running the chatbot
  
  Returns:
      bot (db.ChatBots): The created chatbot
docstr_tok: ["Adds","a","chatbot","to","the","database",".","Parameters",":","name","(","str",")",":","The","name","of","the","new","chatbot","project_name","(","str",")",":","The","containing","project","model_name","(","str",")",":","The","name","of","the","existing","ML","model","the","chatbot","will","use","agent_name","(","str",")",":","The","name","of","the","existing","agent","the","chatbot","will","use","database_id","(","int",")",":","The","ID","of","the","existing","database","the","chatbot","will","use","is_running","(","bool",")",":","Whether","or","not","to","start","the","chatbot","right","after","creation","params",":","(","Dict","[","str",",","str","]",")",":","Parameters","to","use","when","running","the","chatbot","Returns",":","bot","(","db.ChatBots",")",":","The","created","chatbot"]
code: def add_chatbot(
      self,
      name: str,
      project_name: str,
      model_name: str = None,
      agent_name: str = None,
      database_id: int = None,
      is_running: bool = True,
      params: Dict[str, str] = {},
  ) -> db.ChatBots:
      """
      Adds a chatbot to the database.
  
      Parameters:
          name (str): The name of the new chatbot
          project_name (str): The containing project
          model_name (str): The name of the existing ML model the chatbot will use
          agent_name (str): The name of the existing agent the chatbot will use
          database_id (int): The ID of the existing database the chatbot will use
          is_running (bool): Whether or not to start the chatbot right after creation
          params: (Dict[str, str]): Parameters to use when running the chatbot
  
      Returns:
          bot (db.ChatBots): The created chatbot
      """
  
      config = Config()
  
      is_cloud = config.get("cloud", False)
      if is_cloud and ctx.user_class == 0:
          raise Exception("You can't create chatbot")
  
      if project_name is None:
          project_name = "mindsdb"
      project = self.project_controller.get(name=project_name)
  
      bot = self.get_chatbot(name, project_name)
  
      if bot is not None:
          raise Exception(f"Chat bot already exists: {name}")
  
      # check database
      session_controller = SessionController()
      db_record = session_controller.integration_controller.get_by_id(
          database_id
      )
      if db_record is None:
          raise Exception(f"Database doesn't exist: {database_id}")
  
      if model_name is None and agent_name is None:
          raise ValueError(
              'Need to provide either "model_name" or "agent_name" when creating a chatbot'
          )
      if agent_name is not None:
          agent = self.agents_controller.get_agent(
              agent_name, project_name
          )
          if agent is None:
              raise ValueError(
                  f"Agent with name doesn't exist: {agent_name}"
              )
      else:
          # Create a new agent with the given model name.
          agent = self.agents_controller.add_agent(
              name, project_name, model_name, []
          )
  
      bot = db.ChatBots(
          name=name,
          project_id=project.id,
          agent_id=agent.id,
          model_name=agent.model_name,
          database_id=database_id,
          params=params,
      )
      db.session.add(bot)
      db.session.flush()
  
      task_record = db.Tasks(
          company_id=ctx.company_id,
          user_class=ctx.user_class,
          object_type=self.OBJECT_TYPE,
          object_id=bot.id,
          active=is_running,
      )
      db.session.add(task_record)
  
      db.session.commit()
  
      return bot
  
file_path: mindsdb/mindsdb/interfaces/chatbot/chatbot_controller.py
imports: from typing import Dict, List
  from mindsdb.interfaces.agents.agents_controller import AgentsController
  from mindsdb.interfaces.database.projects import ProjectController
  from mindsdb.interfaces.storage import db
  from mindsdb.utilities.context import context
  from mindsdb.api.executor.controllers.session_controller import SessionController
  from mindsdb.utilities.config import Config
label_desc: Use image node_id 4 for calling the ChatBotController obj's underlying member method code with example usage: obj.add_chatbot(name, project_name, model_name, agent_name, database_id, is_running, params) and returns: bot