feat: add model field to setup form; use it for validation ping and as default in conversation setup
This commit is contained in:
1 parent
3dd1c88df9
commit
cfb53c25f6
1 file changed
+5
-2
@@ -78,6 +78,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
vol.Required(CONF_API_KEY): str,
|
vol.Required(CONF_API_KEY): str,
|
||||||
vol.Optional(CONF_BASE_URL): str,
|
vol.Optional(CONF_BASE_URL): str,
|
||||||
|
vol.Optional(CONF_CHAT_MODEL, default="claude-3-haiku-20240307"): str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
|
|||||||
if exc.status_code == 404:
|
if exc.status_code == 404:
|
||||||
# Proxy does not support models endpoint — validate via a tiny messages call
|
# Proxy does not support models endpoint — validate via a tiny messages call
|
||||||
await client.messages.create(
|
await client.messages.create(
|
||||||
model="claude-3-haiku-20240307",
|
model=data.get(CONF_CHAT_MODEL) or "claude-3-haiku-20240307",
|
||||||
max_tokens=1,
|
max_tokens=1,
|
||||||
messages=[{"role": "user", "content": "hi"}],
|
messages=[{"role": "user", "content": "hi"}],
|
||||||
timeout=10.0,
|
timeout=10.0,
|
||||||
@@ -373,10 +374,12 @@ class ConversationSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
"""Manage advanced options."""
|
"""Manage advanced options."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
|
# Use model stored in parent entry as default (set during setup)
|
||||||
|
entry_default_model = self._get_entry().data.get(CONF_CHAT_MODEL, DEFAULT[CONF_CHAT_MODEL])
|
||||||
step_schema: VolDictType = {
|
step_schema: VolDictType = {
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_CHAT_MODEL,
|
CONF_CHAT_MODEL,
|
||||||
default=DEFAULT[CONF_CHAT_MODEL],
|
default=entry_default_model,
|
||||||
): SelectSelector(
|
): SelectSelector(
|
||||||
SelectSelectorConfig(
|
SelectSelectorConfig(
|
||||||
options=await self._get_model_list(), custom_value=True
|
options=await self._get_model_list(), custom_value=True
|
||||||
|
|||||||
Reference in new issue
Block a user