Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d68f29ab5 | ||
|
|
19d4a93bca | ||
|
|
fb75c5f44e | ||
|
|
52af987985 | ||
|
|
162a30acdd | ||
|
|
898a6fc638 | ||
|
|
38e2362be4 | ||
|
|
cea912d0b5 | ||
|
|
5ec00040c2 | ||
|
|
8d28fc4a0d | ||
|
|
7cc6587724 | ||
|
|
bacf76e0a9 | ||
|
|
f86c7bfd57 | ||
|
|
2aaf340575 | ||
|
|
bae11ba85c | ||
|
|
9eb7d8912c |
@@ -4,7 +4,7 @@
|
||||
|
||||
  [](https://creativecommons.org/licenses/by-nc-sa/4.0/) [](https://github.com/hacs/integration)   
|
||||
|
||||
<img src="https://github.com/smkrv/ha-text-ai/blob/e03b5315c2cc7b489a6e1175da728075275ed614/misc/icons/logo.png" alt="HA Text AI" style="width: 80%; max-width: 640px; max-height: 150px; aspect-ratio: 2/1; object-fit: contain;"/>
|
||||
<img src="https://github.com/smkrv/ha-text-ai/blob/2aaf3405759eb2d97624834594e24ace896131df/assets/images/icons/logo.png" alt="HA Text AI" style="width: 80%; max-width: 640px; max-height: 150px; aspect-ratio: 2/1; object-fit: contain;"/>
|
||||
|
||||
### Advanced AI Integration for [Home Assistant](https://www.home-assistant.io/) with LLM multi-provider support
|
||||
</div>
|
||||
@@ -17,13 +17,11 @@ Transform your smart home experience with powerful AI assistance powered by mult
|
||||
---
|
||||
|
||||
> [!IMPORTANT]
|
||||
> 🚧 BETA VERSION
|
||||
> Expect: potential bugs, frequent changes, incomplete features.
|
||||
> 🤝 Community Driven
|
||||
>
|
||||
> <a href="https://community.home-assistant.io/t/ha-text-ai-transforming-home-automation-with-multi-provider-language-models/799741"><img src="https://img.shields.io/badge/Community-blue?style=for-the-badge&logo=homeassistant&logoColor=white&color=03a9f4"/></a>
|
||||
>
|
||||
> [Screenshots](misc/screenshots/screenshot.jpg)
|
||||
> [Screenshots](assets/images/screenshots/screenshot.jpg)
|
||||
|
||||
## 🌟 Features
|
||||
|
||||
@@ -34,7 +32,7 @@ Transform your smart home experience with powerful AI assistance powered by mult
|
||||
- 🎯 **Advanced Customization**: Per-request model and parameter selection
|
||||
- 🔒 **Enhanced Security**: Secure API key management and usage monitoring
|
||||
- 🎨 **Improved User Experience**: Intuitive configuration and rich interfaces
|
||||
- 🔄 **Automation Integration**: Event-driven responses and template compatibility
|
||||
- 🔄 **Automation Integration**: Event-driven responses and template compatibility
|
||||
|
||||
<details>
|
||||
<summary>📦 Detailed Feature Breakdown</summary>
|
||||
@@ -89,6 +87,19 @@ Transform your smart home experience with powerful AI assistance powered by mult
|
||||
|
||||
</details>
|
||||
|
||||
#### 🌐 Translations
|
||||
|
||||
| Code | Language | Status |
|
||||
|------|----------|--------|
|
||||
| 🇩🇪 de | Deutsch | Full |
|
||||
| 🇬🇧 en | English | Primary |
|
||||
| 🇪🇸 es | Español | Full |
|
||||
| 🇮🇳 hi | हिन्दी | Full |
|
||||
| 🇮🇹 it | Italiano | Full |
|
||||
| 🇷🇺 ru | Русский | Full |
|
||||
| 🇷🇸 sr | Српски | Full |
|
||||
| 🇨🇳 zh | 中文 | Full |
|
||||
|
||||
## 📋 Prerequisites
|
||||
|
||||
- Home Assistant 2024.11 or later
|
||||
@@ -96,6 +107,7 @@ Transform your smart home experience with powerful AI assistance powered by mult
|
||||
- OpenAI ([Get key](https://platform.openai.com/account/api-keys))
|
||||
- Anthropic ([Get key](https://console.anthropic.com/))
|
||||
- OpenRouter ([Get key](https://openrouter.ai/keys))
|
||||
- Any OpenAI-compatible API provider
|
||||
- Python 3.9 or newer
|
||||
- Stable internet connection
|
||||
|
||||
@@ -136,6 +148,7 @@ To be compatible, a provider should support:
|
||||
- JSON request/response format
|
||||
- Standard authentication method
|
||||
- Similar model parameter handling
|
||||
|
||||
</details>
|
||||
|
||||
## ⚡ Installation
|
||||
@@ -238,12 +251,14 @@ data:
|
||||
max_tokens: 500 # optional
|
||||
context_messages: 10 #optional, number of previous messages to include in context, default: 5
|
||||
system_prompt: "You are a sleep optimization expert" # optional
|
||||
instance: sensor.ha_text_ai_gpt
|
||||
```
|
||||
|
||||
### set_system_prompt
|
||||
```yaml
|
||||
service: ha_text_ai.set_system_prompt
|
||||
data:
|
||||
instance: sensor.ha_text_ai_gpt
|
||||
prompt: |
|
||||
You are a home automation expert focused on:
|
||||
1. Energy efficiency
|
||||
@@ -299,6 +314,7 @@ automation:
|
||||
- service: ha_text_ai.ask_question
|
||||
data:
|
||||
question: "Home automation advice"
|
||||
instance: sensor.ha_text_ai_gpt
|
||||
- service: notify.mobile
|
||||
data:
|
||||
message: >
|
||||
@@ -507,10 +523,11 @@ If you want to say thanks financially, you can send a small token of appreciatio
|
||||
|
||||
---
|
||||
|
||||
<div align="center"><img src="https://github.com/smkrv/ha-text-ai/blob/f2a41aaa2cd88adaf6929ba5f228205a315efdfa/custom_components/ha_text_ai/icons/dark_icon%402x.png" alt="HA Text AI" style="width: 128px; height: auto;"/></div>
|
||||
<div align="center"><img src="https://github.com/smkrv/ha-text-ai/blob/2aaf3405759eb2d97624834594e24ace896131df/assets/images/icons/footer_icon.png" alt="HA Text AI" style="width: 128px; height: auto;"/></div>
|
||||
<div align="center">
|
||||
|
||||
Made with ❤️ and Claude 3.5 Sonnet for the Home Assistant Community
|
||||
Made with ❤️ for the Home Assistant Community,
|
||||
utilizing Claude 3.5 Sonnet, Gemini Pro 1.5, and Qwen 2.5 Coder 32B Instruct.
|
||||
|
||||
[Report Bug](https://github.com/smkrv/ha-text-ai/issues) · [Request Feature](https://github.com/smkrv/ha-text-ai/issues)
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 618 KiB After Width: | Height: | Size: 618 KiB |
|
Before Width: | Height: | Size: 923 KiB After Width: | Height: | Size: 923 KiB |
|
Before Width: | Height: | Size: 339 KiB After Width: | Height: | Size: 339 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
@@ -173,7 +173,6 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
||||
|
||||
self.available = True
|
||||
self._state = STATE_READY
|
||||
self._conversation_history = [] # Full conversation history
|
||||
|
||||
self._start_time = dt_util.utcnow()
|
||||
|
||||
@@ -404,17 +403,32 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
||||
|
||||
async def async_initialize_history_file(self) -> None:
|
||||
"""
|
||||
Asynchronously initialize history file.
|
||||
Asynchronously initialize history file and load existing history.
|
||||
"""
|
||||
try:
|
||||
# Ensure directory exists first
|
||||
await self._create_history_dir()
|
||||
|
||||
# Initialize file
|
||||
if not await self._file_exists(self._history_file):
|
||||
if await self._file_exists(self._history_file):
|
||||
# Load existing history
|
||||
async with AsyncFileHandler(self._history_file, 'r') as f:
|
||||
content = await f.read()
|
||||
if content:
|
||||
history = json.loads(content)
|
||||
# Validate and load history
|
||||
if isinstance(history, list):
|
||||
self._conversation_history = history[-self.max_history_size:]
|
||||
_LOGGER.debug(
|
||||
f"Loaded {len(self._conversation_history)} history entries "
|
||||
f"for {self.instance_name}"
|
||||
)
|
||||
else:
|
||||
# Create new history file
|
||||
async with AsyncFileHandler(self._history_file, 'w') as f:
|
||||
await f.write(json.dumps([]))
|
||||
|
||||
await self._check_history_size()
|
||||
await self.async_update_ha_state()
|
||||
|
||||
_LOGGER.debug(f"History file initialized: {self._history_file}")
|
||||
|
||||
except Exception as e:
|
||||
@@ -504,6 +518,15 @@ class HATextAICoordinator(DataUpdateCoordinator):
|
||||
_LOGGER.error(f"Error writing history entry: {e}")
|
||||
_LOGGER.debug(traceback.format_exc())
|
||||
|
||||
async def _check_history_size(self) -> None:
|
||||
"""Verify and adjust history size if needed."""
|
||||
if len(self._conversation_history) > self.max_history_size:
|
||||
_LOGGER.warning(
|
||||
f"History size ({len(self._conversation_history)}) exceeds "
|
||||
f"maximum ({self.max_history_size}). Trimming..."
|
||||
)
|
||||
self._conversation_history = self._conversation_history[-self.max_history_size:]
|
||||
|
||||
async def _check_file_size(self, file_path: str) -> int:
|
||||
"""
|
||||
Check file size asynchronously.
|
||||
|
||||
@@ -23,6 +23,6 @@
|
||||
"single_config_entry": false,
|
||||
"ssdp": [],
|
||||
"usb": [],
|
||||
"version": "2.0.7-beta",
|
||||
"version": "2.0.8",
|
||||
"zeroconf": []
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
},
|
||||
"services": {
|
||||
"ask_question": {
|
||||
"name": "Hacer Pregunta (IA de Texto de HA)",
|
||||
"name": "Hacer Pregunta (HA Text AI)",
|
||||
"description": "Envía una pregunta al modelo de IA y recibe una respuesta detallada. La respuesta se almacenará en el historial de conversación y se podrá recuperar más tarde.",
|
||||
"fields": {
|
||||
"instance": {
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
},
|
||||
"services": {
|
||||
"ask_question": {
|
||||
"name": "प्रश्न पूछें (एचए टेक्स्ट एआई)",
|
||||
"name": "प्रश्न पूछें (HA Text AI)",
|
||||
"description": "एआई मॉडल को एक प्रश्न भेजें और विस्तृत प्रतिक्रिया प्राप्त करें। प्रतिक्रिया बातचीत के इतिहास में संग्रहीत की जाएगी और बाद में पुनर्प्राप्त की जा सकती है।",
|
||||
"fields": {
|
||||
"instance": {
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
},
|
||||
"services": {
|
||||
"ask_question": {
|
||||
"name": "Задать вопрос (Текстовый ИИ HA)",
|
||||
"name": "Задать вопрос (HA Text AI)",
|
||||
"description": "Отправить вопрос модели ИИ и получить подробный ответ. Ответ будет сохранен в истории разговора и может быть получен позже.",
|
||||
"fields": {
|
||||
"instance": {
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
},
|
||||
"services": {
|
||||
"ask_question": {
|
||||
"name": "提问(HA文本AI)",
|
||||
"name": "提问 (HA Text AI)",
|
||||
"description": "向AI模型发送问题并接收详细响应。响应将存储在对话历史中,可以稍后检索。",
|
||||
"fields": {
|
||||
"instance": {
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
```
|
||||
ha-text-ai/
|
||||
├── custom_components
|
||||
│ └── ha_text_ai
|
||||
│ ├── __init__.py
|
||||
│ ├── api_client.py
|
||||
│ ├── config_flow.py
|
||||
│ ├── const.py
|
||||
│ ├── coordinator.py
|
||||
│ ├── icons
|
||||
│ │ ├── dark_icon.png
|
||||
│ │ ├── dark_icon@2x.png
|
||||
│ │ ├── dark_logo.png
|
||||
│ │ ├── dark_logo@2x.png
|
||||
│ │ ├── icon.png
|
||||
│ │ ├── icon@2x.png
|
||||
│ │ ├── logo.png
|
||||
│ │ └── logo@2x.png
|
||||
│ ├── manifest.json
|
||||
│ ├── sensor.py
|
||||
│ ├── services.yaml
|
||||
│ └── translations
|
||||
│ ├── de.json
|
||||
│ ├── en.json
|
||||
│ ├── es.json
|
||||
│ ├── hi.json
|
||||
│ ├── it.json
|
||||
│ ├── ru.json
|
||||
│ ├── sr.json
|
||||
│ └── zh.json
|
||||
ha_text_ai/
|
||||
├── __init__.py
|
||||
├── api_client.py
|
||||
├── config_flow.py
|
||||
├── const.py
|
||||
├── coordinator.py
|
||||
├── icons
|
||||
│ ├── dark_icon.png
|
||||
│ ├── dark_icon@2x.png
|
||||
│ ├── dark_logo.png
|
||||
│ ├── dark_logo@2x.png
|
||||
│ ├── icon.png
|
||||
│ ├── icon@2x.png
|
||||
│ ├── logo.png
|
||||
│ └── logo@2x.png
|
||||
├── manifest.json
|
||||
├── sensor.py
|
||||
├── services.yaml
|
||||
└── translations
|
||||
├── de.json
|
||||
├── en.json
|
||||
├── es.json
|
||||
├── hi.json
|
||||
├── it.json
|
||||
├── ru.json
|
||||
├── sr.json
|
||||
└── zh.json
|
||||
|
||||
```
|
||||
|
||||