Skip to content

Commit

Permalink
Handle model_provider_id not associating with model
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-i committed Nov 9, 2023
1 parent a40a2b6 commit feb191c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/jupyter-ai/jupyter_ai/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class BlockedModelError(Exception):
pass


class ConfigValidationError(Exception):
def __init__(self, property_name, message):
self.property_name = property_name
super().__init__(message)


def _validate_provider_authn(config: GlobalConfig, provider: AnyProvider):
# TODO: handle non-env auth strategies
if not provider.auth_strategy or provider.auth_strategy.type != "env":
Expand Down Expand Up @@ -171,7 +177,14 @@ def _init_config(self):

# re-write to the file to validate the config and apply any
# updates to the config file immediately
self._write_config(config)
try:
self._write_config(config)
except ConfigValidationError as e:
if e.property_name == "model_provider_id":
self.log.warning(f"{str(e)} Setting to None")
config.model_provider_id = None
self._write_config(config)

return

properties = self.validator.schema.get("properties", {})
Expand Down Expand Up @@ -213,8 +226,9 @@ def _validate_config(self, config: GlobalConfig):

# verify model is declared by some provider
if not lm_provider:
raise ValueError(
f"No language model is associated with '{config.model_provider_id}'."
raise ConfigValidationError(
"model_provider_id",
f"No language model is associated with '{config.model_provider_id}'.",
)

# verify model is not blocked
Expand Down

0 comments on commit feb191c

Please sign in to comment.