-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[chatgpt] Initial contribution of the ChatGPT binding #14809
Conversation
Signed-off-by: Kai Kreuzer <[email protected]>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/chatgpt-and-openhab-incl-possibly-alexa-integration/144060/15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredible - thanks! I have provided some quick feedback, but might need another look tomorrow. 🙂
....chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java
Outdated
Show resolved
Hide resolved
....chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java
Outdated
Show resolved
Hide resolved
...enhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java
Outdated
Show resolved
Hide resolved
...enhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties
Outdated
Show resolved
Hide resolved
bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml
Outdated
Show resolved
Hide resolved
....chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java
Outdated
Show resolved
Hide resolved
@kaikreuzer you beat me too it !!! FYI I was also hoping to eventually support local LLMs like the LLaMa variations ( Alpaca, GTP4All, Vicuna) . I have an obsession with running them locally right now ;-) Can't wait to try this out. |
Quick comment after trying it once. Should there be two channels, one for sending a prompt, one for receiving a prompt? Think of it as a "user" channel and a "assistant" channel. Right now the channel state changes from "previous answer -> question -> new answer" over the course of a second, which will make it hard to monitor in rules for reacting to the response which is what matters. The other possibility is to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a lot of fun without not that much code. 🙂
I have added few minor comments below.
...binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java
Outdated
Show resolved
Hide resolved
...enhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java
Outdated
Show resolved
Hide resolved
...g.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java
Outdated
Show resolved
Hide resolved
...enhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Kai Kreuzer <[email protected]>
Thanks for your immensely quick reviews @jlaur and @wborn! I have addressed your comments now.
@digitaldan This is exactly what I did, see here.
If this really happens for you right now, then something is buggy; it isn't the case for me.
I tried Alpaca myself already as well, but decided that those local LLMs are probably rather something for a very few users, so I didn't try to generify this binding to support all kinds of LLMs. |
Signed-off-by: Kai Kreuzer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These SAT issues should also be easy to fix:
...hab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Kai Kreuzer <[email protected]>
@wborn I've addressed your comments. |
Signed-off-by: Kai Kreuzer <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice and clean now! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two very minor comments
|
||
| Name | Type | Description | Default | Required | Advanced | | ||
|-----------------|---------|-----------------------------------------|---------|----------|----------| | ||
| apiKey | text | The API key to be used for the requests | N/A | yes | no | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| apiKey | text | The API key to be used for the requests | N/A | yes | no | | |
| `apiKey` | text | The API key to be used for the requests | N/A | yes | no | |
In a lot of bindings (and I believe this is some sort of unwritten convention) we use code fences for channel/parameter names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in situations where the parameters are mentioned in text, but not within the table - this column is clearly meant for the parameter name, so I do not think it needs to be made explicit by code fences.
Note that our archetype is not suggesting code fences in these tables, see https://github.com/openhab/openhab-core/blob/main/tools/archetype/binding/src/main/resources/archetype-resources/README.md?plain=1#L52-L56.
Ah, sorry did not check the code, i was quickly looking at the logs which look like this
You can see that the channel has both a change event and an update event to "FooBar" which is the command i posted. Then the channel has another change event and update event with the openAI response. I have not looked into this, I guess it could be something i did when setting the item up (although i used the UI to do so) . |
Signed-off-by: Kai Kreuzer <[email protected]>
@jlaur I've fixed the link syntax. |
@digitaldan That's interesting, I do not have the ItemStateUpdatedEvent/ItemStateChangedEvent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
So i just checked another binding that uses the veto policy, its correctly not triggering a Predicted/Updated event when a command is posted. Not sure why this binding would be different, or why you see a Predicted event, but not Updated/Changed like i do. I went ahead and recreated the item in a file, since this is the only obvious difference to me with the rest of my system ( i use files for all my items still), but that did not change the behavior (not surprising) . |
Really looking forward to this! Thank you for your work! |
@kaikreuzer, @digitaldan - I did not merge yet since I'm not sure if you are looking into event issues? Let me know when you think it's fine to be merged. |
@jlaur I just tested it once more and it all behaves as expected for me:
I would therefore say that everything is fine and the PR can be merged. |
@digitaldan I actually now had the same effect (veto not being considered) on my production system. I tracked it down to some issues in the core indeed - when the Main UI creates things through the REST API, it does not set autoUpdatePolicy for the channels, which makes the core use "RECOMMEND" as a policy without looking at a potential information at the channel type definition. I have created openhab/openhab-core#3575, which hopefully fixes this (but faulty channels will need to be recreated). |
Hi @kaikreuzer I'm trying to use it in another language. And everything works fine, if the response is short enough, otherwise I'm getting hieroglyphs. things: Translation: "You are a robot assistant in a Russian family living in Norway. Write a short story about: " items:
translation: "when a child didn't brush their teeth properly and it led to something bad" Response:
In English working fine. Also on the website "https://chat.openai.com/" no hieroglyphs, works fine. Do you have any idea why? |
This looks like some encoding issue. I've checked the code and I couldn't find any obvious error in it - we process strings as UTF-8 and also consider content-type headers, if ChatGPT returns something different. I'd need to deeper debug this with your example. Could you maybe open a dedicated issue about this, so that it can be tracked and isn't lost here on the merged PR? |
@kaikreuzer that's great addition! - sorry a bit late in the game here. Is there any chance to make this binding work with LocalAI? I can help along as I'm the author and an avid openhab user willing to integrate it in my domotic system :) I'm reading from the docs that it is possible to just configure an Also - any plans maybe we can use LocalAI as a TTS engine, or Audio-to-text? Sadly I'm not much into Java, but willing to help in any other way. |
Hey @mudler, thanks for your great work on LocalAI. I didn't yet come across it, but since you say it is API-compatible to OpenAI, it should indeed be very easy to add support for it by making the server url configurable.
I'm not familiar with the possibilities of LocalAI here. On openHAB side, @GiviMAD is the person who is most active in TTS & STT topics, so he might be interested in such new possibilities. |
Hey @mudler, first of all great project. I have an open PR for using whisper.cpp for speech-to-text #15166, maybe we can add there an option to switch between the library and the LocalAI api. But in case you prefer to create a separate add-on to expose in a single place all the capabilities than LocalAI can provide to openHAB, don't hesitate to steal any code in the PR that can help you. I'm planning to create an add-on for using llama.cpp within openHAB but I have no idea how long it could take me, it's great to have this available. BR |
fantastic, had a look already, seems good here! It's enough to allow changing the urls - as it is 1:1 compatible with OpenAI nothing else should be needed and it just "works"
That's looking great, amazing job!
I'd be happy to help but my java-fu it's very limited and my bandwidth for it as well, however there are TTS capabilities (besides voice-to-text) and OpenAI functions as well that can be a nice addition that might be a good fit for OpenHAB. |
Everyone is talking about ChatGPT and thus openHAB also needs a binding for it!
I see an opportunity to personalize the interaction with the home by replacing the "static" announcements that many people use in the home for different purposes. ChatGPT allows bringing in emotions and moods and ensures that it isn't always the very same text, but that everything becomes much more personal and individual.
The examples in the README show how it can be used to have a personal advice for the day based on the weather or to have a morning message announcing the time (e.g. for an alarm clock use case).
There are certainly many more things one could think of and I am looking forward to what the community makes out of it!