hass-core/tests/components/ollama/conftest.py
Denis Shulyaka 4b2073ca59
Add LLM tools support for Ollama (#120454)
* Add LLM tools support for Ollama

* fix tests

* coverage

* Separate call for tool parameters

* Fix example

* hint on parameters schema if LLM forgot to request it

* Switch to native tool call functionality

* Fix tests

* Fix tools list

* update strings and default model

* Ignore mypy error until fixed upstream

* Ignore mypy error until fixed upstream

* Add missing prompt part

* Update default model
2024-07-28 18:19:53 -07:00

56 lines
1.5 KiB
Python

"""Tests Ollama integration."""
from unittest.mock import patch
import pytest
from homeassistant.components import ollama
from homeassistant.const import CONF_LLM_HASS_API
from homeassistant.core import HomeAssistant
from homeassistant.helpers import llm
from homeassistant.setup import async_setup_component
from . import TEST_OPTIONS, TEST_USER_DATA
from tests.common import MockConfigEntry
@pytest.fixture
def mock_config_entry(hass: HomeAssistant) -> MockConfigEntry:
"""Mock a config entry."""
entry = MockConfigEntry(
domain=ollama.DOMAIN,
data=TEST_USER_DATA,
options=TEST_OPTIONS,
)
entry.add_to_hass(hass)
return entry
@pytest.fixture
def mock_config_entry_with_assist(
hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> MockConfigEntry:
"""Mock a config entry with assist."""
hass.config_entries.async_update_entry(
mock_config_entry, options={CONF_LLM_HASS_API: llm.LLM_API_ASSIST}
)
return mock_config_entry
@pytest.fixture
async def mock_init_component(hass: HomeAssistant, mock_config_entry: MockConfigEntry):
"""Initialize integration."""
assert await async_setup_component(hass, "homeassistant", {})
with patch(
"ollama.AsyncClient.list",
):
assert await async_setup_component(hass, ollama.DOMAIN, {})
await hass.async_block_till_done()
@pytest.fixture(autouse=True)
async def setup_ha(hass: HomeAssistant) -> None:
"""Set up Home Assistant."""
assert await async_setup_component(hass, "homeassistant", {})