-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HOW TO: FUNCTION to find entity_id based on friendly name, no IDs in prompt! #193
Comments
Hmm, there are also area_ids - so the answer is not quite correct. But I love the fuzzy search. |
I do not use area_ids for anything, just the entity_id. How would you expect it to respond? Python definitely is not my best language but I can try and modify for area_ids. |
I think it's not a big deal with area_ids. We can just let ChatGPT to choose the best function. Why do you search your entities by the device name? |
@rfam13 Configuration Requirements for the Extended OpenAI Conversation Fuzzy-Entity-Search-Function in Home AssistantPrerequisites:This function has been tested exclusively on the current development version of Home Assistant, which supports the use of labels and floors. Ensure your Home Assistant version is up to date with these features before proceeding. Setting Up Python Script Pro:To enhance the functionality of our function with Python Script Pro, you need to include the following lines in your python_script: # no 'S' at the end!
requirements:
- rapidfuzz
- fuzzywuzzy
- Levenshtein Note: While Configuration of Entities:When setting up the function, it is recommended to refer to entities as 'entities' and not as 'devices'. This helps ensure clarity in commands and configurations. Below is a segment you should include in your ChatGPT configuration prompt without modification, to ensure proper understanding and handling by ChatGPT: 'Labels' categorize entities, devices, or areas for easier organization and retrieval. Labels are not to be confused with physical locations:
'Floors' represent physical sections within the home, uniquely identified by 'floor_id' or 'floor_name':
'Areas' represent physical sections within the home, uniquely identified by 'area_id' or 'area_name':
Search and verify correct entity IDs before responding to queries. Follow these guidelines:
Example: These instructions ensure all responses are based on validated and accurate information. Handling of Local Variables:An important note for users: Python Script Pro passes all local variables via "response_variable: _function_result". This means that all entities might be unintentionally transmitted to ChatGPT if they are stored in local variables within the Python function. We have addressed this issue in the current version to avoid unintentional data exposure every time the function is used. Documentation and Understanding Response Variables:There is a lack of extensive documentation on |
Edit: 2024-04-25: New version: Added is_exposed filter with a workaround.
|
Awesome! I ended with the same libraries and a character count with reward and penalty based on length of friendly name and requested device name comparison. This helped eliminate the entities being found with 1 or 2 characters extra but matched true for all the other rules. I will test yours out when I get a chance, yours may be a winner! |
I updated to a new version above. It now requires a Label, but it should work even if you remove this requirement. And you may want to add this to your prompt:
|
NOTICE: you must have https://github.com/AlexxIT/PythonScriptsPro installed for this to work correctly.
EDIT: I'm assuming you need to change the allowed number of functions from 1, I have mine at 5 but have not tested with it set to 1.
Model: gpt-3.5-turbo
This uses python scripts pro (allows for inline python) to search your entities using Python for a matching name of an entity, and then returns the entity_id as a response to the function. This eliminates the need for sending all entities in the initial prompt allowing the context to be minimal.
Make sure you add to your prompt, to use the functions response as the entity_id for the action requested.
This is a rough draft of the function chatgpt and I came up with. I have mine modified to source out lights mainly. If I make any advancements in the fuzzy search I will update.
You can also instruct it to find the entity_id first then proceed with the requested action, for example getting the entity_id and then getting the attributes
The text was updated successfully, but these errors were encountered: