class_docstr: Handles CRUD operations at the database level for Chatbots
class_docstr_tok: ["Handles","CRUD","operations","at","the","database","level","for","Chatbots"]
docstr: Updates a chatbot in the database, creating it if it doesn't already exist.
  
  Parameters:
      chatbot_name (str): The name of the new chatbot, or existing chatbot to update
      project_name (str): The containing project
      name (str): The updated name of the chatbot
      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 the chatbot will run after update/creation
      params: (Dict[str, str]): Parameters to use when running the chatbot
  
  Returns:
      bot (db.ChatBots): The created or updated chatbot
docstr_tok: ["Updates","a","chatbot","in","the","database",",","creating","it","if","it","does","n't","already","exist",".","Parameters",":","chatbot_name","(","str",")",":","The","name","of","the","new","chatbot",",","or","existing","chatbot","to","update","project_name","(","str",")",":","The","containing","project","name","(","str",")",":","The","updated","name","of","the","chatbot","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","the","chatbot","will","run","after","update\/creation","params",":","(","Dict","[","str",",","str","]",")",":","Parameters","to","use","when","running","the","chatbot","Returns",":","bot","(","db.ChatBots",")",":","The","created","or","updated","chatbot"]
code: def update_chatbot(
      self,
      chatbot_name: str,
      project_name: str = "mindsdb",
      name: str = None,
      model_name: str = None,
      agent_name: str = None,
      database_id: int = None,
      is_running: bool = None,
      params: Dict[str, str] = None,
  ):
      """
      Updates a chatbot in the database, creating it if it doesn't already exist.
  
      Parameters:
          chatbot_name (str): The name of the new chatbot, or existing chatbot to update
          project_name (str): The containing project
          name (str): The updated name of the chatbot
          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 the chatbot will run after update/creation
          params: (Dict[str, str]): Parameters to use when running the chatbot
  
      Returns:
          bot (db.ChatBots): The created or updated chatbot
      """
  
      existing_chatbot = self.get_chatbot(
          chatbot_name, project_name=project_name
      )
      if existing_chatbot is None:
          raise Exception(f"Chat bot not found: {chatbot_name}")
  
      existing_chatbot_rec = db.ChatBots.query.get(
          existing_chatbot["id"]
      )
  
      if name is not None and name != chatbot_name:
          # check new name
          bot2 = self.get_chatbot(name, project_name=project_name)
          if bot2 is not None:
              raise Exception(f"Chat already exists: {name}")
  
          existing_chatbot_rec.name = name
  
      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}"
              )
          existing_chatbot_rec.agent_id = agent.id
  
      if model_name is not None:
          # TODO check model_name
          existing_chatbot_rec.model_name = model_name
      if database_id is not None:
          # TODO check database_id
          existing_chatbot_rec.database_id = database_id
  
      task = db.Tasks.query.filter(
          db.Tasks.object_type == self.OBJECT_TYPE,
          db.Tasks.object_id == existing_chatbot_rec.id,
          db.Tasks.company_id == ctx.company_id,
      ).first()
  
      if task is not None:
          if is_running is not None:
              task.active = is_running
  
          # reload task
          task.reload = True
  
      if params is not None:
          # Merge params on update
          existing_params = existing_chatbot_rec.params or {}
          params.update(existing_params)
          existing_chatbot_rec.params = params
      db.session.commit()
  
      return existing_chatbot_rec
  
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 5 for calling the ChatBotController obj's underlying member method code with example usage: obj.update_chatbot(chatbot_name, project_name, name, model_name, agent_name, database_id, is_running, params) and returns: existing_chatbot_rec