GithubHelp home page GithubHelp logo

openai_response's Introduction

Original Project: openai_response

In addition to having updated the code for access to the new openai APIs, I added the ability to set the maximum number of tokens for each service call.

Installation

1. Copy the openai_response 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.

2. Add the following lines to your Home Assistant configuration.yaml file or create openai.yaml into /packages if you have already configured it, and put:

sensor:
  - platform: openai_response
    api_key: YOUR_OPENAI_API_KEY
    model: "gpt-3.5-turbo" # Optional, defaults to "gpt-3.5-turbo"
    name: "hassio_openai_response" # Optional, defaults to "hassio_openai_response" # Optional
    instructions: "Act like a virtual assistant and provide clear information" # Optional
    max_tokens: 350 # Optional

Replace YOUR_OPENAI_API_KEY with your actual OpenAI API key.

3. Restart Home Assistant.

Usage

Create an input_text.gpt_input entity in Home Assistant to serve as the input for the GPT-3 model. Add the following lines to your configuration.yaml file:

input_text:
  gpt_input:
    name: GPT-3 Input

Note you can also create this input_text via the device helpers page!

If you are creating via YAML, you will need to unpdate input text to developer tools page or restart Home assistant.

To generate a response from GPT-3, update the input_text.gpt_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_openai_response entity.

To use it in your scripts or automations just set it like this (you can also use templates):

service: openai_response.openai_input
data:
  max_tokens: 350
  model: gpt-3.5-turbo
  Instructions: You are a helpful assistant
  prompt: what can you do?

Example

To display the GPT-3 input and response in your Home Assistant frontend, add the following to your ui-lovelace.yaml file or create a card in the Lovelace UI:

type: grid
square: false
columns: 1
cards:
  - type: entities
    entities:
      - entity: input_text.gpt_input
  - type: markdown
    content: '{{ state_attr(''sensor.hassio_openai_response'', ''response_text'') }}'
    title: ChatGPT Response

Now you can type your text in the GPT-3 Input field, and the generated response will be displayed in the response card.

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-3 /4 API at your own risk, and be aware of the API usage costs associated with the OpenAI API.

openai_response's People

Contributors

pajeronda avatar

Watchers

 avatar Kostas Georgiou 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.