Skip to content
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

Adding support for 2023.5.x #29

Merged
merged 6 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .attachments/customAssistant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@ This conversation agent is unable to control your house. It can only query infor

# Limitations

- Home Assistant 2023.4.0+ is required
- Supported [Azure OpenAI API Versions](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#completions):
- 2023-03-15-preview
- 2022-12-01
- **Home Assistant versions** supported: Due to the breaking changes introduced by [Home Assistant Core](https://github.com/home-assistant/core/releases) for custom assistants, the Azure OpenAI Conversation integration is compatible with the following Home Assistant versions:
<center>

| Azure OpenAI Conversation Version | Home Assistant Version |
| --------------------------------- | ---------------------- |
| 0.x.y | 2023.4.x |
| 1.x.y | 2023.5.x |
</center>

## AI Models supported:

Expand All @@ -44,22 +51,26 @@ conversation:
```
2. Download and install the integration from HACS: [Azure OpenAI Conversation](https://my.home-assistant.io/redirect/hacs_repository/?owner=joselcaguilar&repository=azure-openai-ha&category=integration)
3. Restart your Home Assistant instance
4. Go to Settings -> Devices & Services -> Add Integration
5. Search for `Azure OpenAI Conversation`
6. Type your `API Key`, `API Base` and `API Version` used following the example below and hit submit:
4. Go to [Settings -> Devices & Services -> Add Integration -> Azure OpenAI Conversation](https://my.home-assistant.io/redirect/config_flow_start/?domain=azure_openai_conversation)
5. Type your `API Key`, `API Base` and `API Version` used following the example below and hit submit:
> - API Key: 1234567890abcdef1234567890abcdef <br>
> - API Base: https://iotlabopenai.openai.azure.com/ <br>
> - API Version: 2023-03-15-preview <br>

#### **Home Assistant 2023.5.x users:**
The custom assistant needs to be added from [Settings -> Voice assistants](https://my.home-assistant.io/redirect/voice_assistants/). Once it's added, you can select the custom assistant as favorite to be used by default:

<center>
![Voice Assistants](https://raw.githubusercontent.com/joselcaguilar/azure-openai-ha/main/.attachments/customAssistant.png)
</center>

# Options

Options for Azure OpenAI Conversation can be set via the user interface, by taking the following steps:

1. Browse to your Home Assistant instance.
2. In the sidebar click on Settings.
3. From the configuration menu select: Devices & Services.
4. If multiple instances of OpenAI Conversation are configured, choose the instance you want to configure.
Click on "Options".
2. In the sidebar click on [Settings -> Devices & Services](https://my.home-assistant.io/redirect/integrations/).
3. If multiple instances of OpenAI Conversation are configured, choose the instance you want to modify and click on "Configure".

Options available:
- **Prompt Template:**
Expand Down
8 changes: 7 additions & 1 deletion custom_components/azure_openai_conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

from functools import partial
import logging
from typing import Literal

import openai
from openai import error

from homeassistant.components import conversation
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY
from homeassistant.const import CONF_API_KEY, MATCH_ALL
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady, TemplateError
from homeassistant.helpers import intent, template
Expand Down Expand Up @@ -78,6 +79,11 @@ def attribution(self):
"url": "https://azure.microsoft.com/products/cognitive-services/openai-service",
}

@property
def supported_languages(self) -> list[str] | Literal["*"]:
"""Return a list of supported languages."""
return MATCH_ALL

async def async_process(
self, user_input: conversation.ConversationInput
) -> conversation.ConversationResult:
Expand Down
3 changes: 0 additions & 3 deletions custom_components/azure_openai_conversation/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle the initial step."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")

if user_input is None:
return self.async_show_form(
step_id="user", data_schema=STEP_USER_DATA_SCHEMA
Expand Down
3 changes: 0 additions & 3 deletions custom_components/azure_openai_conversation/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]"
}
},
"options": {
Expand Down