Skip to content

Commit 3a78e6d

Browse files
committed
fix: restore ai task image analysis config
1 parent 40bbb32 commit 3a78e6d

6 files changed

Lines changed: 32 additions & 8 deletions

File tree

custom_components/ai_hub/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
250250
# Create AI task subentry with defaults
251251
ai_task_data = {
252252
CONF_RECOMMENDED: True,
253+
CONF_CHAT_URL: AI_HUB_CHAT_URL,
253254
CONF_CHAT_MODEL: RECOMMENDED_AI_TASK_MODEL,
254255
CONF_TEMPERATURE: RECOMMENDED_AI_TASK_TEMPERATURE,
255256
CONF_TOP_P: RECOMMENDED_AI_TASK_TOP_P,

custom_components/ai_hub/ai_task.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1515

1616
from .consts import (
17+
AI_HUB_CHAT_URL,
1718
AI_HUB_IMAGE_GEN_URL,
1819
CONF_CHAT_MODEL,
20+
CONF_CHAT_URL,
1921
CONF_IMAGE_MODEL,
2022
CONF_IMAGE_URL,
2123
ERROR_GETTING_RESPONSE,
@@ -47,6 +49,16 @@ def _get_conversation_model(config_entry: ConfigEntry) -> str:
4749
return RECOMMENDED_CHAT_MODEL
4850

4951

52+
def _get_conversation_chat_url(config_entry: ConfigEntry) -> str:
53+
"""Get the chat URL from Conversation Agent subentry."""
54+
for subentry in config_entry.subentries.values():
55+
if subentry.subentry_type == SUBENTRY_CONVERSATION:
56+
chat_url = subentry.data.get(CONF_CHAT_URL, AI_HUB_CHAT_URL)
57+
if isinstance(chat_url, str) and chat_url.strip():
58+
return chat_url
59+
return AI_HUB_CHAT_URL
60+
61+
5062
async def async_setup_entry(
5163
hass: HomeAssistant,
5264
config_entry: ConfigEntry,
@@ -100,6 +112,15 @@ def __init__(
100112
):
101113
self._attr_supported_features |= ai_task.AITaskEntityFeature.GENERATE_IMAGE
102114

115+
def _get_model_config(self, chat_log: conversation.ChatLog | None = None) -> dict[str, Any]:
116+
"""AI Task follows Conversation model and chat URL settings."""
117+
model_config = super()._get_model_config(chat_log)
118+
chat_url = self.subentry.data.get(CONF_CHAT_URL)
119+
if not isinstance(chat_url, str) or not chat_url.strip():
120+
chat_url = _get_conversation_chat_url(self.entry)
121+
model_config[CONF_CHAT_URL] = chat_url
122+
return model_config
123+
103124
async def _async_generate_data(
104125
self,
105126
task: ai_task.GenDataTask,

custom_components/ai_hub/consts/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129

130130
RECOMMENDED_AI_TASK_OPTIONS: Final = {
131131
CONF_RECOMMENDED: True,
132+
CONF_CHAT_URL: AI_HUB_CHAT_URL,
133+
CONF_CHAT_MODEL: RECOMMENDED_AI_TASK_MODEL,
132134
CONF_IMAGE_MODEL: RECOMMENDED_IMAGE_MODEL,
133135
CONF_IMAGE_URL: AI_HUB_IMAGE_GEN_URL,
134136
CONF_TEMPERATURE: RECOMMENDED_AI_TASK_TEMPERATURE,

custom_components/ai_hub/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ async def _async_handle_chat_log(
287287
part["text"] = str(part.get("text", ""))
288288
_LOGGER.warning("Message %d part %d had non-string text, converted", i, j)
289289

290-
api_url = options.get(CONF_CHAT_URL)
290+
api_url = model_config.get(CONF_CHAT_URL, options.get(CONF_CHAT_URL))
291291
if not isinstance(api_url, str) or not api_url.strip():
292292
raise HomeAssistantError(
293293
translation_domain=DOMAIN,

custom_components/ai_hub/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"iot_class": "cloud_polling",
1010
"issue_tracker": "https://github.com/ha-china/ai_hub/issues",
1111
"requirements": ["edge-tts==7.2.7", "aiofiles", "aiohttp"],
12-
"version": "v2026.04.10"
12+
"version": "v2026.04.11"
1313
}

custom_components/ai_hub/services.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ async def _handle_analyze_image(call: ServiceCall) -> dict:
226226
SUBENTRY_CONVERSATION,
227227
(CONF_CHAT_URL, AI_HUB_CHAT_URL),
228228
(CONF_CHAT_MODEL, RECOMMENDED_CHAT_MODEL),
229-
lambda config: (config[2], config[0]),
230-
handle_analyze_image,
229+
config_mapper=lambda config: (config[2], config[0]),
230+
handler=handle_analyze_image,
231231
)
232232

233233

@@ -237,8 +237,8 @@ async def _handle_generate_image(call: ServiceCall) -> dict:
237237
call,
238238
SUBENTRY_AI_TASK,
239239
(CONF_IMAGE_URL, AI_HUB_IMAGE_GEN_URL),
240-
lambda config: (config[1], config[0]),
241-
handle_generate_image,
240+
config_mapper=lambda config: (config[1], config[0]),
241+
handler=handle_generate_image,
242242
)
243243

244244

@@ -248,8 +248,8 @@ async def _handle_stt_transcribe(call: ServiceCall) -> dict:
248248
call,
249249
SUBENTRY_STT,
250250
(CONF_STT_URL, SILICONFLOW_ASR_URL),
251-
lambda config: (config[1], config[0]),
252-
handle_stt_transcribe,
251+
config_mapper=lambda config: (config[1], config[0]),
252+
handler=handle_stt_transcribe,
253253
)
254254

255255

0 commit comments

Comments
 (0)