jekalmin / extended_openai_conversation

Home Assistant custom component of conversation agent. It uses OpenAI to control your devices.
829 stars 108 forks source link

DateTime format is invalid while creating automation #232

Open storm1er opened 1 week ago

storm1er commented 1 week ago

I'm getting this error when asking for a dummy "light up X light in 30min":

Expected HH:MM, HH:MM:SS or Entity ID with domain ‘input_datetime’ or ‘sensor’ @ data[‘at’][0].

Complete trace:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/assist_pipeline/pipeline.py", line 993, in recognize_intent conversation_result = await conversation.async_converse( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/conversation/__init__.py", line 544, in async_converse result = await agent.async_process( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/__init__.py", line 196, in async_process query_response = await self.query(user_input, messages, exposed_entities, 0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/__init__.py", line 384, in query return await self.execute_tool_calls( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/__init__.py", line 461, in execute_tool_calls result = await self.execute_tool_function( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/__init__.py", line 494, in execute_tool_function result = await function_executor.execute( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/helpers.py", line 211, in execute return await self.add_automation( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/extended_openai_conversation/helpers.py", line 299, in add_automation await _async_validate_config_item(hass, config, True, False) File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 177, in _async_validate_config_item automation_config[CONF_TRIGGER] = await async_validate_trigger_config( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/trigger.py", line 242, in async_validate_trigger_config conf = await platform.async_validate_trigger_config(hass, conf) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/homeassistant/trigger.py", line 34, in async_validate_trigger_config return platform.TRIGGER_SCHEMA(config) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__ return self._compiled([], data) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict return base_validate(path, iteritems(data), out) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 433, in validate_mapping raise er.MultipleInvalid(errors) voluptuous.error.MultipleInvalid: Expected HH:MM, HH:MM:SS or Entity ID with domain 'input_datetime' or 'sensor' @ data['at'][0]

By looking at this I understand the created automation is wrong.

Using the logger I got this:

Raw:

``` {'id': 'chatcmpl-REDACTED', 'choices': [{'finish_reason': 'tool_calls', 'index': 0, 'message': {'role': 'assistant', 'tool_calls': [{'id': 'call_REDACTED', 'function': {'arguments': '{"automation_config":"alias: Allumer la chambre de Mina dans 30 minutes\\ntrigger:\\n - platform: time\\n at: \'2024-06-18T16:21:20+02:00\'\\naction:\\n - service: light.turn_on\\n target:\\n entity_id: light.chambre_mina\\nmode: single\\n"}', 'name': 'add_automation'}, 'type': 'function'}]}}], 'created': 1718718680, 'model': 'gpt-4o-2024-05-13', 'object': 'chat.completion', 'system_fingerprint': 'fp_REDACTED', 'usage': {'completion_tokens': 88, 'prompt_tokens': 989, 'total_tokens': 1077}} ```

Formated

``` { 'id': 'chatcmpl-REDACTED', 'choices': [{ 'finish_reason': 'tool_calls', 'index': 0, 'message': { 'role': 'assistant', 'tool_calls': [{ 'id': 'call_REDACTED', 'function': { 'arguments': '{ "automation_config":" alias: Allumer la chambre de Mina dans 30 minutes trigger: - platform: time at: \'2024-06-18T16:21:20+02:00\' action: - service: light.turn_on target: entity_id: light.chambre_mina mode: single "}', 'name': 'add_automation' }, 'type': 'function' }] } }], 'created': 1718718680, 'model': 'gpt-4o-2024-05-13', 'object': 'chat.completion', 'system_fingerprint': 'REDACTED', 'usage': { 'completion_tokens': 88, 'prompt_tokens': 989, 'total_tokens': 1077 } } ```
storm1er commented 1 week ago

A good yaml would be

 alias: Allumer la chambre de Mina dans 30 minutes
 trigger:
   - platform: time
-    at: '2024-06-18T16:21:20+02:00'
+    at: '16:21:20'
 action:
   - service: light.turn_on
     target:
       entity_id: light.chambre_mina
 mode: single