23
23
CONF_AWS_SECRET_ACCESS_KEY ,
24
24
CONF_AWS_REGION_NAME ,
25
25
CONF_AWS_DEFAULT_MODEL ,
26
+ CONF_OPENWEBUI_IP_ADDRESS ,
27
+ CONF_OPENWEBUI_PORT ,
28
+ CONF_OPENWEBUI_HTTPS ,
29
+ CONF_OPENWEBUI_API_KEY ,
30
+ CONF_OPENWEBUI_DEFAULT_MODEL ,
26
31
MESSAGE ,
27
32
REMEMBER ,
28
33
MODEL ,
@@ -81,12 +86,18 @@ async def async_setup_entry(hass, entry):
81
86
ollama_https = entry .data .get (CONF_OLLAMA_HTTPS )
82
87
custom_openai_endpoint = entry .data .get (CONF_CUSTOM_OPENAI_ENDPOINT )
83
88
custom_openai_api_key = entry .data .get (CONF_CUSTOM_OPENAI_API_KEY )
84
- custom_openai_default_model = entry .data .get (CONF_CUSTOM_OPENAI_DEFAULT_MODEL )
89
+ custom_openai_default_model = entry .data .get (
90
+ CONF_CUSTOM_OPENAI_DEFAULT_MODEL )
85
91
retention_time = entry .data .get (CONF_RETENTION_TIME )
86
92
aws_access_key_id = entry .data .get (CONF_AWS_ACCESS_KEY_ID )
87
93
aws_secret_access_key = entry .data .get (CONF_AWS_SECRET_ACCESS_KEY )
88
94
aws_region_name = entry .data .get (CONF_AWS_REGION_NAME )
89
95
aws_default_model = entry .data .get (CONF_AWS_DEFAULT_MODEL )
96
+ openwebui_ip_address = entry .data .get (CONF_OPENWEBUI_IP_ADDRESS )
97
+ openwebui_port = entry .data .get (CONF_OPENWEBUI_PORT )
98
+ openwebui_https = entry .data .get (CONF_OPENWEBUI_HTTPS )
99
+ openwebui_api_key = entry .data .get (CONF_OPENWEBUI_API_KEY )
100
+ openwebui_default_model = entry .data .get (CONF_OPENWEBUI_DEFAULT_MODEL )
90
101
91
102
# Ensure DOMAIN exists in hass.data
92
103
if DOMAIN not in hass .data :
@@ -116,6 +127,11 @@ async def async_setup_entry(hass, entry):
116
127
CONF_AWS_SECRET_ACCESS_KEY : aws_secret_access_key ,
117
128
CONF_AWS_REGION_NAME : aws_region_name ,
118
129
CONF_AWS_DEFAULT_MODEL : aws_default_model ,
130
+ CONF_OPENWEBUI_IP_ADDRESS : openwebui_ip_address ,
131
+ CONF_OPENWEBUI_PORT : openwebui_port ,
132
+ CONF_OPENWEBUI_HTTPS : openwebui_https ,
133
+ CONF_OPENWEBUI_API_KEY : openwebui_api_key ,
134
+ CONF_OPENWEBUI_DEFAULT_MODEL : openwebui_default_model
119
135
}
120
136
121
137
# Filter out None values
@@ -170,7 +186,7 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
170
186
return False
171
187
172
188
173
- async def _remember (hass , call , start , response ) -> None :
189
+ async def _remember (hass , call , start , response , key_frame ) -> None :
174
190
if call .remember :
175
191
# Find semantic index config
176
192
config_entry = None
@@ -186,37 +202,27 @@ async def _remember(hass, call, start, response) -> None:
186
202
187
203
semantic_index = SemanticIndex (hass , config_entry )
188
204
189
- if "title" in response :
190
- title = response .get ("title" , "Unknown object seen" )
191
- if call .image_entities and len (call .image_entities ) > 0 :
192
- camera_name = call .image_entities [0 ]
193
- elif call .video_paths and len (call .video_paths ) > 0 :
194
- camera_name = call .video_paths [0 ].split (
195
- "/" )[- 1 ].replace (".mp4" , "" )
196
- else :
197
- camera_name = "File Input"
198
-
199
- if "title" not in response :
200
- if call .image_entities and len (call .image_entities ) > 0 :
201
- camera_name = call .image_entities [0 ]
202
- title = "Motion detected near " + camera_name
203
- elif call .video_paths and len (call .video_paths ) > 0 :
204
- camera_name = call .video_paths [0 ].split (
205
- "/" )[- 1 ].replace (".mp4" , "" )
206
- title = "Motion detected in " + camera_name
207
- else :
208
- camera_name = "File Input"
209
- title = "Motion detected"
205
+ if call .image_entities and len (call .image_entities ) > 0 :
206
+ camera_name = call .image_entities [0 ]
207
+ title = "Motion detected near " + camera_name
208
+ elif call .video_paths and len (call .video_paths ) > 0 :
209
+ camera_name = call .video_paths [0 ].split (
210
+ "/" )[- 1 ].replace (".mp4" , "" )
211
+ title = "Motion detected in " + camera_name
212
+ else :
213
+ camera_name = ""
214
+ title = "Motion detected"
210
215
211
- if "response_text" not in response :
212
- raise ValueError ( "response_text is missing in the response" )
216
+ if "title" in response :
217
+ title = response . get ( "title " )
213
218
214
219
await semantic_index .remember (
215
220
start = start ,
216
221
end = dt_util .now () + timedelta (minutes = 1 ),
217
222
label = title ,
218
- camera_name = camera_name ,
219
- summary = response ["response_text" ]
223
+ summary = response ["response_text" ],
224
+ key_frame = key_frame ,
225
+ camera_name = camera_name
220
226
)
221
227
222
228
@@ -337,12 +343,17 @@ async def image_analyzer(data_call):
337
343
image_paths = call .image_paths ,
338
344
target_width = call .target_width ,
339
345
include_filename = call .include_filename ,
340
- expose_images = call .expose_images
346
+ expose_images = call .expose_images ,
347
+ expose_images_persist = call .expose_images_persist
341
348
)
342
349
343
350
# Validate configuration, input data and make the call
344
351
response = await request .call (call )
345
- await _remember (hass , call , start , response )
352
+ await _remember (hass = hass ,
353
+ call = call ,
354
+ start = start ,
355
+ response = response ,
356
+ key_frame = processor .key_frame )
346
357
return response
347
358
348
359
async def video_analyzer (data_call ):
@@ -368,7 +379,11 @@ async def video_analyzer(data_call):
368
379
frigate_retry_seconds = call .frigate_retry_seconds
369
380
)
370
381
response = await request .call (call )
371
- await _remember (hass , call , start , response )
382
+ await _remember (hass = hass ,
383
+ call = call ,
384
+ start = start ,
385
+ response = response ,
386
+ key_frame = processor .key_frame )
372
387
return response
373
388
374
389
async def stream_analyzer (data_call ):
@@ -382,16 +397,22 @@ async def stream_analyzer(data_call):
382
397
temperature = call .temperature ,
383
398
)
384
399
processor = MediaProcessor (hass , request )
400
+
385
401
request = await processor .add_streams (image_entities = call .image_entities ,
386
402
duration = call .duration ,
387
403
max_frames = call .max_frames ,
388
404
target_width = call .target_width ,
389
405
include_filename = call .include_filename ,
390
- expose_images = call .expose_images
406
+ expose_images = call .expose_images ,
407
+ expose_images_persist = call .expose_images_persist
391
408
)
392
409
393
410
response = await request .call (call )
394
- await _remember (hass , call , start , response )
411
+ await _remember (hass = hass ,
412
+ call = call ,
413
+ start = start ,
414
+ response = response ,
415
+ key_frame = processor .key_frame )
395
416
return response
396
417
397
418
async def data_analyzer (data_call ):
0 commit comments