diff --git a/README.md b/README.md index 09a9f35..d7ac68e 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,10 @@ Options include [OpenAI Conversation](https://www.home-assistant.io/integrations - `execute_service` - `domain`(string): domain to be passed to `hass.services.async_call` - `service`(string): service to be passed to `hass.services.async_call` - - `service_data`(string): service_data to be passed to `hass.services.async_call` + - `service_data`(object): service_data to be passed to `hass.services.async_call`. + - `entity_id`(string): target entity + - `device_id`(string): target device + - `area_id`(string): target area - `add_automation` - `automation_config`(string): An automation configuration in a yaml format - `get_history` @@ -142,6 +145,9 @@ Then you will be able to let OpenAI call your function. ### 1. template #### 1-1. Get current weather +For real world example, see [weather](https://github.com/jekalmin/extended_openai_conversation/tree/main/examples/function/weather).
+This is just an example from [OpenAI documentation](https://platform.openai.com/docs/guides/function-calling/common-use-cases) + ```yaml - spec: name: get_current_weather diff --git a/examples/function/area/README.md b/examples/function/area/README.md new file mode 100644 index 0000000..197a68e --- /dev/null +++ b/examples/function/area/README.md @@ -0,0 +1,51 @@ + + +## Objective +- Call service via area_id + + + + +## Function + +### get_attributes +```yaml +- spec: + name: execute_services + description: Execute service of devices in Home Assistant. + parameters: + type: object + properties: + list: + type: array + items: + type: object + properties: + domain: + type: string + description: The domain of the service. + service: + type: string + description: The service to be called + service_data: + type: object + description: The service data object to indicate what to control. + properties: + entity_id: + type: array + items: + type: string + description: The entity_id retrieved from available devices. It must start with domain, followed by dot character. + area_id: + type: array + items: + type: string + description: The id retrieved from areas. You can specify only area_id without entity_id to act on all entities in that area + required: + - domain + - service + - service_data + function: + type: native + name: execute_service +``` \ No newline at end of file diff --git a/examples/function/attributes/README.md b/examples/function/attributes/README.md index 7dd018d..510cda7 100644 --- a/examples/function/attributes/README.md +++ b/examples/function/attributes/README.md @@ -2,7 +2,7 @@ - Get attributes of entity - + ## Function diff --git a/examples/function/google_search/README.md b/examples/function/google_search/README.md new file mode 100644 index 0000000..85324bb --- /dev/null +++ b/examples/function/google_search/README.md @@ -0,0 +1,37 @@ +## Objective +- Search from Google + +## Prerequisite +Needs Google API Key + +## Function + +### search_google + +```yaml +- spec: + name: search_google + description: Search Google using the Custom Search API. + parameters: + type: object + properties: + query: + type: string + description: The search query. + required: + - query + function: + type: rest + resource_template: "https://www.googleapis.com/customsearch/v1?key=[GOOGLE_API_KEY]&cx=[GOOGLE_PROGRAMMING_SEARCH_ENGINE]:omuauf_lfve&q={{ query }}&num=3" + value_template: >- + {% if value_json.items %} + ```csv + title,link + {% for item in value_json.items %} + "{{ item.title | replace(',', ' ') }}","{{ item.link }}" + {% endfor %} + ``` + {% else %} + No results found, + {% endif %} +``` \ No newline at end of file diff --git a/examples/function/weather/README.md b/examples/function/weather/README.md new file mode 100644 index 0000000..273b077 --- /dev/null +++ b/examples/function/weather/README.md @@ -0,0 +1,28 @@ +## Objective +- Get current weather and forecasts + + + + +## Prerequisite +Expose `weather.xxxxx` entity + +## Function + +### get_attributes +```yaml +- spec: + name: get_attributes + description: Get attributes of any home assistant entity + parameters: + type: object + properties: + entity_id: + type: string + description: entity_id + required: + - entity_id + function: + type: template + value_template: "{{states[entity_id]}}" +``` \ No newline at end of file