prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Restrict the training set of the StepsToReproduce model only to defects
  Given that STRs don't apply to enhancement or task.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `bugbug/models/stepstoreproduce.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 # This Source Code Form is subject to the terms of the Mozilla Public
  3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4 # You can obtain one at http://mozilla.org/MPL/2.0/.
  5 
  6 import logging
  7 
  8 import xgboost
  9 from imblearn.pipeline import Pipeline as ImblearnPipeline
  10 from imblearn.under_sampling import RandomUnderSampler
  11 from sklearn.compose import ColumnTransformer
  12 from sklearn.feature_extraction import DictVectorizer
  13 from sklearn.pipeline import Pipeline
  14 
  15 from bugbug import bug_features, bugzilla, feature_cleanup, utils
  16 from bugbug.model import BugModel
  17 
  18 logging.basicConfig(level=logging.INFO)
  19 logger = logging.getLogger(__name__)
  20 
  21 
  22 class StepsToReproduceModel(BugModel):
  23     def __init__(self, lemmatization=False):
  24         BugModel.__init__(self, lemmatization)
  25 
  26         feature_extractors = [
  27             bug_features.HasRegressionRange(),
  28             bug_features.Severity(),
  29             bug_features.Keywords({"stepswanted"}),
  30             bug_features.IsCoverityIssue(),
  31             bug_features.HasCrashSignature(),
  32             bug_features.HasURL(),
  33             bug_features.HasW3CURL(),
  34             bug_features.HasGithubURL(),
  35             bug_features.Whiteboard(),
  36             bug_features.Patches(),
  37             bug_features.Landings(),
  38         ]
  39 
  40         cleanup_functions = [
  41             feature_cleanup.fileref(),
  42             feature_cleanup.url(),
  43             feature_cleanup.synonyms(),
  44         ]
  45 
  46         self.extraction_pipeline = Pipeline(
  47             [
  48                 (
  49                     "bug_extractor",
  50                     bug_features.BugExtractor(feature_extractors, cleanup_functions),
  51                 ),
  52             ]
  53         )
  54 
  55         self.clf = ImblearnPipeline(
  56             [
  57                 (
  58                     "union",
  59                     ColumnTransformer(
  60                         [
  61                             ("data", DictVectorizer(), "data"),
  62                             ("title", self.text_vectorizer(), "title"),
  63                             ("comments", self.text_vectorizer(), "comments"),
  64                         ]
  65                     ),
  66                 ),
  67                 ("sampler", RandomUnderSampler(random_state=0)),
  68                 (
  69                     "estimator",
  70                     xgboost.XGBClassifier(n_jobs=utils.get_physical_cpu_count()),
  71                 ),
  72             ]
  73         )
  74 
  75     def get_labels(self):
  76         classes = {}
  77 
  78         for bug_data in bugzilla.get_bugs():
  79             if "cf_has_str" in bug_data:
  80                 if bug_data["cf_has_str"] == "no":
  81                     classes[int(bug_data["id"])] = 0
  82                 elif bug_data["cf_has_str"] == "yes":
  83                     classes[int(bug_data["id"])] = 1
  84             elif "stepswanted" in bug_data["keywords"]:
  85                 classes[int(bug_data["id"])] = 0
  86             else:
  87                 for entry in bug_data["history"]:
  88                     for change in entry["changes"]:
  89                         if change["removed"].startswith("stepswanted"):
  90                             classes[int(bug_data["id"])] = 1
  91 
  92         logger.info(
  93             "%d bugs have no steps to reproduce",
  94             sum(label == 0 for label in classes.values()),
  95         )
  96         logger.info(
  97             "%d bugs have steps to reproduce",
  98             sum(label == 1 for label in classes.values()),
  99         )
  100 
  101         return classes, [0, 1]
  102 
  103     def overwrite_classes(self, bugs, classes, probabilities):
  104         for i, bug in enumerate(bugs):
  105             if "cf_has_str" in bug and bug["cf_has_str"] == "no":
  106                 classes[i] = 0 if not probabilities else [1.0, 0.0]
  107             elif "cf_has_str" in bug and bug["cf_has_str"] == "yes":
  108                 classes[i] = 1 if not probabilities else [0.0, 1.0]
  109             elif "stepswanted" in bug["keywords"]:
  110                 classes[i] = 0 if not probabilities else [1.0, 0.0]
  111 
  112         return classes
  113 
  114     def get_feature_names(self):
  115         return self.clf.named_steps["union"].get_feature_names_out()
  116
  ```
  --- 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/bugbug/models/stepstoreproduce.py b/bugbug/models/stepstoreproduce.py
  --- a/bugbug/models/stepstoreproduce.py
  +++ b/bugbug/models/stepstoreproduce.py
  @@ -76,6 +76,8 @@
           classes = {}
   
           for bug_data in bugzilla.get_bugs():
  +            if bug_data["type"] != "defect":
  +                continue
               if "cf_has_str" in bug_data:
                   if bug_data["cf_has_str"] == "no":
                       classes[int(bug_data["id"])] = 0
  
verification_info: {"golden_diff": "diff --git a/bugbug/models/stepstoreproduce.py b/bugbug/models/stepstoreproduce.py\n--- a/bugbug/models/stepstoreproduce.py\n+++ b/bugbug/models/stepstoreproduce.py\n@@ -76,6 +76,8 @@\n         classes = {}\n \n         for bug_data in bugzilla.get_bugs():\n+            if bug_data[\"type\"] != \"defect\":\n+                continue\n             if \"cf_has_str\" in bug_data:\n                 if bug_data[\"cf_has_str\"] == \"no\":\n                     classes[int(bug_data[\"id\"])] = 0\n", "issue": "Restrict the training set of the StepsToReproduce model only to defects\nGiven that STRs don't apply to enhancement or task.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# This Source Code Form is subject to the terms of the Mozilla Public\n# License, v. 2.0. If a copy of the MPL was not distributed with this file,\n# You can obtain one at http://mozilla.org/MPL/2.0/.\n\nimport logging\n\nimport xgboost\nfrom imblearn.pipeline import Pipeline as ImblearnPipeline\nfrom imblearn.under_sampling import RandomUnderSampler\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.feature_extraction import DictVectorizer\nfrom sklearn.pipeline import Pipeline\n\nfrom bugbug import bug_features, bugzilla, feature_cleanup, utils\nfrom bugbug.model import BugModel\n\nlogging.basicConfig(level=logging.INFO)\nlogger = logging.getLogger(__name__)\n\n\nclass StepsToReproduceModel(BugModel):\n    def __init__(self, lemmatization=False):\n        BugModel.__init__(self, lemmatization)\n\n        feature_extractors = [\n            bug_features.HasRegressionRange(),\n            bug_features.Severity(),\n            bug_features.Keywords({\"stepswanted\"}),\n            bug_features.IsCoverityIssue(),\n            bug_features.HasCrashSignature(),\n            bug_features.HasURL(),\n            bug_features.HasW3CURL(),\n            bug_features.HasGithubURL(),\n            bug_features.Whiteboard(),\n            bug_features.Patches(),\n            bug_features.Landings(),\n        ]\n\n        cleanup_functions = [\n            feature_cleanup.fileref(),\n            feature_cleanup.url(),\n            feature_cleanup.synonyms(),\n        ]\n\n        self.extraction_pipeline = Pipeline(\n            [\n                (\n                    \"bug_extractor\",\n                    bug_features.BugExtractor(feature_extractors, cleanup_functions),\n                ),\n            ]\n        )\n\n        self.clf = ImblearnPipeline(\n            [\n                (\n                    \"union\",\n                    ColumnTransformer(\n                        [\n                            (\"data\", DictVectorizer(), \"data\"),\n                            (\"title\", self.text_vectorizer(), \"title\"),\n                            (\"comments\", self.text_vectorizer(), \"comments\"),\n                        ]\n                    ),\n                ),\n                (\"sampler\", RandomUnderSampler(random_state=0)),\n                (\n                    \"estimator\",\n                    xgboost.XGBClassifier(n_jobs=utils.get_physical_cpu_count()),\n                ),\n            ]\n        )\n\n    def get_labels(self):\n        classes = {}\n\n        for bug_data in bugzilla.get_bugs():\n            if \"cf_has_str\" in bug_data:\n                if bug_data[\"cf_has_str\"] == \"no\":\n                    classes[int(bug_data[\"id\"])] = 0\n                elif bug_data[\"cf_has_str\"] == \"yes\":\n                    classes[int(bug_data[\"id\"])] = 1\n            elif \"stepswanted\" in bug_data[\"keywords\"]:\n                classes[int(bug_data[\"id\"])] = 0\n            else:\n                for entry in bug_data[\"history\"]:\n                    for change in entry[\"changes\"]:\n                        if change[\"removed\"].startswith(\"stepswanted\"):\n                            classes[int(bug_data[\"id\"])] = 1\n\n        logger.info(\n            \"%d bugs have no steps to reproduce\",\n            sum(label == 0 for label in classes.values()),\n        )\n        logger.info(\n            \"%d bugs have steps to reproduce\",\n            sum(label == 1 for label in classes.values()),\n        )\n\n        return classes, [0, 1]\n\n    def overwrite_classes(self, bugs, classes, probabilities):\n        for i, bug in enumerate(bugs):\n            if \"cf_has_str\" in bug and bug[\"cf_has_str\"] == \"no\":\n                classes[i] = 0 if not probabilities else [1.0, 0.0]\n            elif \"cf_has_str\" in bug and bug[\"cf_has_str\"] == \"yes\":\n                classes[i] = 1 if not probabilities else [0.0, 1.0]\n            elif \"stepswanted\" in bug[\"keywords\"]:\n                classes[i] = 0 if not probabilities else [1.0, 0.0]\n\n        return classes\n\n    def get_feature_names(self):\n        return self.clf.named_steps[\"union\"].get_feature_names_out()\n", "path": "bugbug/models/stepstoreproduce.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# This Source Code Form is subject to the terms of the Mozilla Public\n# License, v. 2.0. If a copy of the MPL was not distributed with this file,\n# You can obtain one at http://mozilla.org/MPL/2.0/.\n\nimport logging\n\nimport xgboost\nfrom imblearn.pipeline import Pipeline as ImblearnPipeline\nfrom imblearn.under_sampling import RandomUnderSampler\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.feature_extraction import DictVectorizer\nfrom sklearn.pipeline import Pipeline\n\nfrom bugbug import bug_features, bugzilla, feature_cleanup, utils\nfrom bugbug.model import BugModel\n\nlogging.basicConfig(level=logging.INFO)\nlogger = logging.getLogger(__name__)\n\n\nclass StepsToReproduceModel(BugModel):\n    def __init__(self, lemmatization=False):\n        BugModel.__init__(self, lemmatization)\n\n        feature_extractors = [\n            bug_features.HasRegressionRange(),\n            bug_features.Severity(),\n            bug_features.Keywords({\"stepswanted\"}),\n            bug_features.IsCoverityIssue(),\n            bug_features.HasCrashSignature(),\n            bug_features.HasURL(),\n            bug_features.HasW3CURL(),\n            bug_features.HasGithubURL(),\n            bug_features.Whiteboard(),\n            bug_features.Patches(),\n            bug_features.Landings(),\n        ]\n\n        cleanup_functions = [\n            feature_cleanup.fileref(),\n            feature_cleanup.url(),\n            feature_cleanup.synonyms(),\n        ]\n\n        self.extraction_pipeline = Pipeline(\n            [\n                (\n                    \"bug_extractor\",\n                    bug_features.BugExtractor(feature_extractors, cleanup_functions),\n                ),\n            ]\n        )\n\n        self.clf = ImblearnPipeline(\n            [\n                (\n                    \"union\",\n                    ColumnTransformer(\n                        [\n                            (\"data\", DictVectorizer(), \"data\"),\n                            (\"title\", self.text_vectorizer(), \"title\"),\n                            (\"comments\", self.text_vectorizer(), \"comments\"),\n                        ]\n                    ),\n                ),\n                (\"sampler\", RandomUnderSampler(random_state=0)),\n                (\n                    \"estimator\",\n                    xgboost.XGBClassifier(n_jobs=utils.get_physical_cpu_count()),\n                ),\n            ]\n        )\n\n    def get_labels(self):\n        classes = {}\n\n        for bug_data in bugzilla.get_bugs():\n            if bug_data[\"type\"] != \"defect\":\n                continue\n            if \"cf_has_str\" in bug_data:\n                if bug_data[\"cf_has_str\"] == \"no\":\n                    classes[int(bug_data[\"id\"])] = 0\n                elif bug_data[\"cf_has_str\"] == \"yes\":\n                    classes[int(bug_data[\"id\"])] = 1\n            elif \"stepswanted\" in bug_data[\"keywords\"]:\n                classes[int(bug_data[\"id\"])] = 0\n            else:\n                for entry in bug_data[\"history\"]:\n                    for change in entry[\"changes\"]:\n                        if change[\"removed\"].startswith(\"stepswanted\"):\n                            classes[int(bug_data[\"id\"])] = 1\n\n        logger.info(\n            \"%d bugs have no steps to reproduce\",\n            sum(label == 0 for label in classes.values()),\n        )\n        logger.info(\n            \"%d bugs have steps to reproduce\",\n            sum(label == 1 for label in classes.values()),\n        )\n\n        return classes, [0, 1]\n\n    def overwrite_classes(self, bugs, classes, probabilities):\n        for i, bug in enumerate(bugs):\n            if \"cf_has_str\" in bug and bug[\"cf_has_str\"] == \"no\":\n                classes[i] = 0 if not probabilities else [1.0, 0.0]\n            elif \"cf_has_str\" in bug and bug[\"cf_has_str\"] == \"yes\":\n                classes[i] = 1 if not probabilities else [0.0, 1.0]\n            elif \"stepswanted\" in bug[\"keywords\"]:\n                classes[i] = 0 if not probabilities else [1.0, 0.0]\n\n        return classes\n\n    def get_feature_names(self):\n        return self.clf.named_steps[\"union\"].get_feature_names_out()\n", "path": "bugbug/models/stepstoreproduce.py"}]}