Giter Club home page Giter Club logo

openassist's Introduction

Buy Me A Coffee
OpenAssist Beta - Home Assistant OpenAI GPT4 with Pinecone Index

Video Walkthrough

https://youtu.be/2folwIIP3ms



Overview

Hey there! Just wanted to let you know that this project is still in the beta stage. Sure, it's functional, but it's got a couple of quirks (like not always finding the right entities after a query).

This is a one-man show and I'm knee-deep in the development process. I'm open to any ideas from the community. Your suggestions could really help in shaping this into something spectacular. So, dive in!


This Home Assistant custom component creates a Pinecone index containing all your Home Assistant entity details. This allows you to make queries or ask questions using the input_boolean.openassist_prompt, such as "turn my kitchen light off" or "what's the current state of my kitchen light".

This query is sent to the Pinecone index to find the closest matching entity, which is then sent to the ChatGPT4 model, returning the necessary data to perform the corresponding service call action.

Integration Install

  1. (Manual) Copy the OpenMindsAI folder to your Home Assistant's custom_components directory. If you don't have a custom_components directory, create one in the same directory as your configuration.yaml file.

(HACS) Add this repository as a HACS Integration: https://github.com/Hassassistant/openassist

  1. Restart Home Assistant.

  2. Add the following lines to your Home Assistant configuration.yaml file: (See below for prerequisites)

input_text:
  openassist_prompt:
    initial: ""
    max: 255

  pinecone_index:
    initial: ""
    max: 255

openassist:
  openai_key: "sk-...s1jz" #YOUR_OPENAI_KEY  
  pinecone_key: "b9a09c6a-...db2" #YOUR_PINECONE_ENVIRONMENT ID
  pinecone_env: "us-west1-gcp-free" #YOUR_PINECONE_ENVIRONMENT ID
  included_domains: "light, weather" #WHICH DOMAINS TO INCLUDE IN PINECONE DB

sensor:
  - platform: openassist
    your_name: "YOUR_NAME" #Optional if you want ChatGPT to know your name.
    mindsdb_model: "gpt4hass" #MINDSDB MODEL NAME.
    mindsdb_email: "[email protected]"
    mindsdb_password: "Your_MindsDB_Password"
    notify_device: "alexa_media_office_echo" #Optional, this sends each ChatGPT response to your notify entity.
    #Can be any of your Notify entities. (Phone, Amazon Echo etc)

# If you need to debug any issues.
logger:
  default: info
  logs:
    custom_components.openassist: debug
  1. Restart Home Assistant.

Example Lovelace Card

enter image description here?raw=true)

square: false
columns: 1
type: grid
cards:
  - type: entities
    entities:
      - entity: input_text.pinecone_index
        name: Index Creation (Please type your ENV ID and hit enter)
  - type: markdown
    content: '{{ state_attr(''sensor.openassist_response'', ''index_status'') }}'
    title: Pinecone Index Status
  - type: entities
    entities:
      - entity: input_text.openassist_prompt
        name: OpenAssist
  - type: markdown
    content: '{{ state_attr(''sensor.openassist_response'', ''message'') }}'
    title: OpenAssist Response

How to use

  1. Type in your Pinecone Environment ID in the Pinecone Index input_boolean.
  2. Hit enter.
  3. Your Pinecone index will be created, this will then upload all your Home Assistant entity data to the index. Please allow 10 - 15 minutes for the proccess to complete, dependant on how many entites you have.

    Be aware: There is a known issue in Pinecone free tier, creation of new indexes getting stuck in a loop. This is out of my control, on one occasion I abandoned the index creation, and started this whole proccess again with a new Pinecone account.

    enter image description here

  4. Notifications on the Index creation will be send to the OpenAssist Response entity.
    enter image description here
    enter image description here
  5. Send a question or query.
    Example 1
    enter image description here
    Example 2
    enter image description here
    Example 3
    enter image description here
    Example 4
    enter image description here

Prerequisites

You need to have the following accounts and their corresponding keys:

  • Pinecone: You need a Pinecone account with an API key, along with the Environment ID (example: us-west1-gcp-free).
  • OpenAI: You need an OpenAI API key, used for embedding.
  • MindsDB: You'll need a MindsDB account, and the name of your MindsDB model.

Creating the AI model in MindsDB

  1. Create a free account on MindsDB and login. You can do so HERE.

  2. Navigate to the MindsDB editor. You can find it HERE.

  3. Create your AI model. In this example, we're creating an OpenAI GPT4 model named gpt4hass. You can replace gpt4hass with your preferred model name. Execute the following SQL query to create your model:

CREATE  MODEL mindsdb.gpt4hass
PREDICT response
USING
  engine  =  'openai',
  max_tokens =  2000,
  model_name =  'gpt-4',
  prompt_template =  '{{text}}';

Click "Run" to execute the query and create your model.

Pinecone API Key and Environment ID

  1. Create a free account on Pinecone and login. You can do so HERE.
  2. Wait for "Project Initializing" to finish.
  3. Navigate to the Pinecone API Key page and take note of the API Key (Value) and Environment ID.

enter image description here

OpenAI API Key

  1. Create a free account on Openai Playground and login. You can do so HERE.
  2. Navigate to the OpenAI API Keys page. You can do so HERE.
  3. Create a new secret key, and take note of the API Key.

enter image description here

openassist's People

Contributors

hassassistant avatar

Stargazers

Isaac Hernandez avatar  avatar Joe Geldart avatar  avatar JH220 aka. Jan-Hendrik avatar SAP Sentinel avatar Anton Volnuhin avatar Alexander Auras avatar StarSkyZheng avatar Pablo P Varela avatar  avatar  avatar  avatar Simon B.Robert avatar LoRd_NeX avatar Juan Fran avatar David Konsumer avatar Andrew Rowe avatar MAUIXER avatar dognonymous avatar Alex Borisov avatar Daniel Zarinski avatar  avatar Ozgur Ogul Koca avatar  avatar sedy avatar Ralph Schuler avatar Giel Janssens avatar  avatar Levi Govaerts avatar cat&cat avatar  avatar  avatar Johann Natividad avatar  avatar Kevin avatar  avatar  avatar Michal Vilímek avatar Imre avatar  avatar  avatar

Watchers

Dave Proffer avatar Carlo Costanzo avatar  avatar  avatar  avatar

openassist's Issues

No pinecone vectors

Hi,

I'm struggling to get my entities uploaded to pinecode. Have tried with 2 different accounts, and also tried to delete index and restart process, several times.
The index status response is replying that the index is being created, and data is being uploaded. I will be noticed when everything is ready. But that never happens.

Would really like to ask for some advice to debug this further.

My setup:

openai_key: "my_secret_key" #YOUR_OPENAI_KEY
pinecone_key: "mysecret_key"
pinecone_env: "us-west1-gcp-free" #YOUR_PINECONE_ENVIRONMENT ID
included_domains: "light, weather, climate, media_player" #WHICH DOMAINS TO INCLUDE IN PINECONE DB

  • platform: openassist
    your_name: "My_name" #Optional if you want ChatGPT to know your name.
    mindsdb_model: "gpt4hass" #MINDSDB MODEL NAME.
    mindsdb_cookie: "my_session_cookie" #MINDSDB SESSION COOKIE

    notify_device: "alexa_media_office_echo"

Log:

2023-06-24 11:19:38.242 DEBUG (MainThread) [custom_components.openassist] Setting up OpenAssist 2023-06-24 11:20:07.730 DEBUG (SyncWorker_10) [custom_components.openassist.sensor] Setting up OpenAssistSensor 2023-06-24 11:20:07.730 INFO (SyncWorker_10) [custom_components.openassist.sensor] OpenAssistSensor initialized 2023-06-24 11:20:07.735 DEBUG (SyncWorker_10) [custom_components.openassist.sensor] OpenAssistSensor added to entities 2023-06-24 11:20:07.817 INFO (MainThread) [custom_components.openassist.sensor] OpenAssistSensor added to hass, connecting to OpenAssist update event 2023-06-24 11:20:07.817 INFO (MainThread) [custom_components.openassist.sensor] OpenAssistSensor connected to OpenAssist update event 2023-06-24 11:20:41.633 DEBUG (SyncWorker_8) [custom_components.openassist] Sending GET request 2023-06-24 11:20:43.751 DEBUG (SyncWorker_26) [custom_components.openassist] Sending POST request to URL: https://controller.us-west1-gcp-free.pinecone.io/databases 2023-06-24 11:20:43.751 DEBUG (SyncWorker_26) [custom_components.openassist] POST data: { 2023-06-24 11:20:45.846 DEBUG (SyncWorker_10) [custom_components.openassist] Sending GET request 2023-06-24 11:20:46.373 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:20:51.375 DEBUG (SyncWorker_21) [custom_components.openassist] Sending GET request 2023-06-24 11:20:51.930 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:20:56.933 DEBUG (SyncWorker_5) [custom_components.openassist] Sending GET request 2023-06-24 11:20:57.505 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:02.507 DEBUG (SyncWorker_34) [custom_components.openassist] Sending GET request 2023-06-24 11:21:03.071 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:08.073 DEBUG (SyncWorker_24) [custom_components.openassist] Sending GET request 2023-06-24 11:21:08.641 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:13.641 DEBUG (SyncWorker_27) [custom_components.openassist] Sending GET request 2023-06-24 11:21:14.222 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:19.223 DEBUG (SyncWorker_14) [custom_components.openassist] Sending GET request 2023-06-24 11:21:19.746 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:24.747 DEBUG (SyncWorker_32) [custom_components.openassist] Sending GET request 2023-06-24 11:21:25.285 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:30.286 DEBUG (SyncWorker_3) [custom_components.openassist] Sending GET request 2023-06-24 11:21:30.856 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:35.858 DEBUG (SyncWorker_19) [custom_components.openassist] Sending GET request 2023-06-24 11:21:36.385 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:41.386 DEBUG (SyncWorker_36) [custom_components.openassist] Sending GET request 2023-06-24 11:21:41.966 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:46.970 DEBUG (SyncWorker_36) [custom_components.openassist] Sending GET request 2023-06-24 11:21:47.502 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:52.504 DEBUG (SyncWorker_29) [custom_components.openassist] Sending GET request 2023-06-24 11:21:53.038 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:21:58.038 DEBUG (SyncWorker_23) [custom_components.openassist] Sending GET request 2023-06-24 11:21:58.621 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:03.622 DEBUG (SyncWorker_23) [custom_components.openassist] Sending GET request 2023-06-24 11:22:04.164 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:09.165 DEBUG (SyncWorker_32) [custom_components.openassist] Sending GET request 2023-06-24 11:22:09.734 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:14.735 DEBUG (SyncWorker_36) [custom_components.openassist] Sending GET request 2023-06-24 11:22:15.392 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:20.393 DEBUG (SyncWorker_12) [custom_components.openassist] Sending GET request 2023-06-24 11:22:20.977 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:25.977 DEBUG (SyncWorker_0) [custom_components.openassist] Sending GET request 2023-06-24 11:22:26.506 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:31.507 DEBUG (SyncWorker_31) [custom_components.openassist] Sending GET request 2023-06-24 11:22:32.055 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:37.059 DEBUG (SyncWorker_26) [custom_components.openassist] Sending GET request 2023-06-24 11:22:37.595 DEBUG (MainThread) [custom_components.openassist] Index is not ready yet, waiting for 5 seconds... 2023-06-24 11:22:42.597 DEBUG (SyncWorker_23) [custom_components.openassist] Sending GET request 2023-06-24 11:22:43.127 DEBUG (MainThread) [custom_components.openassist] Index is ready. 2023-06-24 11:22:43.127 DEBUG (MainThread) [custom_components.openassist] Waiting an additional 3 minutes before beginning upsert operations... 2023-06-24 11:25:43.138 DEBUG (SyncWorker_28) [custom_components.openassist] Creating embedding File "/config/custom_components/openassist/__init__.py", line 222, in state_change_handler_pinecone File "/config/custom_components/openassist/__init__.py", line 39, in create_embedding

image
image
image

Integration and platform error

I get this after ages validating my config:

Integration error: openassist - Requirements for openassist not found: ['PyYAML==6.0'].
Platform error sensor.openassist - Requirements for openassist not found: ['PyYAML==6.0'].

can you please fix this? I have PyYAML in /usr/lib/python3.11/site-packages (6.0.1)

Cheers for the great work!

Error doing job: Task exception was never retrieved

Logger: homeassistant
Source: custom_components/openassist/init.py:50
Integration: OpenAssist (documentation)
First occurred: 10:40:37 PM (1 occurrences)
Last logged: 10:40:37 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 960, in json
return complexjson.loads(self.content.decode(encoding), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/simplejson/init.py", line 514, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/simplejson/decoder.py", line 386, in decode
obj, end = self.raw_decode(s)
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/simplejson/decoder.py", line 416, in raw_decode
return self.scan_once(s, idx=_w(s, idx).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/config/custom_components/openassist/init.py", line 150, in state_change_handler_pinecone
response = await hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/openassist/init.py", line 50, in get_request_pinecone
return response.json()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 968, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

KeyError: 'included_domains'

Logger: homeassistant.setup
Source: setup.py:396
First occurred: 1:51:40 PM (1 occurrences)
Last logged: 1:51:40 PM

Unable to prepare setup for platform openassist.sensor: Unable to set up component.

2023-06-11 13:51:40.505 ERROR (MainThread) [homeassistant.setup] Error during setup of component openassist
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 286, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/openassist/init.py", line 88, in async_setup
included_domains = [domain.strip() for domain in conf['included_domains'].split(',')]

KeyError: 'included_domains'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.