Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d2659d0
Update README.md
gritaro Feb 13, 2024
c434390
Added gitignore
gritaro Feb 13, 2024
bf8ea46
Cleanup code and fix requirements versions
gritaro Feb 13, 2024
84f92b4
Fix broken release 0.1.0
gritaro Feb 13, 2024
df6197a
Add support for multiple LLM engines
gritaro Feb 13, 2024
511cdbd
Merge pull request #1 from gritaro/rc-0.1.2
gritaro Feb 14, 2024
65b044c
Bump version to 0.1.2
gritaro Feb 14, 2024
1b4ceef
Merge pull request #2 from gritaro/bump-manifest-version
gritaro Feb 14, 2024
da89b50
- Add support for completion models configuration
gritaro Feb 14, 2024
96582f6
Merge pull request #3 from gritaro/rc-0.1.3
gritaro Feb 16, 2024
378d51f
Bump version
gritaro Feb 16, 2024
8976efe
Merge pull request #4 from gritaro/rc-0.1.3-bump
gritaro Feb 16, 2024
6653779
Add support for choosing models
gritaro Feb 18, 2024
f1edeb0
Merge pull request #5 from gritaro/rc-0.1.4
gritaro Feb 18, 2024
44c42b8
Enhance github actions files
gritaro Feb 20, 2024
1d33534
Merge pull request #7 from gritaro/github-actions-enh
gritaro Feb 20, 2024
c50d09f
Support inbuilt functionality for controlling home-assistant (#6)
gritaro Feb 20, 2024
75a5c78
Support Anyscale LLM (#8)
gritaro Feb 21, 2024
2f23407
Correct
gritaro Feb 23, 2024
c6a2ea1
0.1.7 HA compatibility fix (#9)
gritaro May 16, 2024
95cdc20
Fix compatibility with HA 2024.12.1+ (#12)
gritaro Jan 12, 2025
38da792
Update README.md
gritaro Jan 12, 2025
a7bc725
Update README-ru.md
gritaro Jan 12, 2025
005f95d
feat: migrate to ConversationEntity, add tests, changelog and docs
dzerik Mar 10, 2026
9d8cc00
feat: ChatLog для истории, миграция на langchain-gigachat/langchain-o…
dzerik Mar 10, 2026
4610f4c
feat: streaming ответов LLM через async_add_delta_content_stream
dzerik Mar 10, 2026
7cdb61c
feat: rename GigaChain -> SmartChain + add AI Task entity (v0.7.0)
dzerik Mar 10, 2026
b52e915
docs: add CLAUDE.md project rules
dzerik Mar 10, 2026
917ddec
feat: register AI Task platform + add 7 AI Task tests + lint fixes (v…
dzerik Mar 10, 2026
2f894cd
docs: update all documentation for SmartChain rename
dzerik Mar 10, 2026
51c3a4e
build: migrate to uv + pyproject.toml
dzerik Mar 10, 2026
30e3c5d
Bump actions/checkout from 4 to 6
dependabot[bot] Mar 10, 2026
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @gritaro
17 changes: 17 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"
36 changes: 36 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# These settings are synced to GitHub by https://probot.github.io/apps/settings/

repository:
name: ha-smartchain
description: "SmartChain — multi-provider LLM conversation agent for Home Assistant (GigaChat, YandexGPT, OpenAI) with tool calling and streaming"
homepage: https://github.com/gritaro/ha-smartchain
topics: homeassistant, hacs-integration, voice-assistant, langchain, gigachat, yandexgpt, openai, llm, smart-home, ai-agent
private: false
has_issues: true
has_projects: false
has_wiki: false
default_branch: main
allow_squash_merge: true
use_squash_pr_title_as_default: true
allow_merge_commit: false
allow_rebase_merge: true
delete_branch_on_merge: true
enable_vulnerability_alerts: true

labels:
- name: "Feature Request"
color: "00ffbb"
- name: "Bug"
color: "e30000"
- name: "Wont Fix"
color: "ffffff"
- name: "Enhancement"
color: "48ff00"
- name: "Documentation"
color: "0077ff"
- name: "Help needed"
color: "fbca04"
- name: "dependencies"
color: "000000"
- name: "github_actions"
color: "000000"
21 changes: 21 additions & 0 deletions .github/workflows/cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Cron HACS actions

on:
schedule:
- cron: "0 0 * * *"

jobs:
validate:
runs-on: "ubuntu-latest"
name: Validate
steps:
- uses: "actions/checkout@v6"

- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
ignore: brands

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"
17 changes: 0 additions & 17 deletions .github/workflows/hacs.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/hassfest.yaml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pull actions

on:
pull_request:

env:
PYTHON_VERSION: "3.12"

jobs:
validate:
runs-on: "ubuntu-latest"
name: Validate
steps:
- uses: "actions/checkout@v6"

- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"

lint:
runs-on: "ubuntu-latest"
name: Lint with ruff
steps:
- uses: "actions/checkout@v6"
- uses: "astral-sh/setup-uv@v5"
- run: uv run ruff check .
- run: uv run ruff format --check .

test:
runs-on: "ubuntu-latest"
name: Run tests
steps:
- uses: "actions/checkout@v6"
- uses: "astral-sh/setup-uv@v5"
- run: uv sync
- run: uv run pytest tests/ -v
44 changes: 44 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Push actions

on:
push:
branches:
- main
- rc-*

env:
PYTHON_VERSION: "3.12"

jobs:
validate:
runs-on: "ubuntu-latest"
name: Validate
steps:
- uses: "actions/checkout@v6"

- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
ignore: brands

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"

lint:
runs-on: "ubuntu-latest"
name: Lint with ruff
steps:
- uses: "actions/checkout@v6"
- uses: "astral-sh/setup-uv@v5"
- run: uv run ruff check .
- run: uv run ruff format --check .

test:
runs-on: "ubuntu-latest"
name: Run tests
steps:
- uses: "actions/checkout@v6"
- uses: "astral-sh/setup-uv@v5"
- run: uv sync
- run: uv run pytest tests/ -v
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
__pycache__
.idea
/shelf/
/workspace.xml
/httpRequests/
/dataSources/
/dataSources.local.xml
*.iws
*.iml
*.ipr
/.mcp.json
/.serena/
.pytest_cache
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.7
hooks:
- id: ruff
- id: ruff-format
75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Changelog

All notable changes to this project are documented in this file.

Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
project follows [Semantic Versioning](https://semver.org/).

## [0.7.0] - 2026-03-10

### Changed
- **Project renamed: GigaChain -> SmartChain** — reflects multi-provider nature (not GigaChat-only)
- Domain: `gigachain` -> `smartchain`
- Entity classes: `GigaChainConversationEntity` -> `SmartChainConversationEntity`
- New GitHub repository: `ha-smartchain`
- HACS name: SmartChain
- Version bumped to 0.7.0

### Added
- **AI Task entity** — `SmartChainAITaskEntity` implements `ai_task.AITaskEntity` with `_async_generate_data()` for automation-driven text generation via `ai_task.generate_data` service
- Structured output support in AI Task (JSON parsing with `task.structure`)
- Tool calling support in AI Task (reuses conversation entity's LangChain integration)

## [0.6.0] - 2026-03-10

### Added
- **Assist API for device control** — integration with HA LLM API (`async_provide_llm_data`) allows LLM to call Home Assistant services (turn on/off lights, locks, etc.)
- `llm_hass_api` option in Options Flow — select HA API for LLM (Assist, custom APIs)
- HA `llm.Tool` (voluptuous schema) -> LangChain tools conversion via `voluptuous_openapi` + `client.bind_tools()`
- Tool calling loop with `MAX_TOOL_ITERATIONS = 10`
- `tool_calls` in `AIMessageChunk` -> HA `ToolInput` in stream deltas
- `ToolResultContent` <-> LangChain `ToolMessage` conversion in `_chatlog_to_langchain()`

### Changed
- `_async_handle_message` — uses `async_provide_llm_data` when LLM API configured, manual prompt otherwise
- Options Flow: `common_config_option_schema` takes `hass` to list available LLM APIs

## [0.5.0] - 2026-03-10

### Added
- **Streaming responses** — `_attr_supports_streaming = True`, responses streamed via `ChatLog.async_add_delta_content_stream()`
- Async generator `_async_langchain_stream()` for `AIMessageChunk` -> HA delta dicts

### Changed
- `client.invoke()` via `async_add_executor_job` replaced with `client.astream()` (async, no executor)

## [0.4.0] - 2026-03-10

### Changed
- **ChatLog for history** — removed custom `OrderedDict`, uses native HA `ChatLog`
- **Migration to langchain-gigachat/langchain-openai** — proper package imports

## [0.3.0] - 2026-03-10

### Added
- **Migration to ConversationEntity** — entity-based conversation agent with `_async_handle_message(user_input, chat_log)`

## [0.2.0] - 2026-03-10

### Fixed
- Blocking LLM calls, deprecated LangChain API, memory leaks, model defaults

### Removed
- Anyscale support completely removed

## [0.1.8] - 2024-12-01

### Fixed
- Compatibility with Home Assistant 2024.12.1+

## [0.1.1] - 2024-03-01

### Added
- Initial release with GigaChat, YandexGPT support
- Config Flow and Options Flow
- Chat history and Jinja2 system prompts
57 changes: 57 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SmartChain — Project Rules

## Project Overview
SmartChain is a Home Assistant custom integration providing a multi-provider LLM conversation agent via LangChain.

- **Domain**: `smartchain`
- **HA Platform**: `Platform.CONVERSATION` (+ `Platform.AI_TASK` planned)
- **Supported LLM providers**: GigaChat, YandexGPT, OpenAI
- **Planned providers**: Ollama, DeepSeek, Anthropic
- **GitHub**: https://github.com/dzerik/ha-smartchain

## Architecture

### Core Files
- `custom_components/smartchain/__init__.py` — entry setup, client creation
- `custom_components/smartchain/conversation.py` — `SmartChainConversationEntity` (streaming, tool calling)
- `custom_components/smartchain/ai_task.py` — `SmartChainAITaskEntity` (data generation)
- `custom_components/smartchain/config_flow.py` — Config Flow + Options Flow
- `custom_components/smartchain/client_util.py` — LLM client factory (`get_client`, `validate_client`)
- `custom_components/smartchain/const.py` — all constants, prompts, model lists

### Key Patterns
- **Streaming**: `client.astream()` -> `_async_langchain_stream()` -> `chat_log.async_add_delta_content_stream()`
- **Tool calling**: HA `llm.Tool` -> `_ha_tool_to_dict()` -> `client.bind_tools()` -> loop until no `unresponded_tool_results`
- **ChatLog conversion**: `_chatlog_to_langchain()` converts HA ChatLog content to LangChain message list
- **System prompt**: With Assist API — `async_provide_llm_data()`, without — manual Jinja2 template + `DEFAULT_DEVICES_PROMPT`

### Tests
- `tests/test_config_flow.py` — 11 config flow tests
- `tests/test_init.py` — 19 conversation entity tests
- `tests/test_setup.py` — 4 setup/unload tests
- Run: `python3 -m pytest tests/ -v`

## Development Rules

### Naming
- Entity classes: `SmartChain*Entity` (e.g., `SmartChainConversationEntity`)
- Imports: `from custom_components.smartchain.X import Y`
- Domain constant: `DOMAIN = "smartchain"`

### Testing
- Always run tests before committing: `python3 -m pytest tests/ -v`
- All tests must pass
- Mock LLM clients with `MagicMock` + `astream` side_effect
- Use `_make_chat_log()` helper for mock ChatLog with streaming support

### Dependencies
- `langchain-gigachat>=0.3.0` — GigaChat provider
- `langchain-openai>=0.3.0` — OpenAI provider
- `langchain-community>=0.4.0` — YandexGPT and others
- `home-assistant-intents` — language support
- `yandexcloud==0.295.0` — Yandex Cloud SDK

### Version Policy
- Manifest version in `custom_components/smartchain/manifest.json`
- Follow semver: PATCH for fixes, MINOR for features, MAJOR for breaking changes
- Current: 0.7.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 gritaro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading