33# Declare variables
44from .const import (
55 DOMAIN ,
6- CONF_OPENAI_API_KEY ,
7- CONF_AZURE_API_KEY ,
6+ CONF_PROVIDER ,
7+ CONF_API_KEY ,
8+ CONF_IP_ADDRESS ,
9+ CONF_PORT ,
10+ CONF_HTTPS ,
11+ CONF_DEFAULT_MODEL ,
12+ CONF_TEMPERATURE ,
13+ CONF_DEFAULT_TOP_P ,
814 CONF_AZURE_VERSION ,
915 CONF_AZURE_BASE_URL ,
1016 CONF_AZURE_DEPLOYMENT ,
11- CONF_ANTHROPIC_API_KEY ,
12- CONF_GOOGLE_API_KEY ,
13- CONF_GROQ_API_KEY ,
14- CONF_LOCALAI_IP_ADDRESS ,
15- CONF_LOCALAI_PORT ,
16- CONF_LOCALAI_HTTPS ,
17- CONF_OLLAMA_IP_ADDRESS ,
18- CONF_OLLAMA_PORT ,
19- CONF_OLLAMA_HTTPS ,
2017 CONF_CUSTOM_OPENAI_ENDPOINT ,
21- CONF_CUSTOM_OPENAI_API_KEY ,
22- CONF_CUSTOM_OPENAI_DEFAULT_MODEL ,
2318 CONF_RETENTION_TIME ,
2419 CONF_MEMORY_PATHS ,
2520 CONG_MEMORY_IMAGES_ENCODED ,
2924 CONF_AWS_ACCESS_KEY_ID ,
3025 CONF_AWS_SECRET_ACCESS_KEY ,
3126 CONF_AWS_REGION_NAME ,
32- CONF_AWS_DEFAULT_MODEL ,
33- CONF_OPENWEBUI_IP_ADDRESS ,
34- CONF_OPENWEBUI_PORT ,
35- CONF_OPENWEBUI_HTTPS ,
36- CONF_OPENWEBUI_API_KEY ,
37- CONF_OPENWEBUI_DEFAULT_MODEL ,
3827 MESSAGE ,
3928 REMEMBER ,
4029 USE_MEMORY ,
5140 INTERVAL ,
5241 DURATION ,
5342 MAX_FRAMES ,
54- TEMPERATURE ,
5543 INCLUDE_FILENAME ,
5644 EXPOSE_IMAGES ,
5745 GENERATE_TITLE ,
@@ -79,79 +67,65 @@ async def async_setup_entry(hass, entry):
7967 # Use the entry_id from the config entry as the UID
8068 entry_uid = entry .entry_id
8169
82- # Get all entries from config flow
83- openai_api_key = entry .data .get (CONF_OPENAI_API_KEY )
84- azure_api_key = entry .data .get (CONF_AZURE_API_KEY )
70+ provider = entry .data .get (CONF_PROVIDER )
71+ api_key = entry .data .get (CONF_API_KEY )
72+ ip_address = entry .data .get (CONF_IP_ADDRESS )
73+ port = entry .data .get (CONF_PORT )
74+ https = entry .data .get (CONF_HTTPS )
75+ default_model = entry .data .get (CONF_DEFAULT_MODEL )
76+ default_temperature = entry .data .get (CONF_TEMPERATURE )
77+ default_top_p = entry .data .get (CONF_DEFAULT_TOP_P )
78+
79+ # Azure specific
8580 azure_base_url = entry .data .get (CONF_AZURE_BASE_URL )
8681 azure_deployment = entry .data .get (CONF_AZURE_DEPLOYMENT )
8782 azure_version = entry .data .get (CONF_AZURE_VERSION )
88- anthropic_api_key = entry .data .get (CONF_ANTHROPIC_API_KEY )
89- google_api_key = entry .data .get (CONF_GOOGLE_API_KEY )
90- groq_api_key = entry .data .get (CONF_GROQ_API_KEY )
91- localai_ip_address = entry .data .get (CONF_LOCALAI_IP_ADDRESS )
92- localai_port = entry .data .get (CONF_LOCALAI_PORT )
93- localai_https = entry .data .get (CONF_LOCALAI_HTTPS )
94- ollama_ip_address = entry .data .get (CONF_OLLAMA_IP_ADDRESS )
95- ollama_port = entry .data .get (CONF_OLLAMA_PORT )
96- ollama_https = entry .data .get (CONF_OLLAMA_HTTPS )
83+
84+ # Custom OpenAI specific
9785 custom_openai_endpoint = entry .data .get (CONF_CUSTOM_OPENAI_ENDPOINT )
98- custom_openai_api_key = entry .data .get (CONF_CUSTOM_OPENAI_API_KEY )
99- custom_openai_default_model = entry .data .get (
100- CONF_CUSTOM_OPENAI_DEFAULT_MODEL )
86+
87+ # AWS specific
88+ aws_access_key_id = entry .data .get (CONF_AWS_ACCESS_KEY_ID )
89+ aws_secret_access_key = entry .data .get (CONF_AWS_SECRET_ACCESS_KEY )
90+ aws_region_name = entry .data .get (CONF_AWS_REGION_NAME )
91+
92+ # Timeline
10193 retention_time = entry .data .get (CONF_RETENTION_TIME )
94+
95+ # Memory
10296 memory_paths = entry .data .get (CONF_MEMORY_PATHS )
10397 memory_images_encoded = entry .data .get (CONG_MEMORY_IMAGES_ENCODED )
10498 memory_strings = entry .data .get (CONF_MEMORY_STRINGS )
10599 system_prompt = entry .data .get (CONF_SYSTEM_PROMPT )
106100 title_prompt = entry .data .get (CONF_TITLE_PROMPT )
107- aws_access_key_id = entry .data .get (CONF_AWS_ACCESS_KEY_ID )
108- aws_secret_access_key = entry .data .get (CONF_AWS_SECRET_ACCESS_KEY )
109- aws_region_name = entry .data .get (CONF_AWS_REGION_NAME )
110- aws_default_model = entry .data .get (CONF_AWS_DEFAULT_MODEL )
111- openwebui_ip_address = entry .data .get (CONF_OPENWEBUI_IP_ADDRESS )
112- openwebui_port = entry .data .get (CONF_OPENWEBUI_PORT )
113- openwebui_https = entry .data .get (CONF_OPENWEBUI_HTTPS )
114- openwebui_api_key = entry .data .get (CONF_OPENWEBUI_API_KEY )
115- openwebui_default_model = entry .data .get (CONF_OPENWEBUI_DEFAULT_MODEL )
116101
117102 # Ensure DOMAIN exists in hass.data
118103 if DOMAIN not in hass .data :
119104 hass .data [DOMAIN ] = {}
120105
121106 # Create a dictionary for the entry data
122107 entry_data = {
123- CONF_OPENAI_API_KEY : openai_api_key ,
124- CONF_AZURE_API_KEY : azure_api_key ,
108+ CONF_PROVIDER : provider ,
109+ CONF_API_KEY : api_key ,
110+ CONF_IP_ADDRESS : ip_address ,
111+ CONF_PORT : port ,
112+ CONF_HTTPS : https ,
113+ CONF_DEFAULT_MODEL : default_model ,
114+ CONF_TEMPERATURE : default_temperature ,
115+ CONF_DEFAULT_TOP_P : default_top_p ,
125116 CONF_AZURE_BASE_URL : azure_base_url ,
126117 CONF_AZURE_DEPLOYMENT : azure_deployment ,
127118 CONF_AZURE_VERSION : azure_version ,
128- CONF_ANTHROPIC_API_KEY : anthropic_api_key ,
129- CONF_GOOGLE_API_KEY : google_api_key ,
130- CONF_GROQ_API_KEY : groq_api_key ,
131- CONF_LOCALAI_IP_ADDRESS : localai_ip_address ,
132- CONF_LOCALAI_PORT : localai_port ,
133- CONF_LOCALAI_HTTPS : localai_https ,
134- CONF_OLLAMA_IP_ADDRESS : ollama_ip_address ,
135- CONF_OLLAMA_PORT : ollama_port ,
136- CONF_OLLAMA_HTTPS : ollama_https ,
137119 CONF_CUSTOM_OPENAI_ENDPOINT : custom_openai_endpoint ,
138- CONF_CUSTOM_OPENAI_API_KEY : custom_openai_api_key ,
139- CONF_CUSTOM_OPENAI_DEFAULT_MODEL : custom_openai_default_model ,
120+ CONF_AWS_ACCESS_KEY_ID : aws_access_key_id ,
121+ CONF_AWS_SECRET_ACCESS_KEY : aws_secret_access_key ,
122+ CONF_AWS_REGION_NAME : aws_region_name ,
140123 CONF_RETENTION_TIME : retention_time ,
141124 CONF_MEMORY_PATHS : memory_paths ,
142125 CONG_MEMORY_IMAGES_ENCODED : memory_images_encoded ,
143126 CONF_MEMORY_STRINGS : memory_strings ,
144127 CONF_SYSTEM_PROMPT : system_prompt ,
145128 CONF_TITLE_PROMPT : title_prompt ,
146- CONF_AWS_ACCESS_KEY_ID : aws_access_key_id ,
147- CONF_AWS_SECRET_ACCESS_KEY : aws_secret_access_key ,
148- CONF_AWS_REGION_NAME : aws_region_name ,
149- CONF_AWS_DEFAULT_MODEL : aws_default_model ,
150- CONF_OPENWEBUI_IP_ADDRESS : openwebui_ip_address ,
151- CONF_OPENWEBUI_PORT : openwebui_port ,
152- CONF_OPENWEBUI_HTTPS : openwebui_https ,
153- CONF_OPENWEBUI_API_KEY : openwebui_api_key ,
154- CONF_OPENWEBUI_DEFAULT_MODEL : openwebui_default_model
155129 }
156130
157131 # Filter out None values
@@ -210,8 +184,6 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
210184 _LOGGER .debug (
211185 f"{ config_entry .title } version: { config_entry .version } .{ config_entry .minor_version } " )
212186 if config_entry .version == 2 and config_entry .data ["provider" ] == "Event Calendar" :
213- _LOGGER .info (
214- "Migrating LLM Vision Timeline config entry from v2.0 to v3.0" )
215187 # Change Provider name to Timeline
216188 new_data = config_entry .data .copy ()
217189 new_data ["provider" ] = "Timeline"
@@ -221,9 +193,19 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry) -> bool:
221193 config_entry , title = "LLM Vision Timeline" , data = new_data , version = 3 , minor_version = 0
222194 )
223195 return True
196+ if config_entry .version == 3 :
197+ new_data = config_entry .data .copy ()
198+
199+ if config_entry .data .get (PROVIDER ) is "OpenAI" :
200+ new_data [CONF_API_KEY ] = new_data .pop ("openai_api_key" )
201+ new_data [CONF_DEFAULT_MODEL ] = DEFAULT_MODEL_OPENAI
202+ new_data [CONF_TEMPERATURE ] = DEFAULT_TEMPERATURE_OPENAI
203+ new_data [CONF_DEFAULT_TOP_P ] = DEFAULT_TOP_P_OPENAI
204+
205+
224206 else :
225207 hass .config_entries .async_update_entry (
226- config_entry , version = 3 , minor_version = 0
208+ config_entry , version = 4 , minor_version = 0
227209 )
228210 return True
229211
@@ -328,8 +310,7 @@ class ServiceCallData:
328310
329311 def __init__ (self , data_call ):
330312 self .provider = str (data_call .data .get (PROVIDER ))
331- self .model = str (data_call .data .get (
332- MODEL ))
313+ self .model = data_call .data .get (MODEL )
333314 self .message = str (data_call .data .get (MESSAGE , "" )[0 :2000 ])
334315 self .remember = data_call .data .get (REMEMBER , False )
335316 self .use_memory = data_call .data .get (USE_MEMORY , False )
@@ -348,7 +329,7 @@ def __init__(self, data_call):
348329 data_call .data .get (FRIGATE_RETRY_SECONDS , 1 ))
349330 self .max_frames = int (data_call .data .get (MAX_FRAMES , 3 ))
350331 self .target_width = data_call .data .get (TARGET_WIDTH , 3840 )
351- self .temperature = float (data_call . data . get ( TEMPERATURE , 0.3 ) )
332+ self .temperature = float ()
352333 self .max_tokens = int (data_call .data .get (MAXTOKENS , 100 ))
353334 self .include_filename = data_call .data .get (INCLUDE_FILENAME , False )
354335 self .expose_images = data_call .data .get (EXPOSE_IMAGES , False )
0 commit comments