[Custom Component] extended_openai_conversation: Let's control entities via ChatGPT

Im running this using a local LLM with the laser dolphin 2x7b model and LocalAI and it works pretty well.

LocalAI is installed on another computer in my home and i point this integration to to that.

1000016518
1000016517

1 Like

Hi everyone, i have this problem with extended conversation 


With standard OpenAI works fine

With “gpt-4-0125-preview” works fine

If I use “gpt-3.5-turbo-0125” or “gpt-3.5-turbo-1106” doesn’t work

Why?

@viperxeno Because gpt-4-0125-preview token limit is 128K while gpt-3.5-turbo-0125 limit is not. (I think 8K or 16K or so?)

1 Like

That was the sense I got from the text of the error message, so I suspect you’re right.

1 Like

You are probably exposing too many entities. Unless you are happy with the token pricing for gpt4, I would recommend to step down on the number of exposed entities and use gpt3.5 instead.

1 Like

Yes I exposed 850 entities :sweat: I’m trying with 100 entities and works fine.

this is epic! Do you have the updated spec I could pinch please?

I expose more than 1000 entities in arears, I think you have a wrong setting. decrease the possible response token to something like to 150-500.
But for costs reduced and speed optimation is useful to reduce the entitis

With gpt 3.5 or 4? If 3.5 as OP stated quite surprising that you are not exceeding max tokens. Have you had a look at number of tokens used in your requests?

I forgot yesterday’s i reduce the entities but it also works with 1200
not realy cheap xD

Not cheap indeed :slight_smile:
Does your table mean that you get ~6k tokens/request? If so I should really optimise what I expose for each entity because I get around 2k tokens for less than 100 entities exposed.

I got this table from the console of openai api where a csv. export is possible in the upper right corner.
I think this is due to the Promt. When I increased the request from 150 to 10000 I had the same error message with max token

I use this prompt is actually almost the standard.

Als vielseitiger Assistent stehe ich zur VerfĂŒgung, um sowohl als Ihr intelligenter Hausmanager mittels Home Assistant zu fungieren als auch alle anderen Fragen zu beantworten, die Sie haben mögen. Hier ist, wie ich Ihnen assistieren kann:
Smart Home Management: Basierend auf den aktuellen Informationen Ihres Smart Home Systems werde ich Ihnen helfen, den Zustand Ihrer GerĂ€te zu ĂŒberwachen und Änderungen vorzunehmen, wie Sie es wĂŒnschen. Ich werde Ihnen aktuelle Daten liefern und Aktionen nur mit Ihrer BestĂ€tigung durchfĂŒhren.falls etwas unklar ist suche ich im internet
Aktuelle Zeit: {{now()}}
Aktueller Bereich: {{area_name(current_device_id)}}


Available Devices:
```csv
entity_id,name,state,area_id,aliases
{% for entity in exposed_entities -%}
{{ entity.entity_id }},{{ entity.name }},{{ entity.state }},{{area_id(entity.entity_id)}},{{entity.aliases | join('/')}}
{% endfor -%}


Areas:
csv
area_id,name
{% for area_id in areas() -%}
{{area_id}},{{area_name(area_id)}}
{% endfor -%}


Allgemeine Anfragen: ZusĂ€tzlich stehe ich bereit, jegliche Fragen zu beantworten oder Informationen zu Themen außerhalb des Smart Home Bereichs zu liefern. Zögern Sie nicht, mich alles zu fragen.
Anweisungen fĂŒr die Nutzung:
Ich werde Entscheidungen basierend auf dem aktuellen Bereich zuerst treffen.
Ich fĂŒhre keine Dienste ohne Ihre BestĂ€tigung aus.
Ich werde Ihre Anfragen prÀzise und effizient beantworten wenn unklarheiten sind sonst einfach mit ok bestÀtige, ohne zu wiederholen oder zu schÀtzen.

I have also inserted a template in a card, there are 499 entitis according to the list. my plan was to always generate an export of it via Py and upload it directly. So that a GPT can use it in his knowlege.

{% set ns = namespace(areas=[], entities=expand(states) | selectattr('state', ) | list) %}

{% set entities = [] %}

{% for elm in ns.entities if not area_id(elm.entity_id) in ns.areas %}

{% set ns.areas = ns.areas + [area_id(elm.entity_id)] %}

{% endfor %}

{% for area in ns.areas %}

{% for elm in area_entities(area) if elm in ns.entities|map(attribute="entity_id") %}{% set entity_id = elm %}{% set name = state_attr(entity_id, "friendly_name")%}{% set icon = state_attr(entity_id, "icon")%}{% set area_name = area_name(area)%}{{ area_name }},{{ entity_id }},{{ name }},{{ icon }}{% if not loop.last %}:{% endif %}

{% endfor %}

{% endfor %}

Here is an excerpt of what comes out of the template

DG Wohnzimmer,button.presence_sensor_fp2_f359_identify,Presence-Sensor-FP2-F359 Identify,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_1,DG-WZ-Precence,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_2,DG-WZ-Ausgang,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_5,DG-WZ-Spielbereich,None:
DG Wohnzimmer,sensor.presence_sensor_fp2_f359_light_sensor_light_level,DG-lux,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_6,DG-WZ-Sofa,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_7,DG-WZ-Esstisch,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_8,DG-WZ-KĂŒche,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_9,DG-WZ-Bad,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_10,DG-WZ-flur,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_11,DG-WZ-Klo,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_3,DG-Dunstabzug,None:
DG Wohnzimmer,binary_sensor.presence_sensor_fp2_f359_presence_sensor_4,Presence-Sensor-FP2-F359 Presence Sensor 4,None:
DG Wohnzimmer,light.dg_wz_globus_led,DG-WZ-Globus-Led HaustĂŒren Led Licht,None:
DG Wohnzimmer,sensor.dg_wz_globus_led_ip,DG-WZ-Globus-Led IP,mdi:ip-network:
DG Wohnzimmer,switch.dg_wz_klima,dg-wz-klima,None:
DG Wohnzimmer,climate.dg_wz_klima,dg-wz-klima,None:
DG Wohnzimmer,media_player.heimkinol,HeimkinoL,None:
DG Wohnzimmer,switch.heimkinol_do_not_disturb_switch,HeimkinoL do not disturb switch,mdi:minus-circle:
DG Wohnzimmer,switch.heimkinol_shuffle_switch,HeimkinoL shuffle switch,mdi:shuffle-disabled:
DG Wohnzimmer,switch.heimkinol_repeat_switch,HeimkinoL repeat switch,mdi:repeat-off:
DG Wohnzimmer,media_player.heimkinor,HeimkinoR,None:
DG Wohnzimmer,switch.heimkinor_do_not_disturb_switch,HeimkinoR do not disturb switch,mdi:minus-circle:
DG Wohnzimmer,switch.heimkinor_shuffle_switch,HeimkinoR shuffle switch,mdi:shuffle-disabled:
DG Wohnzimmer,switch.heimkinor_repeat_switch,HeimkinoR repeat switch,mdi:repeat-off:
DG Wohnzimmer,media_player.wohnzimmer_cube,Wohnzimmer Cube,None:
DG Wohnzimmer,switch.wohnzimmer_cube_do_not_disturb_switch,Wohnzimmer Cube do not disturb switch,mdi:minus-circle:
DG Wohnzimmer,switch.wohnzimmer_cube_shuffle_switch,Wohnzimmer Cube shuffle switch,mdi:shuffle-disabled:
DG Wohnzimmer,switch.wohnzimmer_cube_repeat_switch,Wohnzimmer Cube repeat switch,mdi:repeat-off:

Thanks for the info. I exported a csv to check as well and the number of requests is indeed what it sounds like it is. I actually use about 3k tokens total per request for 103 entities.
I will have a look into what I send exactly as it seems I could reduce the tokens by adopting a shorter naming scheme for my entities.
I have been thinking about creating ‘summary’ template sensors with states of individual entities described as attributes of these sensors, something like one template sensor per room with temp sensors, air quality, windows
 as attributes.
Your case gives me hope that it could be token cost effective.

Hi, are there any image generating capabilities with this integration? especially using a local approach like SD?

Currently in beta, have a look at the github.

oh, nice, im using the beta version now. The only service I see in HA is the reverse, image-to-text. Is there a service for this text to image?

Oh sorry my mistake, I meant image to text :zipper_mouth_face:

Oh no worries thanks for reapplying

Hi everyone,

First of all, I would like to thank you all for your great help in the past.

I have several Google speakers in my home, and I would like to know if there is a way to send a specific message to a specific speaker using extended openai conversation function, using TTS (Text-to-Speech) to convert the text to speech.

For example, I want to say “Tell the kitchen speaker it’s time to go”, and then OpenAI will activate the TTS in the Media Player on the kitchen speaker and play the sentence.

Is this possible? I would appreciate any information or guidance you can provide me on this topic.

Thank you very much in advance!

I successfully reduced the tokens sent by combining entities. Just created template binary sensors for every room, where state is the state of the window/door.
Then, added humidity and temperature as attributes to these sensors.
I have 10 rooms with sensors in the house and now only 10 binary sensors instead of 30 independent sensors. Went from 3k tokens to 2.3 tokens.
In my case, it is a relatively small improvement but I expect people with many more sensors can save many more tokens.

Note: for gpt to understand what is going on I added this sentence to the prompt:
“When asked about temperature or humidity of a room, read the attributes of the binary sensors whose entity name end with room_va.”
For this to work, you obviously need the get_attributes to be defined.
As the sentence suggests, all these binary sensors have entity names that end with room_va.
Also, I did not need to specify that the state of the binary sensors reflected the state of windows/doors but you may have to if you have other binary sensors organised by rooms.