mirror of
https://github.com/acon96/home-llm.git
synced 2026-01-09 13:48:05 -05:00
Merge pull request #307 from loopy321/develop
Fix slice/Type error by enforcing integer in config_flow.py
This commit is contained in:
@@ -157,6 +157,11 @@ from . import HomeLLMAPI, LocalLLMConfigEntry, LocalLLMClient, BACKEND_TO_CLS
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def _coerce_int(val, default=0):
|
||||
try:
|
||||
return int(val)
|
||||
except (TypeError, ValueError):
|
||||
return default
|
||||
|
||||
def pick_backend_schema(backend_type=None, selected_language=None):
|
||||
return vol.Schema(
|
||||
@@ -1164,6 +1169,17 @@ class LocalLLMSubentryFlowHandler(ConfigSubentryFlow):
|
||||
if user_input[CONF_LLM_HASS_API] == "none":
|
||||
user_input.pop(CONF_LLM_HASS_API)
|
||||
|
||||
# --- Normalize numeric fields to ints to avoid slice/type errors later ---
|
||||
for key in (
|
||||
CONF_REMEMBER_NUM_INTERACTIONS,
|
||||
CONF_MAX_TOOL_CALL_ITERATIONS,
|
||||
CONF_CONTEXT_LENGTH,
|
||||
CONF_MAX_TOKENS,
|
||||
CONF_REQUEST_TIMEOUT,
|
||||
):
|
||||
if key in user_input:
|
||||
user_input[key] = _coerce_int(user_input[key], user_input.get(key) or 0)
|
||||
|
||||
if len(errors) == 0:
|
||||
try:
|
||||
# validate input
|
||||
@@ -1218,4 +1234,4 @@ class LocalLLMSubentryFlowHandler(ConfigSubentryFlow):
|
||||
if not self.model_config:
|
||||
self.model_config = dict(self._get_reconfigure_subentry().data)
|
||||
|
||||
return await self.async_step_model_parameters(user_input)
|
||||
return await self.async_step_model_parameters(user_input)
|
||||
|
||||
Reference in New Issue
Block a user