OpenAI GPT4 Integration: No API Key Needed!

Introducing the OpenMindsAI Response Sensor for Home Assistant

I’m thrilled to share with you my latest project, a custom integration that lets you bring the power of MindsDB’s machine learning directly into your Home Assistant setup. With this integration, you can bring OpenAI-driven conversations to your dashboard, and potentially more.

The OpenMindsAI is a Home Assistant sensor that allows you to communicate with MindsDB’s machine learning models for predictions based on your input text.

One of the best things about this integration is that it does not require you to have an OpenAI API key. You can simply use MindsDB’s machine learning models to generate responses to your input text.

card

9 Likes

Thanks for this. I’m finding LLMs generally of interest at the moment (who isn’t?!) but I’m struggling to see use cases for home automation other than as a coding assistant. Do you have any insights you could share?

It allows you to feed data to mindsdb.com directly from your homeassistant instance, with the added benefit that they can harvest it as they please.

2 Likes

Yeah so I will be looking at creating a vector database next, the data being my Home Assistant entity registry, I’ll then pass this data to OpenAI’s embedding model. The goal here will be to allow OpenAI to query my data. As a result, unlock device control via OpenAI.

As for the actual use case, It’s really yet to be discovered. I am just learning as I go, providing you guys with all my findings in the hope that it sparks interest and ideas in the community.

2 Likes

So just to clarify, the only data being passed to MindsDB is the Prompt.

“the only data”

If you’re concerned, MindsDBs has open sourced their platform to allow this setup to be run locally.

Whilst that may be the case your component doesn’t: OpenMindsAI/sensor.py at 90f36be7fb2f9e5cf6361bc61057d0a9a776893c · Hassassistant/OpenMindsAI · GitHub

Are you affiliated with MindsDB in any way?

No this component in particular makes use of their cloud platform.
Here, we’re using HTTP API to post requests to our MindsDB cloud instance an retrieve the response.

This can in theory be hosted locally. Here’s their GitHub. This would however require you to bring your own OpenAI API key.

I am not affiliated no.

1 Like

I am getting the following error

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/openmindsai/sensor.py:31
Integration: openmindsai (documentation)
First occurred: 7:22:24 AM (3 occurrences)
Last logged: 7:22:37 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/openmindsai/sensor.py", line 69, in async_ask
    response = await self._hass.async_add_executor_job(ask, self._session_cookie, self._model, new_query)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/openmindsai/sensor.py", line 31, in ask
    response_message = response_json[0]["response"]
KeyError: 0

I’m on 2022.11.4. Does this need a specific version to run?

1 Like

Make sure to change the “model” key in your configuration.yaml to the name of your model in mindsdb.

2 Likes

Missed this in my mad rush to release this to the public.
Good eye Oslo :slight_smile:

3 Likes

Thanks for the release! It works well.

1 Like

So based on the instructions the model name in the yaml should be gpt-4 or 'gpt-4'? As I still can’t get it to work

Edit: nvm. Got it working with the updated read.me

1 Like

session cookie I think needs to start with a “.”

so example:

“.eJw9i8sKgCAUBf_lrl2UlUY… etc”

Hi there, thanks very much for this! All is working as it should for me, but responses seem very slow. I think on average it takes about 40 seconds to get a reply. Is that expected?

This utilises mindsDBs free service, which ultimately means we are using a shared computing resource. So it will be slower compared to other premium available options.

1 Like

What if you use a local ChatGPT or LLaMa

Hi !
Nice job, thx.
I’ve tried to clean the value of the attribute response_text after reading it, but the value come back again …
Why ?

There is a much better method of using the mindsdb website.
This is to log in, do the sql query and show the result.

This can be done with a change to the code as below.

session = requests.Session()
session.post('https://cloud.mindsdb.com/cloud/login', json={
    'email': username,
    'password': password
})

response = session.post('https://cloud.mindsdb.com/api/sql/query', json={'query':
                         'SELECT response from '+model+' WHERE author_username = "mindsdb" AND text= "'+message+'";'})
response_json = response.json()