This is a custom integration for Home Assistant that allows you to interact with OpenAI's text generation models. It provides a sensor entity to track the status of the integration and services to ask questions, view response history, and clear the history. 📊🔍
1.**Install HACS** (if you haven't already): Follow the [HACS installation guide](https://hacs.xyz/docs/installation/prerequisites/) if you need to install HACS first.
2.**Add HA text AI Integration to HACS**:
- Open Home Assistant.
- Navigate to **HACS**.
- Click on **Integrations**.
- Click the **Explore & Add Repositories** button (➕).
- Enter the repository URL: `https://github.com/smkrv/ha_text_ai`
- Click **Add repository**.
3.**Install**:
- In the list of available integrations, find **HA text AI**.
- **Description**: Ask a question to the integrated AI and receive a response.
- **Parameters**:
- `question`: The question or prompt to send to the AI (required)
- `model`: Override the default model for this question (optional)
- `temperature`: Adjust randomness in the response (0.0-1.0, optional)
- `max_tokens`: Limit the length of the response (optional)
### 2. Clear History
**Service:** `ha_text_ai.clear_history`
- **Description**: Clear the stored history of questions and responses.
### 3. Get History
**Service:** `ha_text_ai.get_history`
- **Description**: Retrieve the history of recent interactions.
- **Parameters**:
- `limit`: Maximum number of history items to return (default: `10`)
### 4. Set System Prompt
**Service:** `ha_text_ai.set_system_prompt`
- **Description**: Set a system prompt to guide the AI's behavior in future interactions.
- **Parameters**:
- `prompt`: The system prompt to set (required)
---
## Advanced Usage
- **Sensor State**: The sensor entity `sensor.ha_text_ai` will show `Ready` if the integration is configured and operational, otherwise it will show `Not Ready`.
- **Attributes**: When the sensor state is `Ready`, it provides attributes:
- `question`: The last question asked.
- `response`: The response to the last question.
- `last_updated`: Timestamp of the last successful update from the API.
---
## Logs & Debugging
- To view logs and debug issues, check the Home Assistant logs under **Configuration** -> **Logs**.
---
## Contributing
Feel free to contribute to this project! Open an issue or submit a pull request with any questions, improvements, or bug fixes.