Skip to content

Commit

Permalink
Format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmitsch committed Jul 13, 2023
1 parent 97fa11f commit 564c2b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 14 additions & 6 deletions spacy/cli/init_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,38 @@ def init_config(
raise ValueError(Errors.E1055) from ex

if llm_model is None:
raise ValueError("Option `llm.model` must be set if `llm` component is in pipeline.")
raise ValueError(
"Option `llm.model` must be set if `llm` component is in pipeline."
)
if llm_task is None:
raise ValueError("Option `llm.task` must be set if `llm` component is in pipeline.")
raise ValueError(
"Option `llm.task` must be set if `llm` component is in pipeline."
)

# Select registry handles for model(s) and task(s). Raise if no match found.
llm_spec = {
spec_type: {
"arg": llm_model if spec_type == "model" else llm_task,
"matched_reg_handle": None,
"reg_handles": getattr(registry, f"llm_{spec_type}s").get_all()
"reg_handles": getattr(registry, f"llm_{spec_type}s").get_all(),
}
for spec_type in ("model", "task")
}

for spec_type, spec in llm_spec.items():
for reg_handle in spec["reg_handles"]:
if reg_handle.split(".")[1].lower() == spec["arg"].lower().replace(".", "-"):
if reg_handle.split(".")[1].lower() == spec["arg"].lower().replace(
".", "-"
):
spec["matched_reg_handle"] = reg_handle
break

if not spec["matched_reg_handle"]:
arg = spec["arg"]
raise ValueError(f"Couldn't find a matching registration handle for {spec_type} '{spec}'. Double-check"
f" whether '{arg}' is spelled correctly.")
raise ValueError(
f"Couldn't find a matching registration handle for {spec_type} '{spec}'. Double-check"
f" whether '{arg}' is spelled correctly."
)

defaults = RECOMMENDATIONS["__default__"]
reco = RecommendationSchema(**RECOMMENDATIONS.get(lang, defaults)).dict()
Expand Down
2 changes: 0 additions & 2 deletions spacy/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,6 @@ def test_init_config_llm(pipeline, llm_model, llm_task):
load_model_from_config(config, auto_fill=True)




def test_model_recommendations():
for lang, data in RECOMMENDATIONS.items():
assert RecommendationSchema(**data)
Expand Down

0 comments on commit 564c2b0

Please sign in to comment.