mirror of
https://github.com/acon96/home-llm.git
synced 2026-01-10 14:18:00 -05:00
enforce gbnf/icl file exists when creating model
This commit is contained in:
@@ -636,18 +636,34 @@ class ConfigFlow(BaseLlamaConversationConfigFlow, config_entries.ConfigFlow, dom
|
||||
schema = vol.Schema(local_llama_config_option_schema(self.hass, selected_default_options, backend_type))
|
||||
|
||||
if user_input:
|
||||
if not user_input.get(CONF_REFRESH_SYSTEM_PROMPT) and user_input.get(CONF_PROMPT_CACHING_ENABLED):
|
||||
errors["base"] = "sys_refresh_caching_enabled"
|
||||
|
||||
if user_input.get(CONF_USE_GBNF_GRAMMAR):
|
||||
filename = user_input.get(CONF_GBNF_GRAMMAR_FILE, DEFAULT_GBNF_GRAMMAR_FILE)
|
||||
if not os.path.isfile(os.path.join(os.path.dirname(__file__), filename)):
|
||||
errors["base"] = "missing_gbnf_file"
|
||||
description_placeholders["filename"] = filename
|
||||
|
||||
if user_input.get(CONF_USE_IN_CONTEXT_LEARNING_EXAMPLES):
|
||||
filename = user_input.get(CONF_IN_CONTEXT_EXAMPLES_FILE, DEFAULT_IN_CONTEXT_EXAMPLES_FILE)
|
||||
if not os.path.isfile(os.path.join(os.path.dirname(__file__), filename)):
|
||||
errors["base"] = "missing_icl_file"
|
||||
description_placeholders["filename"] = filename
|
||||
|
||||
if user_input[CONF_LLM_HASS_API] == "none":
|
||||
user_input.pop(CONF_LLM_HASS_API)
|
||||
|
||||
try:
|
||||
# validate input
|
||||
schema(user_input)
|
||||
if len(errors) == 0:
|
||||
try:
|
||||
# validate input
|
||||
schema(user_input)
|
||||
|
||||
self.options = user_input
|
||||
return await self.async_step_finish()
|
||||
except Exception as ex:
|
||||
_LOGGER.exception("An unknown error has occurred!")
|
||||
errors["base"] = "unknown"
|
||||
self.options = user_input
|
||||
return await self.async_step_finish()
|
||||
except Exception as ex:
|
||||
_LOGGER.exception("An unknown error has occurred!")
|
||||
errors["base"] = "unknown"
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="model_parameters", data_schema=schema, errors=errors, description_placeholders=description_placeholders,
|
||||
|
||||
Reference in New Issue
Block a user