prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Allow freqai to pull prediction_models from user_data
  Currently, only classes present in `freqai/prediction_models` are available for backtesting/trading.
  Allowing the user to define a custom model to be used with `--freqaimodel` would allow more flexibility.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `freqtrade/configuration/directory_operations.py`
  Content:
  ```
  1 import logging
  2 import shutil
  3 from pathlib import Path
  4 from typing import Optional
  5 
  6 from freqtrade.constants import USER_DATA_FILES, Config
  7 from freqtrade.exceptions import OperationalException
  8 
  9 
  10 logger = logging.getLogger(__name__)
  11 
  12 
  13 def create_datadir(config: Config, datadir: Optional[str] = None) -> Path:
  14 
  15     folder = Path(datadir) if datadir else Path(f"{config['user_data_dir']}/data")
  16     if not datadir:
  17         # set datadir
  18         exchange_name = config.get('exchange', {}).get('name', '').lower()
  19         folder = folder.joinpath(exchange_name)
  20 
  21     if not folder.is_dir():
  22         folder.mkdir(parents=True)
  23         logger.info(f'Created data directory: {datadir}')
  24     return folder
  25 
  26 
  27 def chown_user_directory(directory: Path) -> None:
  28     """
  29     Use Sudo to change permissions of the home-directory if necessary
  30     Only applies when running in docker!
  31     """
  32     import os
  33     if os.environ.get('FT_APP_ENV') == 'docker':
  34         try:
  35             import subprocess
  36             subprocess.check_output(
  37                 ['sudo', 'chown', '-R', 'ftuser:', str(directory.resolve())])
  38         except Exception:
  39             logger.warning(f"Could not chown {directory}")
  40 
  41 
  42 def create_userdata_dir(directory: str, create_dir: bool = False) -> Path:
  43     """
  44     Create userdata directory structure.
  45     if create_dir is True, then the parent-directory will be created if it does not exist.
  46     Sub-directories will always be created if the parent directory exists.
  47     Raises OperationalException if given a non-existing directory.
  48     :param directory: Directory to check
  49     :param create_dir: Create directory if it does not exist.
  50     :return: Path object containing the directory
  51     """
  52     sub_dirs = ["backtest_results", "data", "hyperopts", "hyperopt_results", "logs",
  53                 "notebooks", "plot", "strategies", ]
  54     folder = Path(directory)
  55     chown_user_directory(folder)
  56     if not folder.is_dir():
  57         if create_dir:
  58             folder.mkdir(parents=True)
  59             logger.info(f'Created user-data directory: {folder}')
  60         else:
  61             raise OperationalException(
  62                 f"Directory `{folder}` does not exist. "
  63                 "Please use `freqtrade create-userdir` to create a user directory")
  64 
  65     # Create required subdirectories
  66     for f in sub_dirs:
  67         subfolder = folder / f
  68         if not subfolder.is_dir():
  69             subfolder.mkdir(parents=False)
  70     return folder
  71 
  72 
  73 def copy_sample_files(directory: Path, overwrite: bool = False) -> None:
  74     """
  75     Copy files from templates to User data directory.
  76     :param directory: Directory to copy data to
  77     :param overwrite: Overwrite existing sample files
  78     """
  79     if not directory.is_dir():
  80         raise OperationalException(f"Directory `{directory}` does not exist.")
  81     sourcedir = Path(__file__).parents[1] / "templates"
  82     for source, target in USER_DATA_FILES.items():
  83         targetdir = directory / target
  84         if not targetdir.is_dir():
  85             raise OperationalException(f"Directory `{targetdir}` does not exist.")
  86         targetfile = targetdir / source
  87         if targetfile.exists():
  88             if not overwrite:
  89                 logger.warning(f"File `{targetfile}` exists already, not deploying sample file.")
  90                 continue
  91             logger.warning(f"File `{targetfile}` exists already, overwriting.")
  92         shutil.copy(str(sourcedir / source), str(targetfile))
  93
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/freqtrade/configuration/directory_operations.py b/freqtrade/configuration/directory_operations.py
  --- a/freqtrade/configuration/directory_operations.py
  +++ b/freqtrade/configuration/directory_operations.py
  @@ -3,7 +3,8 @@
   from pathlib import Path
   from typing import Optional
   
  -from freqtrade.constants import USER_DATA_FILES, Config
  +from freqtrade.constants import (USER_DATA_FILES, USERPATH_FREQAIMODELS, USERPATH_HYPEROPTS,
  +                                 USERPATH_NOTEBOOKS, USERPATH_STRATEGIES, Config)
   from freqtrade.exceptions import OperationalException
   
   
  @@ -49,8 +50,8 @@
       :param create_dir: Create directory if it does not exist.
       :return: Path object containing the directory
       """
  -    sub_dirs = ["backtest_results", "data", "hyperopts", "hyperopt_results", "logs",
  -                "notebooks", "plot", "strategies", ]
  +    sub_dirs = ["backtest_results", "data", USERPATH_HYPEROPTS, "hyperopt_results", "logs",
  +                USERPATH_NOTEBOOKS, "plot", USERPATH_STRATEGIES, USERPATH_FREQAIMODELS]
       folder = Path(directory)
       chown_user_directory(folder)
       if not folder.is_dir():
  
verification_info: {"golden_diff": "diff --git a/freqtrade/configuration/directory_operations.py b/freqtrade/configuration/directory_operations.py\n--- a/freqtrade/configuration/directory_operations.py\n+++ b/freqtrade/configuration/directory_operations.py\n@@ -3,7 +3,8 @@\n from pathlib import Path\n from typing import Optional\n \n-from freqtrade.constants import USER_DATA_FILES, Config\n+from freqtrade.constants import (USER_DATA_FILES, USERPATH_FREQAIMODELS, USERPATH_HYPEROPTS,\n+                                 USERPATH_NOTEBOOKS, USERPATH_STRATEGIES, Config)\n from freqtrade.exceptions import OperationalException\n \n \n@@ -49,8 +50,8 @@\n     :param create_dir: Create directory if it does not exist.\n     :return: Path object containing the directory\n     \"\"\"\n-    sub_dirs = [\"backtest_results\", \"data\", \"hyperopts\", \"hyperopt_results\", \"logs\",\n-                \"notebooks\", \"plot\", \"strategies\", ]\n+    sub_dirs = [\"backtest_results\", \"data\", USERPATH_HYPEROPTS, \"hyperopt_results\", \"logs\",\n+                USERPATH_NOTEBOOKS, \"plot\", USERPATH_STRATEGIES, USERPATH_FREQAIMODELS]\n     folder = Path(directory)\n     chown_user_directory(folder)\n     if not folder.is_dir():\n", "issue": "Allow freqai to pull prediction_models from user_data\nCurrently, only classes present in `freqai/prediction_models` are available for backtesting/trading.\r\nAllowing the user to define a custom model to be used with `--freqaimodel` would allow more flexibility.\n", "before_files": [{"content": "import logging\nimport shutil\nfrom pathlib import Path\nfrom typing import Optional\n\nfrom freqtrade.constants import USER_DATA_FILES, Config\nfrom freqtrade.exceptions import OperationalException\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef create_datadir(config: Config, datadir: Optional[str] = None) -> Path:\n\n    folder = Path(datadir) if datadir else Path(f\"{config['user_data_dir']}/data\")\n    if not datadir:\n        # set datadir\n        exchange_name = config.get('exchange', {}).get('name', '').lower()\n        folder = folder.joinpath(exchange_name)\n\n    if not folder.is_dir():\n        folder.mkdir(parents=True)\n        logger.info(f'Created data directory: {datadir}')\n    return folder\n\n\ndef chown_user_directory(directory: Path) -> None:\n    \"\"\"\n    Use Sudo to change permissions of the home-directory if necessary\n    Only applies when running in docker!\n    \"\"\"\n    import os\n    if os.environ.get('FT_APP_ENV') == 'docker':\n        try:\n            import subprocess\n            subprocess.check_output(\n                ['sudo', 'chown', '-R', 'ftuser:', str(directory.resolve())])\n        except Exception:\n            logger.warning(f\"Could not chown {directory}\")\n\n\ndef create_userdata_dir(directory: str, create_dir: bool = False) -> Path:\n    \"\"\"\n    Create userdata directory structure.\n    if create_dir is True, then the parent-directory will be created if it does not exist.\n    Sub-directories will always be created if the parent directory exists.\n    Raises OperationalException if given a non-existing directory.\n    :param directory: Directory to check\n    :param create_dir: Create directory if it does not exist.\n    :return: Path object containing the directory\n    \"\"\"\n    sub_dirs = [\"backtest_results\", \"data\", \"hyperopts\", \"hyperopt_results\", \"logs\",\n                \"notebooks\", \"plot\", \"strategies\", ]\n    folder = Path(directory)\n    chown_user_directory(folder)\n    if not folder.is_dir():\n        if create_dir:\n            folder.mkdir(parents=True)\n            logger.info(f'Created user-data directory: {folder}')\n        else:\n            raise OperationalException(\n                f\"Directory `{folder}` does not exist. \"\n                \"Please use `freqtrade create-userdir` to create a user directory\")\n\n    # Create required subdirectories\n    for f in sub_dirs:\n        subfolder = folder / f\n        if not subfolder.is_dir():\n            subfolder.mkdir(parents=False)\n    return folder\n\n\ndef copy_sample_files(directory: Path, overwrite: bool = False) -> None:\n    \"\"\"\n    Copy files from templates to User data directory.\n    :param directory: Directory to copy data to\n    :param overwrite: Overwrite existing sample files\n    \"\"\"\n    if not directory.is_dir():\n        raise OperationalException(f\"Directory `{directory}` does not exist.\")\n    sourcedir = Path(__file__).parents[1] / \"templates\"\n    for source, target in USER_DATA_FILES.items():\n        targetdir = directory / target\n        if not targetdir.is_dir():\n            raise OperationalException(f\"Directory `{targetdir}` does not exist.\")\n        targetfile = targetdir / source\n        if targetfile.exists():\n            if not overwrite:\n                logger.warning(f\"File `{targetfile}` exists already, not deploying sample file.\")\n                continue\n            logger.warning(f\"File `{targetfile}` exists already, overwriting.\")\n        shutil.copy(str(sourcedir / source), str(targetfile))\n", "path": "freqtrade/configuration/directory_operations.py"}], "after_files": [{"content": "import logging\nimport shutil\nfrom pathlib import Path\nfrom typing import Optional\n\nfrom freqtrade.constants import (USER_DATA_FILES, USERPATH_FREQAIMODELS, USERPATH_HYPEROPTS,\n                                 USERPATH_NOTEBOOKS, USERPATH_STRATEGIES, Config)\nfrom freqtrade.exceptions import OperationalException\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef create_datadir(config: Config, datadir: Optional[str] = None) -> Path:\n\n    folder = Path(datadir) if datadir else Path(f\"{config['user_data_dir']}/data\")\n    if not datadir:\n        # set datadir\n        exchange_name = config.get('exchange', {}).get('name', '').lower()\n        folder = folder.joinpath(exchange_name)\n\n    if not folder.is_dir():\n        folder.mkdir(parents=True)\n        logger.info(f'Created data directory: {datadir}')\n    return folder\n\n\ndef chown_user_directory(directory: Path) -> None:\n    \"\"\"\n    Use Sudo to change permissions of the home-directory if necessary\n    Only applies when running in docker!\n    \"\"\"\n    import os\n    if os.environ.get('FT_APP_ENV') == 'docker':\n        try:\n            import subprocess\n            subprocess.check_output(\n                ['sudo', 'chown', '-R', 'ftuser:', str(directory.resolve())])\n        except Exception:\n            logger.warning(f\"Could not chown {directory}\")\n\n\ndef create_userdata_dir(directory: str, create_dir: bool = False) -> Path:\n    \"\"\"\n    Create userdata directory structure.\n    if create_dir is True, then the parent-directory will be created if it does not exist.\n    Sub-directories will always be created if the parent directory exists.\n    Raises OperationalException if given a non-existing directory.\n    :param directory: Directory to check\n    :param create_dir: Create directory if it does not exist.\n    :return: Path object containing the directory\n    \"\"\"\n    sub_dirs = [\"backtest_results\", \"data\", USERPATH_HYPEROPTS, \"hyperopt_results\", \"logs\",\n                USERPATH_NOTEBOOKS, \"plot\", USERPATH_STRATEGIES, USERPATH_FREQAIMODELS]\n    folder = Path(directory)\n    chown_user_directory(folder)\n    if not folder.is_dir():\n        if create_dir:\n            folder.mkdir(parents=True)\n            logger.info(f'Created user-data directory: {folder}')\n        else:\n            raise OperationalException(\n                f\"Directory `{folder}` does not exist. \"\n                \"Please use `freqtrade create-userdir` to create a user directory\")\n\n    # Create required subdirectories\n    for f in sub_dirs:\n        subfolder = folder / f\n        if not subfolder.is_dir():\n            subfolder.mkdir(parents=False)\n    return folder\n\n\ndef copy_sample_files(directory: Path, overwrite: bool = False) -> None:\n    \"\"\"\n    Copy files from templates to User data directory.\n    :param directory: Directory to copy data to\n    :param overwrite: Overwrite existing sample files\n    \"\"\"\n    if not directory.is_dir():\n        raise OperationalException(f\"Directory `{directory}` does not exist.\")\n    sourcedir = Path(__file__).parents[1] / \"templates\"\n    for source, target in USER_DATA_FILES.items():\n        targetdir = directory / target\n        if not targetdir.is_dir():\n            raise OperationalException(f\"Directory `{targetdir}` does not exist.\")\n        targetfile = targetdir / source\n        if targetfile.exists():\n            if not overwrite:\n                logger.warning(f\"File `{targetfile}` exists already, not deploying sample file.\")\n                continue\n            logger.warning(f\"File `{targetfile}` exists already, overwriting.\")\n        shutil.copy(str(sourcedir / source), str(targetfile))\n", "path": "freqtrade/configuration/directory_operations.py"}]}