Coder Social home page Coder Social logo

openai_response's Introduction

Home Assistant OpenAI GPT4 Response Sensor

(No API Key Needed)

hacs_badge

This custom component for Home Assistant allows you to generate text responses using OpenAI via MindsDB at no expense.

https://www.youtube.com/watch?v=T29k4qsXKPk&ab_channel=HassAssistant

Creating the AI model in MindsDB

1. You will need to create a free account on MindsDB. HERE

2. Once you have an account, head over to the MindsDB editor HERE

3. The SQL query you need to create your AI model.

  • In this example, we're creating an OpenAI GPT4 model.
  • The name I've given this model is gpt4hassio. Change this to whatever you want.
  • You can change the model name if required from gpt-4.
CREATE  MODEL mindsdb.gpt4hassio
PREDICT response
USING
engine  =  'openai',
max_tokens =  6000,
model_name =  'gpt-4',
prompt_template =  '{{text}}';

When you're happy, click Run to execute the query. This will create your model.

4. We need the Session Cookie for MindsDB authentication within Home Assistant.

  • Head to Inspect Element on your web browser while logged into MindsDB
  • Click the Network tab (Step 1).
  • Refresh the webpage (F5)
  • Look for the Home element (Step 2).
  • Find the home source in the network tab
  • Right click on home, select Copy -> Copy as cURL (cmd or bash)
  • Paste the resulting command into a text editor and locate the 'session=' parameter
  • Copy the session cookie, excluding the trailing " or '
  • Paste this into the configuration enter image description here

Home Assistant Integration

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 to HACS. https://github.com/Hassassistant/openmindsai

2. Restart Home Assistant.

2. Add the following lines to your Home Assistant configuration.yaml file:

input_text:
  gpt_prompt:
    initial: ""
    max: 255
## This is the input_text entity you'll use to send prompts.

sensor:
  - platform: openmindsai
    name: "hassio_mindsdb_response"
## Optional. Defaults to hassio_mindsdb_response
    input_name: "gpt_prompt"
## Optional. Defaults to gpt_prompt. This is your input_text name
    session_cookie: ".eJw9i8sKgCAUBf_lrl2UlUY_..."  
## Required. This is your MindsDB Session Cookie
    model: "gpt4hassio" 
## Required. This is your MindsDB Model Name

3. Restart Home Assistant.

Usage

To generate a response from GPT-3, update the service openai_response.openai_input entity with the text you want to send to the model. The generated response will be available as an attribute of the sensor.hassio_mindsdb_response entity.

You can also use a service call to send a request:

service: openai_response.openai_input
data:
  prompt: Tell a joke
  model: gpt4hassio      # Optional, will use the configured or default model if not specified

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer: This project is not affiliated with or endorsed by OpenAI. Use the GPT-4 API at your own risk.

openai_response's People

Contributors

aeleos avatar hassassistant avatar olen avatar

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.