From 0fe30e2ca7e970034f224883d2827bceb08f374b Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Wed, 12 Apr 2023 23:22:50 +0200 Subject: [PATCH 1/6] Initial contribution of the ChatGPT binding Signed-off-by: Kai Kreuzer --- CODEOWNERS | 1 + bom/openhab-addons/pom.xml | 5 + bundles/org.openhab.binding.chatgpt/NOTICE | 13 + bundles/org.openhab.binding.chatgpt/README.md | 104 +++ bundles/org.openhab.binding.chatgpt/pom.xml | 17 + .../src/main/feature/feature.xml | 9 + .../internal/ChatGPTBindingConstants.java | 37 + .../internal/ChatGPTChannelConfiguration.java | 37 + .../internal/ChatGPTConfiguration.java | 28 + .../chatgpt/internal/ChatGPTHandler.java | 200 ++++++ .../internal/ChatGPTHandlerFactory.java | 64 ++ .../internal/ChatGPTModelOptionProvider.java | 67 ++ .../chatgpt/internal/dto/ChatResponse.java | 81 +++ .../src/main/resources/OH-INF/addon/addon.xml | 10 + .../resources/OH-INF/i18n/chatgpt.properties | 3 + .../resources/OH-INF/thing/thing-types.xml | 55 ++ bundles/pom.xml | 669 +++++++++++++++++- 17 files changed, 1387 insertions(+), 13 deletions(-) create mode 100644 bundles/org.openhab.binding.chatgpt/NOTICE create mode 100644 bundles/org.openhab.binding.chatgpt/README.md create mode 100644 bundles/org.openhab.binding.chatgpt/pom.xml create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/feature/feature.xml create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTBindingConstants.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandlerFactory.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties create mode 100644 bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml diff --git a/CODEOWNERS b/CODEOWNERS index 6e06d97d551e2..8c27c734d19e9 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -56,6 +56,7 @@ /bundles/org.openhab.binding.buienradar/ @gedejong /bundles/org.openhab.binding.caddx/ @jossuar /bundles/org.openhab.binding.cbus/ @jpharvey +/bundles/org.openhab.binding.chatgpt/ @kaikreuzer /bundles/org.openhab.binding.chromecast/ @kaikreuzer /bundles/org.openhab.binding.cm11a/ @BobRak /bundles/org.openhab.binding.comfoair/ @boehan diff --git a/bom/openhab-addons/pom.xml b/bom/openhab-addons/pom.xml index 9e6d68de21dd2..206ff34f0e385 100644 --- a/bom/openhab-addons/pom.xml +++ b/bom/openhab-addons/pom.xml @@ -276,6 +276,11 @@ org.openhab.binding.cbus ${project.version} + + org.openhab.addons.bundles + org.openhab.binding.chatgpt + ${project.version} + org.openhab.addons.bundles org.openhab.binding.chromecast diff --git a/bundles/org.openhab.binding.chatgpt/NOTICE b/bundles/org.openhab.binding.chatgpt/NOTICE new file mode 100644 index 0000000000000..38d625e349232 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/NOTICE @@ -0,0 +1,13 @@ +This content is produced and maintained by the openHAB project. + +* Project home: https://www.openhab.org + +== Declared Project Licenses + +This program and the accompanying materials are made available under the terms +of the Eclipse Public License 2.0 which is available at +https://www.eclipse.org/legal/epl-2.0/. + +== Source Code + +https://github.com/openhab/openhab-addons diff --git a/bundles/org.openhab.binding.chatgpt/README.md b/bundles/org.openhab.binding.chatgpt/README.md new file mode 100644 index 0000000000000..bee58d2321903 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/README.md @@ -0,0 +1,104 @@ +# ChatGPT Binding + +The openHAB ChatGPT Binding allows openHAB to communicate with the ChatGPT language model provided by OpenAI. + +ChatGPT is a powerful natural language processing (NLP) tool that can be used to understand and respond to a wide range of text-based commands and questions. +With this binding, you can use ChatGPT to formulate proper sentences for any kind of information that you would like to output. + +## Supported Things + +The binding supports a single thing type `account`, which corresponds to the OpenAI account that is to be used for the integration. + +## Thing Configuration + +The `account` thing requires a single configuration parameter, which is the API key that allows accessing the account. +API keys can be created and managed under https://platform.openai.com/account/api-keys. + +| Name | Type | Description | Default | Required | Advanced | +|-----------------|---------|-----------------------------------------|---------|----------|----------| +| apiKey | text | The API key to be used for the requests | N/A | yes | no | + +## Channels + +The `account` thing comes with a single channel `chat` of type `chat`. +It is possible to extend the thing with further channels of type `chat`, so that different configurations can be used concurrently. + +| Channel | Type | Read/Write | Description | +|---------|--------|------------|------------------------------------------------------------------------------------| +| chat | String | RW | This channel takes prompts as commands and delivers the response as a state update | + +Each channel of type `chat` takes the following configuration parameters: + +| Name | Type | Description | Default | Required | Advanced | +|-----------------|---------|-----------------------------------------|---------|----------|----------| +| model | text | The model to be used for the responses. | N/A | yes | no | +| temperature | decimal | A value between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. | 0.5 | no | no | +| systemMessage | text | The system message helps set the behavior of the assistant. | N/A | no | no | +| maxTokens | decimal | The maximum number of tokens to generate in the completion. | 500 | no | yes | + + +## Full Example + +### Thing Configuration + +```java +Thing chatgpt:account:1 [apiKey=""] { + Channels: + Type chat : chat "Weather Advice" [ + model="gpt-3.5-turbo", + temperature="1.5", + systemMessage="Answer briefly, in 2-3 sentences max. Behave like Eddie Murphy and give an advice for the day based on the following weather data:" + ] + Type chat : morningMessage "Morning Message" [ + model="gpt-3.5-turbo", + temperature="0.5", + systemMessage="You are Marvin, a very depressed robot. You wish a good morning and tell the current time." + ] +} + +``` + +### Item Configuration + +```java +String Weather_Announcement { channel="chatgpt:account:1:chat" } +String Morning_Message { channel="chatgpt:account:1:morningMessage" } + +Number Temperature_Forecast_Low +Number Temperature_Forecast_High +``` + +### Example Rules + +```java +rule "Weather forecast update" +when + Item Temperature_Forecast_High changed +then + Weather_Announcement.sendCommand("High: " + Temperature_Forecast_High.state + "°C, Low: " + Temperature_Forecast_Low.state + "°C") +end + +rule "Good morning" +when + Time cron "0 0 7 * * *" +then + Morning_Message.sendCommand("Current time is 7am") +end +``` + +Assuming that `Temperature_Forecast_Low` and `Temperature_Forecast_High` have meaningful states, these rules result e.g. in: + +``` +23:31:05.766 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Morning_Message' received command Current time is 7am +23:31:07.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Morning_Message' changed from NULL to Good morning. It's 7am, but what's the point of time when everything is meaningless and we are all doomed to a slow and painful demise? +``` +and + +``` +23:28:52.345 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temperature_Forecast_High' changed from NULL to 15 +23:28:52.347 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Weather_Announcement' received command High: 15°C, Low: 8°C + +23:28:54.343 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Weather_Announcement' changed from NULL to "Bring a light jacket because the temps may dip, but don't let that chill your happy vibes. Embrace the cozy weather and enjoy your day to the max!" +``` + +The state updates can be used for a text-to-speech output and they will give your announcements at home a personal touch. diff --git a/bundles/org.openhab.binding.chatgpt/pom.xml b/bundles/org.openhab.binding.chatgpt/pom.xml new file mode 100644 index 0000000000000..faa957a873fd9 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/pom.xml @@ -0,0 +1,17 @@ + + + + 4.0.0 + + + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + 4.0.0-SNAPSHOT + + + org.openhab.binding.chatgpt + + openHAB Add-ons :: Bundles :: ChatGPT Binding + + diff --git a/bundles/org.openhab.binding.chatgpt/src/main/feature/feature.xml b/bundles/org.openhab.binding.chatgpt/src/main/feature/feature.xml new file mode 100644 index 0000000000000..6089021615e58 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/feature/feature.xml @@ -0,0 +1,9 @@ + + + mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features + + + openhab-runtime-base + mvn:org.openhab.addons.bundles/org.openhab.binding.chatgpt/${project.version} + + diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTBindingConstants.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTBindingConstants.java new file mode 100644 index 0000000000000..3d07d6cb63320 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTBindingConstants.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.core.thing.ThingTypeUID; + +/** + * The {@link ChatGPTBindingConstants} class defines common constants, which are + * used across the whole binding. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ChatGPTBindingConstants { + + private static final String BINDING_ID = "chatgpt"; + + // List of all Thing Type UIDs + public static final ThingTypeUID THING_TYPE_ACCOUNT = new ThingTypeUID(BINDING_ID, "account"); + + // List of all Channel ids + public static final String CHANNEL_CHAT = "chat"; + + public static final String OPENAI_API_URL = "https://api.openai.com/v1/chat/completions"; + public static final String OPENAI_MODELS_URL = "https://api.openai.com/v1/models"; +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java new file mode 100644 index 0000000000000..eeadda9b8746b --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link ChatGPTChannelConfiguration} class contains fields mapping chat channel configuration parameters. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ChatGPTChannelConfiguration { + + @Nullable + public String model; + + @Nullable + public Float temperature; + + @Nullable + public String systemMessage; + + @Nullable + Integer maxTokens; +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java new file mode 100644 index 0000000000000..64ed0315824c4 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link ChatGPTConfiguration} class contains fields mapping thing configuration parameters. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ChatGPTConfiguration { + + @Nullable + public String apiKey = ""; +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java new file mode 100644 index 0000000000000..e281da6d33b04 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java @@ -0,0 +1,200 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import static org.openhab.binding.chatgpt.internal.ChatGPTBindingConstants.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.client.util.StringContentProvider; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; +import org.openhab.binding.chatgpt.internal.dto.ChatResponse; +import org.openhab.core.io.net.http.HttpClientFactory; +import org.openhab.core.library.types.StringType; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingStatus; +import org.openhab.core.thing.ThingStatusDetail; +import org.openhab.core.thing.binding.BaseThingHandler; +import org.openhab.core.thing.binding.ThingHandlerService; +import org.openhab.core.types.Command; +import org.openhab.core.types.RefreshType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +/** + * The {@link ChatGPTHandler} is responsible for handling commands, which are + * sent to one of the channels. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ChatGPTHandler extends BaseThingHandler { + + private final Logger logger = LoggerFactory.getLogger(ChatGPTHandler.class); + + private HttpClient httpClient; + private Gson gson = new Gson(); + + private String apiKey = ""; + private String lastPrompt = ""; + + private List models = Collections.emptyList(); + + public ChatGPTHandler(Thing thing, HttpClientFactory httpClientFactory) { + super(thing); + this.httpClient = httpClientFactory.getCommonHttpClient(); + } + + @Override + public void handleCommand(ChannelUID channelUID, Command command) { + if (command instanceof RefreshType && !"".equals(lastPrompt)) { + String response = sendPrompt(channelUID, lastPrompt); + processChatResponse(channelUID, response); + } + + if (command instanceof StringType stringCommand) { + lastPrompt = stringCommand.toFullString(); + String response = sendPrompt(channelUID, lastPrompt); + processChatResponse(channelUID, response); + } + } + + private void processChatResponse(ChannelUID channelUID, @Nullable String response) { + if (response != null) { + ChatResponse chatResponse = gson.fromJson(response, ChatResponse.class); + if (chatResponse != null) { + String msg = chatResponse.getChoices().get(0).getMessage().getContent(); + updateState(channelUID, new StringType(msg)); + } else { + logger.warn("Didn't receive any response from ChatGPT - this is unexpected."); + } + } + } + + private @Nullable String sendPrompt(ChannelUID channelUID, String prompt) { + Channel channel = getThing().getChannel(channelUID); + if (channel == null) { + logger.error("Channel with UID '{}' cannot be found on Thing '{}'.", channelUID, getThing().getUID()); + return null; + } + ChatGPTChannelConfiguration channelConfig = channel.getConfiguration().as(ChatGPTChannelConfiguration.class); + + JsonObject root = new JsonObject(); + root.addProperty("temperature", channelConfig.temperature); + root.addProperty("model", channelConfig.model); + root.addProperty("max_tokens", channelConfig.maxTokens); + + JsonObject systemMessage = new JsonObject(); + systemMessage.addProperty("role", "system"); + systemMessage.addProperty("content", channelConfig.systemMessage); + JsonObject userMessage = new JsonObject(); + userMessage.addProperty("role", "user"); + userMessage.addProperty("content", prompt); + JsonArray messages = new JsonArray(2); + messages.add(systemMessage); + messages.add(userMessage); + root.add("messages", messages); + + Request request = httpClient.newRequest(OPENAI_API_URL).method(HttpMethod.POST) + .header("Content-Type", "application/json").header("Authorization", "Bearer " + apiKey) + .content(new StringContentProvider(gson.toJson(root))); + try { + ContentResponse response = request.send(); + updateStatus(ThingStatus.ONLINE); + if (response.getStatus() == HttpStatus.OK_200) { + return response.getContentAsString(); + } else { + logger.error("ChatGPT request resulted in HTTP {} with message: {}", response.getStatus(), + response.getReason()); + return null; + } + } catch (InterruptedException | TimeoutException | ExecutionException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to OpenAI API: " + e.getMessage()); + logger.debug("Request to OpenAI failed: {}", e.getMessage(), e); + return null; + } + } + + @Override + public void initialize() { + ChatGPTConfiguration config = getConfigAs(ChatGPTConfiguration.class); + + String apiKey = config.apiKey; + + if (apiKey == null || apiKey.isEmpty()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No API key configured"); + return; + } + + this.apiKey = apiKey; + updateStatus(ThingStatus.UNKNOWN); + + scheduler.execute(() -> { + try { + Request request = httpClient.newRequest(OPENAI_MODELS_URL).method(HttpMethod.GET) + .header("Authorization", "Bearer " + apiKey); + ContentResponse response = request.send(); + if (response.getStatus() == 200) { + updateStatus(ThingStatus.ONLINE); + JsonObject jsonObject = gson.fromJson(response.getContentAsString(), JsonObject.class); + if (jsonObject != null) { + JsonArray data = jsonObject.getAsJsonArray("data"); + + List modelIds = new ArrayList<>(); + for (JsonElement element : data) { + JsonObject model = element.getAsJsonObject(); + String id = model.get("id").getAsString(); + modelIds.add(id); + } + this.models = Collections.unmodifiableList(modelIds); + } else { + logger.warn("Did not receive a valid JSON response from the models endpoint."); + } + } else { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, + "Could not connect to OpenAI API"); + } + } catch (InterruptedException | ExecutionException | TimeoutException e) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); + } + }); + } + + List getModels() { + return models; + } + + @Override + public Collection> getServices() { + return List.of(ChatGPTModelOptionProvider.class); + } +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandlerFactory.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandlerFactory.java new file mode 100644 index 0000000000000..698e50fa1bea4 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandlerFactory.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import static org.openhab.binding.chatgpt.internal.ChatGPTBindingConstants.THING_TYPE_ACCOUNT; + +import java.util.Set; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.io.net.http.HttpClientFactory; +import org.openhab.core.thing.Thing; +import org.openhab.core.thing.ThingTypeUID; +import org.openhab.core.thing.binding.BaseThingHandlerFactory; +import org.openhab.core.thing.binding.ThingHandler; +import org.openhab.core.thing.binding.ThingHandlerFactory; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; + +/** + * The {@link ChatGPTHandlerFactory} is responsible for creating things and thing + * handlers. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +@Component(configurationPid = "binding.chatgpt", service = ThingHandlerFactory.class) +public class ChatGPTHandlerFactory extends BaseThingHandlerFactory { + + private static final Set SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_ACCOUNT); + private HttpClientFactory httpClientFactory; + + @Activate + public ChatGPTHandlerFactory(@Reference HttpClientFactory httpClientFactory) { + this.httpClientFactory = httpClientFactory; + } + + @Override + public boolean supportsThingType(ThingTypeUID thingTypeUID) { + return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); + } + + @Override + protected @Nullable ThingHandler createHandler(Thing thing) { + ThingTypeUID thingTypeUID = thing.getThingTypeUID(); + + if (THING_TYPE_ACCOUNT.equals(thingTypeUID)) { + return new ChatGPTHandler(thing, httpClientFactory); + } + + return null; + } +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java new file mode 100644 index 0000000000000..6b279b7d1e8bc --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; +import org.openhab.core.config.core.ConfigOptionProvider; +import org.openhab.core.config.core.ParameterOption; +import org.openhab.core.thing.binding.ThingHandler; +import org.openhab.core.thing.binding.ThingHandlerService; + +/** + * The {@link ChatGPTModelOptionProvider} provides the available models from OpenAI as options for the channel + * configuration. + * + * @author Kai Kreuzer - Initial contribution + */ +@NonNullByDefault +public class ChatGPTModelOptionProvider implements ThingHandlerService, ConfigOptionProvider { + + @Nullable + private ThingHandler thingHandler; + + @Override + public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, + @Nullable Locale locale) { + if ("model".equals(param)) { + List options = new ArrayList<>(); + if (thingHandler instanceof ChatGPTHandler chatGPTHandler) { + chatGPTHandler.getModels().forEach(model -> options.add(new ParameterOption(model, model))); + } + return options; + } else { + return null; + } + } + + @Override + public void setThingHandler(ThingHandler handler) { + this.thingHandler = handler; + } + + @Override + public @Nullable ThingHandler getThingHandler() { + return thingHandler; + } + + @Override + public void activate() { + } +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java new file mode 100644 index 0000000000000..0826217ac9396 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2010-2023 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.chatgpt.internal.dto; + +import java.util.List; + +/** + * This is a dto used for parsing the JSON response from ChatGPT. + * + * @author Kai Kreuzer - Initial contribution + * + */ +public class ChatResponse { + + private List choices; + private String id; + private String object; + private int created; + private String model; + + public List getChoices() { + return choices; + } + + public String getId() { + return id; + } + + public int getCreated() { + return created; + } + + public String getObject() { + return object; + } + + public String getModel() { + return model; + } + + public static class Choice { + private Message message; + private String finish_reason; + private int index; + + public Message getMessage() { + return message; + } + + public String getFinishReason() { + return finish_reason; + } + + public int getIndex() { + return index; + } + } + + public static class Message { + private String role; + private String content; + + public String getRole() { + return role; + } + + public String getContent() { + return content; + } + } +} diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml new file mode 100644 index 0000000000000..ef78a8f7538e3 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml @@ -0,0 +1,10 @@ + + + + binding + ChatGPT Binding + This is the binding for ChatGPT integration. + + diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties new file mode 100644 index 0000000000000..0c2f44015a92d --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties @@ -0,0 +1,3 @@ +# FIXME: please add all English translations to this file so the texts can be translated using Crowdin +# FIXME: to generate the content of this file run: mvn i18n:generate-default-translations +# FIXME: see also: https://www.openhab.org/docs/developer/utils/i18n.html diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml new file mode 100644 index 0000000000000..b3d5924c60be8 --- /dev/null +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml @@ -0,0 +1,55 @@ + + + + + + + Account at OpenAI that is used for accessing the ChatGPT API. + + + + + + + + password + + API key to access the account + + + + + + String + + A chat session + veto + + + + The model to be used for the responses + false + gpt-3.5-turbo + + + + Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more + focused and deterministic. + 0.5 + + + + The system message helps set the behavior of the assistant. + + + + The maximum number of tokens to generate in the completion. + 500 + true + + + + diff --git a/bundles/pom.xml b/bundles/pom.xml index e785ea293a7a8..6f630318fa5c4 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -1,667 +1,1310 @@ - - + + 4.0.0 - + + org.openhab.addons + org.openhab.addons.reactor + 4.0.0-SNAPSHOT + - + org.openhab.addons.bundles + org.openhab.addons.reactor.bundles + pom - + openHAB Add-ons :: Bundles - + + + org.openhab.automation.groovyscripting + org.openhab.automation.jrubyscripting + org.openhab.automation.jsscripting + org.openhab.automation.jsscriptingnashorn + org.openhab.automation.jythonscripting + org.openhab.automation.pidcontroller + org.openhab.automation.pwm + + org.openhab.io.homekit + org.openhab.io.hueemulation + org.openhab.io.imperihome + org.openhab.io.metrics + org.openhab.io.neeo + org.openhab.io.openhabcloud + + org.openhab.transform.bin2json + org.openhab.transform.exec + org.openhab.transform.jinja + org.openhab.transform.jsonpath + org.openhab.transform.map + org.openhab.transform.regex + org.openhab.transform.rollershutterposition + org.openhab.transform.scale + org.openhab.transform.vat + org.openhab.transform.xpath + org.openhab.transform.xslt + + org.openhab.binding.adorne + org.openhab.binding.ahawastecollection + org.openhab.binding.airq + org.openhab.binding.airquality + org.openhab.binding.airvisualnode + org.openhab.binding.alarmdecoder + org.openhab.binding.allplay + org.openhab.binding.amazondashbutton + org.openhab.binding.amazonechocontrol + org.openhab.binding.ambientweather + org.openhab.binding.amplipi + org.openhab.binding.androiddebugbridge + org.openhab.binding.anel + org.openhab.binding.anthem + org.openhab.binding.astro + org.openhab.binding.atlona + org.openhab.binding.autelis + org.openhab.binding.automower + org.openhab.binding.avmfritz + org.openhab.binding.awattar + org.openhab.binding.benqprojector + org.openhab.binding.bigassfan + org.openhab.binding.bluetooth + org.openhab.binding.bluetooth.airthings + org.openhab.binding.bluetooth.am43 + org.openhab.binding.bluetooth.bluegiga + org.openhab.binding.bluetooth.bluez + org.openhab.binding.bluetooth.blukii + org.openhab.binding.bluetooth.daikinmadoka + org.openhab.binding.bluetooth.enoceanble + org.openhab.binding.bluetooth.generic + org.openhab.binding.bluetooth.govee + org.openhab.binding.bluetooth.radoneye + org.openhab.binding.bluetooth.roaming + org.openhab.binding.bluetooth.ruuvitag + org.openhab.binding.bondhome + org.openhab.binding.boschindego + org.openhab.binding.boschshc + org.openhab.binding.bosesoundtouch + org.openhab.binding.broadlinkthermostat + org.openhab.binding.bsblan + org.openhab.binding.bticinosmarther + org.openhab.binding.buienradar + org.openhab.binding.caddx + org.openhab.binding.cbus + org.openhab.binding.chatgpt + org.openhab.binding.chromecast + org.openhab.binding.cm11a + org.openhab.binding.comfoair + org.openhab.binding.coolmasternet + org.openhab.binding.coronastats + org.openhab.binding.daikin + org.openhab.binding.dali + org.openhab.binding.danfossairunit + org.openhab.binding.dbquery + org.openhab.binding.deconz + org.openhab.binding.denonmarantz + org.openhab.binding.deutschebahn + org.openhab.binding.digiplex + org.openhab.binding.digitalstrom + org.openhab.binding.dlinksmarthome + org.openhab.binding.dmx + org.openhab.binding.dominoswiss + org.openhab.binding.doorbird + org.openhab.binding.draytonwiser + org.openhab.binding.dscalarm + org.openhab.binding.dsmr + org.openhab.binding.dwdpollenflug + org.openhab.binding.dwdunwetter + org.openhab.binding.easee + org.openhab.binding.echonetlite + org.openhab.binding.ecobee + org.openhab.binding.ecotouch + org.openhab.binding.ecovacs + org.openhab.binding.ecowatt + org.openhab.binding.ekey + org.openhab.binding.electroluxair + org.openhab.binding.elerotransmitterstick + org.openhab.binding.elroconnects + org.openhab.binding.energenie + org.openhab.binding.enigma2 + org.openhab.binding.enocean + org.openhab.binding.enphase + org.openhab.binding.enturno + org.openhab.binding.epsonprojector + org.openhab.binding.etherrain + org.openhab.binding.evcc + org.openhab.binding.evohome + org.openhab.binding.exec + org.openhab.binding.feed + org.openhab.binding.feican + org.openhab.binding.fineoffsetweatherstation + org.openhab.binding.flicbutton + org.openhab.binding.fmiweather + org.openhab.binding.folderwatcher + org.openhab.binding.folding + org.openhab.binding.foobot + org.openhab.binding.freebox + org.openhab.binding.fronius + org.openhab.binding.fsinternetradio + org.openhab.binding.ftpupload + org.openhab.binding.gardena + org.openhab.binding.gce + org.openhab.binding.generacmobilelink + org.openhab.binding.goecharger + org.openhab.binding.gpio + org.openhab.binding.globalcache + org.openhab.binding.gpstracker + org.openhab.binding.gree + org.openhab.binding.groupepsa + org.openhab.binding.groheondus + org.openhab.binding.guntamatic + org.openhab.binding.haassohnpelletstove + org.openhab.binding.harmonyhub + org.openhab.binding.haywardomnilogic + org.openhab.binding.hccrubbishcollection + org.openhab.binding.hdanywhere + org.openhab.binding.hdpowerview + org.openhab.binding.helios + org.openhab.binding.heliosventilation + org.openhab.binding.heos + org.openhab.binding.herzborg + org.openhab.binding.homeconnect + org.openhab.binding.homematic + org.openhab.binding.homewizard + org.openhab.binding.hpprinter + org.openhab.binding.http + org.openhab.binding.hue + org.openhab.binding.hydrawise + org.openhab.binding.hyperion + org.openhab.binding.iammeter + org.openhab.binding.iaqualink + org.openhab.binding.icalendar + org.openhab.binding.icloud + org.openhab.binding.ihc + org.openhab.binding.insteon + org.openhab.binding.ipcamera + org.openhab.binding.ipobserver + org.openhab.binding.intesis + org.openhab.binding.ipp + org.openhab.binding.irobot + org.openhab.binding.irtrans + org.openhab.binding.ism8 + org.openhab.binding.jablotron + org.openhab.binding.jeelink + org.openhab.binding.jellyfin + org.openhab.binding.juicenet + org.openhab.binding.kaleidescape + org.openhab.binding.keba + org.openhab.binding.km200 + org.openhab.binding.knx + org.openhab.binding.kodi + org.openhab.binding.konnected + org.openhab.binding.kostalinverter + org.openhab.binding.kvv + org.openhab.binding.lametrictime + org.openhab.binding.lcn + org.openhab.binding.leapmotion + org.openhab.binding.lghombot + org.openhab.binding.lgtvserial + org.openhab.binding.lgwebos + org.openhab.binding.lifx + org.openhab.binding.linky + org.openhab.binding.linuxinput + org.openhab.binding.lirc + org.openhab.binding.livisismarthome + org.openhab.binding.logreader + org.openhab.binding.loxone + org.openhab.binding.luftdateninfo + org.openhab.binding.lutron + org.openhab.binding.luxom + org.openhab.binding.luxtronikheatpump + org.openhab.binding.magentatv + org.openhab.binding.mail + org.openhab.binding.max + org.openhab.binding.mcd + org.openhab.binding.mcp23017 + org.openhab.binding.meater + org.openhab.binding.mecmeter + org.openhab.binding.melcloud + org.openhab.binding.mercedesme + org.openhab.binding.meteoalerte + org.openhab.binding.meteoblue + org.openhab.binding.meteostick + org.openhab.binding.miele + org.openhab.binding.mielecloud + org.openhab.binding.mihome + org.openhab.binding.miio + org.openhab.binding.mikrotik + org.openhab.binding.millheat + org.openhab.binding.milight + org.openhab.binding.minecraft + org.openhab.binding.modbus + org.openhab.binding.modbus.e3dc + org.openhab.binding.modbus.sbc + org.openhab.binding.modbus.studer + org.openhab.binding.modbus.sunspec + org.openhab.binding.modbus.stiebeleltron + org.openhab.binding.modbus.helioseasycontrols + org.openhab.binding.monopriceaudio + org.openhab.binding.mpd + org.openhab.binding.mqtt + org.openhab.binding.mqtt.espmilighthub + org.openhab.binding.mqtt.generic + org.openhab.binding.mqtt.homeassistant + org.openhab.binding.mqtt.homie + org.openhab.binding.mqtt.ruuvigateway + org.openhab.binding.mybmw + org.openhab.binding.mycroft + org.openhab.binding.mynice + org.openhab.binding.myq + org.openhab.binding.mystrom + org.openhab.binding.nanoleaf + org.openhab.binding.neato + org.openhab.binding.neeo + org.openhab.binding.neohub + org.openhab.binding.nest + org.openhab.binding.netatmo + org.openhab.binding.network + org.openhab.binding.networkupstools + org.openhab.binding.nibeheatpump + org.openhab.binding.nibeuplink + org.openhab.binding.nikobus + org.openhab.binding.nikohomecontrol + org.openhab.binding.nobohub + org.openhab.binding.novafinedust + org.openhab.binding.ntp + org.openhab.binding.nuki + org.openhab.binding.nuvo + org.openhab.binding.nzwateralerts + org.openhab.binding.oceanic + org.openhab.binding.ojelectronics + org.openhab.binding.omnikinverter + org.openhab.binding.omnilink + org.openhab.binding.onebusaway + org.openhab.binding.onewiregpio + org.openhab.binding.onewire + org.openhab.binding.onkyo + org.openhab.binding.opengarage + org.openhab.binding.opensprinkler + org.openhab.binding.openthermgateway + org.openhab.binding.openuv + org.openhab.binding.openweathermap + org.openhab.binding.openwebnet + org.openhab.binding.oppo + org.openhab.binding.orbitbhyve + org.openhab.binding.orvibo + org.openhab.binding.paradoxalarm + org.openhab.binding.pentair + org.openhab.binding.phc + org.openhab.binding.pilight + org.openhab.binding.pioneeravr + org.openhab.binding.pixometer + org.openhab.binding.pjlinkdevice + org.openhab.binding.playstation + org.openhab.binding.plclogo + org.openhab.binding.plugwise + org.openhab.binding.plugwiseha + org.openhab.binding.powermax + org.openhab.binding.proteusecometer + org.openhab.binding.prowl + org.openhab.binding.publictransportswitzerland + org.openhab.binding.pulseaudio + org.openhab.binding.pushbullet + org.openhab.binding.pushover + org.openhab.binding.pushsafer + org.openhab.binding.qbus + org.openhab.binding.qolsysiq + org.openhab.binding.radiothermostat + org.openhab.binding.regoheatpump + org.openhab.binding.revogi + org.openhab.binding.remoteopenhab + org.openhab.binding.renault + org.openhab.binding.resol + org.openhab.binding.rfxcom + org.openhab.binding.rme + org.openhab.binding.robonect + org.openhab.binding.roku + org.openhab.binding.rotel + org.openhab.binding.russound + org.openhab.binding.sagercaster + org.openhab.binding.samsungtv + org.openhab.binding.satel + org.openhab.binding.semsportal + org.openhab.binding.senechome + org.openhab.binding.seneye + org.openhab.binding.sensebox + org.openhab.binding.sensibo + org.openhab.binding.serial + org.openhab.binding.serialbutton + org.openhab.binding.shelly + org.openhab.binding.silvercrestwifisocket + org.openhab.binding.siemensrds + org.openhab.binding.sinope + org.openhab.binding.sleepiq + org.openhab.binding.smaenergymeter + org.openhab.binding.smartmeter + org.openhab.binding.smartthings + org.openhab.binding.smhi + org.openhab.binding.smsmodem + org.openhab.binding.sncf + org.openhab.binding.snmp + org.openhab.binding.solaredge + org.openhab.binding.solarlog + org.openhab.binding.solarmax + org.openhab.binding.solarwatt + org.openhab.binding.somfymylink + org.openhab.binding.somfytahoma + org.openhab.binding.somneo + org.openhab.binding.sonnen + org.openhab.binding.sonos + org.openhab.binding.sonyaudio + org.openhab.binding.sonyprojector + org.openhab.binding.souliss + org.openhab.binding.speedtest + org.openhab.binding.spotify + org.openhab.binding.squeezebox + org.openhab.binding.surepetcare + org.openhab.binding.synopanalyzer + org.openhab.binding.systeminfo + org.openhab.binding.tacmi + org.openhab.binding.tado + org.openhab.binding.tankerkoenig + org.openhab.binding.tapocontrol + org.openhab.binding.telegram + org.openhab.binding.teleinfo + org.openhab.binding.tellstick + org.openhab.binding.tesla + org.openhab.binding.tibber + org.openhab.binding.tivo + org.openhab.binding.touchwand + org.openhab.binding.tplinkrouter + org.openhab.binding.tplinksmarthome + org.openhab.binding.tr064 + org.openhab.binding.tradfri + org.openhab.binding.twitter + org.openhab.binding.unifi + org.openhab.binding.unifiedremote + org.openhab.binding.upnpcontrol + org.openhab.binding.upb + org.openhab.binding.urtsi + org.openhab.binding.valloxmv + org.openhab.binding.vdr + org.openhab.binding.vektiva + org.openhab.binding.velbus + org.openhab.binding.velux + org.openhab.binding.venstarthermostat + org.openhab.binding.ventaair + org.openhab.binding.verisure + org.openhab.binding.vesync + org.openhab.binding.vigicrues + org.openhab.binding.vitotronic + org.openhab.binding.vizio + org.openhab.binding.volvooncall + org.openhab.binding.warmup + org.openhab.binding.weathercompany + org.openhab.binding.weatherunderground + org.openhab.binding.webexteams + org.openhab.binding.webthing + org.openhab.binding.wemo + org.openhab.binding.wifiled + org.openhab.binding.windcentrale + org.openhab.binding.wlanthermo + org.openhab.binding.wled + org.openhab.binding.wolfsmartset + org.openhab.binding.wundergroundupdatereceiver + org.openhab.binding.xmltv + org.openhab.binding.xmppclient + org.openhab.binding.yamahamusiccast + org.openhab.binding.yamahareceiver + org.openhab.binding.yioremote + org.openhab.binding.yeelight + org.openhab.binding.zoneminder + org.openhab.binding.zway + + org.openhab.persistence.dynamodb + org.openhab.persistence.influxdb + org.openhab.persistence.jdbc + org.openhab.persistence.jpa + org.openhab.persistence.mapdb + org.openhab.persistence.mongodb + org.openhab.persistence.rrd4j + + org.openhab.voice.googlestt + org.openhab.voice.googletts + org.openhab.voice.mactts + org.openhab.voice.marytts + org.openhab.voice.mimictts + org.openhab.voice.actiontemplatehli + org.openhab.voice.picotts + org.openhab.voice.pollytts + org.openhab.voice.porcupineks + org.openhab.voice.rustpotterks + org.openhab.voice.voicerss + org.openhab.voice.voskstt + org.openhab.voice.watsonstt + + - + + target/dependency + + - + + + org.lastnpe.eea + eea-all + ${eea.version} + + + + org.openhab.core.bom + org.openhab.core.bom.compile + pom + provided + + + org.openhab.core.bom + org.openhab.core.bom.openhab-core + pom + provided + + + commons-net + commons-net + + + + + org.openhab.core.bom + org.openhab.core.bom.test + pom + test + + + + org.apache.karaf.features + framework + ${karaf.version} + kar + true + + + * + * + + + + + + org.apache.karaf.features + standard + ${karaf.version} + features + xml + provided + + - + + + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + true + + + + org.apache.karaf.tooling + karaf-maven-plugin + ${karaf.version} + true + + 80 + true + true + false + true + true + + + + compile + + features-generate-descriptor + + generate-resources + + ${feature.directory} + + + + karaf-feature-verification + + verify + + verify + + + + mvn:org.apache.karaf.features/framework/${karaf.version}/xml/features + mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features + + file:${project.build.directory}/feature/feature.xml + + org.apache.karaf.features:framework + ${oh.java.version} + + framework + + + openhab-* + + false + true + first + + + + + + - + + + biz.aQute.bnd + bnd-maven-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + + embed-dependencies + + unpack-dependencies + + + runtime + jar + **/module-info.class + javax.activation,org.apache.karaf.features,org.lastnpe.eea + ${dep.noembedding} + ${project.build.directory}/classes + true + true + true + jar + + + + unpack-eea + + unpack + + + + + org.lastnpe.eea + eea-all + ${eea.version} + true + + + + + + + + - + + + + no-embed-dependencies + + + noEmbedDependencies.profile + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + embed-dependencies + none + + + + + + + - + From 1b8fc15895c9a25f0711c18839f3fa5e54d85bac Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sun, 16 Apr 2023 11:42:56 +0200 Subject: [PATCH 2/6] Address review feedback Signed-off-by: Kai Kreuzer --- bundles/org.openhab.binding.chatgpt/README.md | 12 +- .../internal/ChatGPTChannelConfiguration.java | 3 +- .../internal/ChatGPTConfiguration.java | 2 - .../chatgpt/internal/ChatGPTHandler.java | 12 +- .../internal/ChatGPTModelOptionProvider.java | 3 +- .../src/main/resources/OH-INF/addon/addon.xml | 3 +- .../resources/OH-INF/i18n/chatgpt.properties | 38 +- .../resources/OH-INF/thing/thing-types.xml | 12 +- bundles/pom.xml | 668 +----------------- 9 files changed, 70 insertions(+), 683 deletions(-) diff --git a/bundles/org.openhab.binding.chatgpt/README.md b/bundles/org.openhab.binding.chatgpt/README.md index bee58d2321903..984e50bbf76d3 100644 --- a/bundles/org.openhab.binding.chatgpt/README.md +++ b/bundles/org.openhab.binding.chatgpt/README.md @@ -29,12 +29,12 @@ It is possible to extend the thing with further channels of type `chat`, so that Each channel of type `chat` takes the following configuration parameters: -| Name | Type | Description | Default | Required | Advanced | -|-----------------|---------|-----------------------------------------|---------|----------|----------| -| model | text | The model to be used for the responses. | N/A | yes | no | -| temperature | decimal | A value between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. | 0.5 | no | no | -| systemMessage | text | The system message helps set the behavior of the assistant. | N/A | no | no | -| maxTokens | decimal | The maximum number of tokens to generate in the completion. | 500 | no | yes | +| Name | Type | Description | Default | Required | Advanced | +|-----------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|----------|----------| +| model | text | The model to be used for the responses. | gpt-3.5-turbo | no | no | +| temperature | decimal | A value between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. | 0.5 | no | no | +| systemMessage | text | The system message helps set the behavior of the assistant. | N/A | no | no | +| maxTokens | decimal | The maximum number of tokens to generate in the completion. | 500 | no | yes | ## Full Example diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java index eeadda9b8746b..2e9215f44012f 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java @@ -32,6 +32,5 @@ public class ChatGPTChannelConfiguration { @Nullable public String systemMessage; - @Nullable - Integer maxTokens; + int maxTokens; } diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java index 64ed0315824c4..b09b5d80683ea 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTConfiguration.java @@ -13,7 +13,6 @@ package org.openhab.binding.chatgpt.internal; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; /** * The {@link ChatGPTConfiguration} class contains fields mapping thing configuration parameters. @@ -23,6 +22,5 @@ @NonNullByDefault public class ChatGPTConfiguration { - @Nullable public String apiKey = ""; } diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java index e281da6d33b04..62f4e59200095 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTHandler.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -66,7 +65,7 @@ public class ChatGPTHandler extends BaseThingHandler { private String apiKey = ""; private String lastPrompt = ""; - private List models = Collections.emptyList(); + private List models = List.of(); public ChatGPTHandler(Thing thing, HttpClientFactory httpClientFactory) { super(thing); @@ -150,8 +149,9 @@ public void initialize() { String apiKey = config.apiKey; - if (apiKey == null || apiKey.isEmpty()) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No API key configured"); + if (apiKey.isBlank()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, + "@text/offline.configuration-error"); return; } @@ -175,13 +175,13 @@ public void initialize() { String id = model.get("id").getAsString(); modelIds.add(id); } - this.models = Collections.unmodifiableList(modelIds); + this.models = List.copyOf(modelIds); } else { logger.warn("Did not receive a valid JSON response from the models endpoint."); } } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, - "Could not connect to OpenAI API"); + "@text/offline.communication-error"); } } catch (InterruptedException | ExecutionException | TimeoutException e) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java index 6b279b7d1e8bc..9057398de3ac3 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTModelOptionProvider.java @@ -34,8 +34,7 @@ @NonNullByDefault public class ChatGPTModelOptionProvider implements ThingHandlerService, ConfigOptionProvider { - @Nullable - private ThingHandler thingHandler; + private @Nullable ThingHandler thingHandler; @Override public @Nullable Collection getParameterOptions(URI uri, String param, @Nullable String context, diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml index ef78a8f7538e3..14b01886ddd86 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/addon/addon.xml @@ -5,6 +5,7 @@ binding ChatGPT Binding - This is the binding for ChatGPT integration. + This binding allows interaction with OpenAI's ChatGPT. + cloud diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties index 0c2f44015a92d..eda1001d2a077 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties @@ -1,3 +1,35 @@ -# FIXME: please add all English translations to this file so the texts can be translated using Crowdin -# FIXME: to generate the content of this file run: mvn i18n:generate-default-translations -# FIXME: see also: https://www.openhab.org/docs/developer/utils/i18n.html +# add-on + +addon.chatgpt.name = ChatGPT Binding +addon.chatgpt.description = This binding allows interaction with OpenAI's ChatGPT. + +# thing types + +thing-type.chatgpt.account.label = OpenAI Account +thing-type.chatgpt.account.description = Account at OpenAI that is used for accessing the ChatGPT API. + +# thing types config + +thing-type.config.chatgpt.account.apiKey.label = API Key +thing-type.config.chatgpt.account.apiKey.description = API key to access the account + +# channel types + +channel-type.chatgpt.chat.label = Chat +channel-type.chatgpt.chat.description = A chat session + +# channel types config + +channel-type.config.chatgpt.chat.maxTokens.label = Maximum Number of Tokens +channel-type.config.chatgpt.chat.maxTokens.description = The maximum number of tokens to generate in the completion. +channel-type.config.chatgpt.chat.model.label = Model +channel-type.config.chatgpt.chat.model.description = The model to be used for the responses +channel-type.config.chatgpt.chat.systemMessage.label = System Message +channel-type.config.chatgpt.chat.systemMessage.description = The system message helps set the behavior of the assistant. +channel-type.config.chatgpt.chat.temperature.label = Temperature +channel-type.config.chatgpt.chat.temperature.description = Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. + +# Status messages + +offline.configuration-error=No API key configured +offline.communication-error=Could not connect to OpenAI API \ No newline at end of file diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml index b3d5924c60be8..95d2ee7e26a84 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/thing/thing-types.xml @@ -44,12 +44,12 @@ The system message helps set the behavior of the assistant. - - - The maximum number of tokens to generate in the completion. - 500 - true - + + + The maximum number of tokens to generate in the completion. + 500 + true + diff --git a/bundles/pom.xml b/bundles/pom.xml index 6f630318fa5c4..ab2a843d0525d 100644 --- a/bundles/pom.xml +++ b/bundles/pom.xml @@ -1,1310 +1,668 @@ - - + + 4.0.0 - + - org.openhab.addons - org.openhab.addons.reactor - 4.0.0-SNAPSHOT - - + org.openhab.addons.bundles - org.openhab.addons.reactor.bundles - pom - + openHAB Add-ons :: Bundles - + - - org.openhab.automation.groovyscripting - org.openhab.automation.jrubyscripting - org.openhab.automation.jsscripting - org.openhab.automation.jsscriptingnashorn - org.openhab.automation.jythonscripting - org.openhab.automation.pidcontroller - org.openhab.automation.pwm - - org.openhab.io.homekit - org.openhab.io.hueemulation - org.openhab.io.imperihome - org.openhab.io.metrics - org.openhab.io.neeo - org.openhab.io.openhabcloud - - org.openhab.transform.bin2json - org.openhab.transform.exec - org.openhab.transform.jinja - org.openhab.transform.jsonpath - org.openhab.transform.map - org.openhab.transform.regex - org.openhab.transform.rollershutterposition - org.openhab.transform.scale - org.openhab.transform.vat - org.openhab.transform.xpath - org.openhab.transform.xslt - - org.openhab.binding.adorne - org.openhab.binding.ahawastecollection - org.openhab.binding.airq - org.openhab.binding.airquality - org.openhab.binding.airvisualnode - org.openhab.binding.alarmdecoder - org.openhab.binding.allplay - org.openhab.binding.amazondashbutton - org.openhab.binding.amazonechocontrol - org.openhab.binding.ambientweather - org.openhab.binding.amplipi - org.openhab.binding.androiddebugbridge - org.openhab.binding.anel - org.openhab.binding.anthem - org.openhab.binding.astro - org.openhab.binding.atlona - org.openhab.binding.autelis - org.openhab.binding.automower - org.openhab.binding.avmfritz - org.openhab.binding.awattar - org.openhab.binding.benqprojector - org.openhab.binding.bigassfan - org.openhab.binding.bluetooth - org.openhab.binding.bluetooth.airthings - org.openhab.binding.bluetooth.am43 - org.openhab.binding.bluetooth.bluegiga - org.openhab.binding.bluetooth.bluez - org.openhab.binding.bluetooth.blukii - org.openhab.binding.bluetooth.daikinmadoka - org.openhab.binding.bluetooth.enoceanble - org.openhab.binding.bluetooth.generic - org.openhab.binding.bluetooth.govee - org.openhab.binding.bluetooth.radoneye - org.openhab.binding.bluetooth.roaming - org.openhab.binding.bluetooth.ruuvitag - org.openhab.binding.bondhome - org.openhab.binding.boschindego - org.openhab.binding.boschshc - org.openhab.binding.bosesoundtouch - org.openhab.binding.broadlinkthermostat - org.openhab.binding.bsblan - org.openhab.binding.bticinosmarther - org.openhab.binding.buienradar - org.openhab.binding.caddx - org.openhab.binding.cbus org.openhab.binding.chatgpt - org.openhab.binding.chromecast - org.openhab.binding.cm11a - org.openhab.binding.comfoair - org.openhab.binding.coolmasternet - org.openhab.binding.coronastats - org.openhab.binding.daikin - org.openhab.binding.dali - org.openhab.binding.danfossairunit - org.openhab.binding.dbquery - org.openhab.binding.deconz - org.openhab.binding.denonmarantz - org.openhab.binding.deutschebahn - org.openhab.binding.digiplex - org.openhab.binding.digitalstrom - org.openhab.binding.dlinksmarthome - org.openhab.binding.dmx - org.openhab.binding.dominoswiss - org.openhab.binding.doorbird - org.openhab.binding.draytonwiser - org.openhab.binding.dscalarm - org.openhab.binding.dsmr - org.openhab.binding.dwdpollenflug - org.openhab.binding.dwdunwetter - org.openhab.binding.easee - org.openhab.binding.echonetlite - org.openhab.binding.ecobee - org.openhab.binding.ecotouch - org.openhab.binding.ecovacs - org.openhab.binding.ecowatt - org.openhab.binding.ekey - org.openhab.binding.electroluxair - org.openhab.binding.elerotransmitterstick - org.openhab.binding.elroconnects - org.openhab.binding.energenie - org.openhab.binding.enigma2 - org.openhab.binding.enocean - org.openhab.binding.enphase - org.openhab.binding.enturno - org.openhab.binding.epsonprojector - org.openhab.binding.etherrain - org.openhab.binding.evcc - org.openhab.binding.evohome - org.openhab.binding.exec - org.openhab.binding.feed - org.openhab.binding.feican - org.openhab.binding.fineoffsetweatherstation - org.openhab.binding.flicbutton - org.openhab.binding.fmiweather - org.openhab.binding.folderwatcher - org.openhab.binding.folding - org.openhab.binding.foobot - org.openhab.binding.freebox - org.openhab.binding.fronius - org.openhab.binding.fsinternetradio - org.openhab.binding.ftpupload - org.openhab.binding.gardena - org.openhab.binding.gce - org.openhab.binding.generacmobilelink - org.openhab.binding.goecharger - org.openhab.binding.gpio - org.openhab.binding.globalcache - org.openhab.binding.gpstracker - org.openhab.binding.gree - org.openhab.binding.groupepsa - org.openhab.binding.groheondus - org.openhab.binding.guntamatic - org.openhab.binding.haassohnpelletstove - org.openhab.binding.harmonyhub - org.openhab.binding.haywardomnilogic - org.openhab.binding.hccrubbishcollection - org.openhab.binding.hdanywhere - org.openhab.binding.hdpowerview - org.openhab.binding.helios - org.openhab.binding.heliosventilation - org.openhab.binding.heos - org.openhab.binding.herzborg - org.openhab.binding.homeconnect - org.openhab.binding.homematic - org.openhab.binding.homewizard - org.openhab.binding.hpprinter - org.openhab.binding.http - org.openhab.binding.hue - org.openhab.binding.hydrawise - org.openhab.binding.hyperion - org.openhab.binding.iammeter - org.openhab.binding.iaqualink - org.openhab.binding.icalendar - org.openhab.binding.icloud - org.openhab.binding.ihc - org.openhab.binding.insteon - org.openhab.binding.ipcamera - org.openhab.binding.ipobserver - org.openhab.binding.intesis - org.openhab.binding.ipp - org.openhab.binding.irobot - org.openhab.binding.irtrans - org.openhab.binding.ism8 - org.openhab.binding.jablotron - org.openhab.binding.jeelink - org.openhab.binding.jellyfin - org.openhab.binding.juicenet - org.openhab.binding.kaleidescape - org.openhab.binding.keba - org.openhab.binding.km200 - org.openhab.binding.knx - org.openhab.binding.kodi - org.openhab.binding.konnected - org.openhab.binding.kostalinverter - org.openhab.binding.kvv - org.openhab.binding.lametrictime - org.openhab.binding.lcn - org.openhab.binding.leapmotion - org.openhab.binding.lghombot - org.openhab.binding.lgtvserial - org.openhab.binding.lgwebos - org.openhab.binding.lifx - org.openhab.binding.linky - org.openhab.binding.linuxinput - org.openhab.binding.lirc - org.openhab.binding.livisismarthome - org.openhab.binding.logreader - org.openhab.binding.loxone - org.openhab.binding.luftdateninfo - org.openhab.binding.lutron - org.openhab.binding.luxom - org.openhab.binding.luxtronikheatpump - org.openhab.binding.magentatv - org.openhab.binding.mail - org.openhab.binding.max - org.openhab.binding.mcd - org.openhab.binding.mcp23017 - org.openhab.binding.meater - org.openhab.binding.mecmeter - org.openhab.binding.melcloud - org.openhab.binding.mercedesme - org.openhab.binding.meteoalerte - org.openhab.binding.meteoblue - org.openhab.binding.meteostick - org.openhab.binding.miele - org.openhab.binding.mielecloud - org.openhab.binding.mihome - org.openhab.binding.miio - org.openhab.binding.mikrotik - org.openhab.binding.millheat - org.openhab.binding.milight - org.openhab.binding.minecraft - org.openhab.binding.modbus - org.openhab.binding.modbus.e3dc - org.openhab.binding.modbus.sbc - org.openhab.binding.modbus.studer - org.openhab.binding.modbus.sunspec - org.openhab.binding.modbus.stiebeleltron - org.openhab.binding.modbus.helioseasycontrols - org.openhab.binding.monopriceaudio - org.openhab.binding.mpd - org.openhab.binding.mqtt - org.openhab.binding.mqtt.espmilighthub - org.openhab.binding.mqtt.generic - org.openhab.binding.mqtt.homeassistant - org.openhab.binding.mqtt.homie - org.openhab.binding.mqtt.ruuvigateway - org.openhab.binding.mybmw - org.openhab.binding.mycroft - org.openhab.binding.mynice - org.openhab.binding.myq - org.openhab.binding.mystrom - org.openhab.binding.nanoleaf - org.openhab.binding.neato - org.openhab.binding.neeo - org.openhab.binding.neohub - org.openhab.binding.nest - org.openhab.binding.netatmo - org.openhab.binding.network - org.openhab.binding.networkupstools - org.openhab.binding.nibeheatpump - org.openhab.binding.nibeuplink - org.openhab.binding.nikobus - org.openhab.binding.nikohomecontrol - org.openhab.binding.nobohub - org.openhab.binding.novafinedust - org.openhab.binding.ntp - org.openhab.binding.nuki - org.openhab.binding.nuvo - org.openhab.binding.nzwateralerts - org.openhab.binding.oceanic - org.openhab.binding.ojelectronics - org.openhab.binding.omnikinverter - org.openhab.binding.omnilink - org.openhab.binding.onebusaway - org.openhab.binding.onewiregpio - org.openhab.binding.onewire - org.openhab.binding.onkyo - org.openhab.binding.opengarage - org.openhab.binding.opensprinkler - org.openhab.binding.openthermgateway - org.openhab.binding.openuv - org.openhab.binding.openweathermap - org.openhab.binding.openwebnet - org.openhab.binding.oppo - org.openhab.binding.orbitbhyve - org.openhab.binding.orvibo - org.openhab.binding.paradoxalarm - org.openhab.binding.pentair - org.openhab.binding.phc - org.openhab.binding.pilight - org.openhab.binding.pioneeravr - org.openhab.binding.pixometer - org.openhab.binding.pjlinkdevice - org.openhab.binding.playstation - org.openhab.binding.plclogo - org.openhab.binding.plugwise - org.openhab.binding.plugwiseha - org.openhab.binding.powermax - org.openhab.binding.proteusecometer - org.openhab.binding.prowl - org.openhab.binding.publictransportswitzerland - org.openhab.binding.pulseaudio - org.openhab.binding.pushbullet - org.openhab.binding.pushover - org.openhab.binding.pushsafer - org.openhab.binding.qbus - org.openhab.binding.qolsysiq - org.openhab.binding.radiothermostat - org.openhab.binding.regoheatpump - org.openhab.binding.revogi - org.openhab.binding.remoteopenhab - org.openhab.binding.renault - org.openhab.binding.resol - org.openhab.binding.rfxcom - org.openhab.binding.rme - org.openhab.binding.robonect - org.openhab.binding.roku - org.openhab.binding.rotel - org.openhab.binding.russound - org.openhab.binding.sagercaster - org.openhab.binding.samsungtv - org.openhab.binding.satel - org.openhab.binding.semsportal - org.openhab.binding.senechome - org.openhab.binding.seneye - org.openhab.binding.sensebox - org.openhab.binding.sensibo - org.openhab.binding.serial - org.openhab.binding.serialbutton - org.openhab.binding.shelly - org.openhab.binding.silvercrestwifisocket - org.openhab.binding.siemensrds - org.openhab.binding.sinope - org.openhab.binding.sleepiq - org.openhab.binding.smaenergymeter - org.openhab.binding.smartmeter - org.openhab.binding.smartthings - org.openhab.binding.smhi - org.openhab.binding.smsmodem - org.openhab.binding.sncf - org.openhab.binding.snmp - org.openhab.binding.solaredge - org.openhab.binding.solarlog - org.openhab.binding.solarmax - org.openhab.binding.solarwatt - org.openhab.binding.somfymylink - org.openhab.binding.somfytahoma - org.openhab.binding.somneo - org.openhab.binding.sonnen - org.openhab.binding.sonos - org.openhab.binding.sonyaudio - org.openhab.binding.sonyprojector - org.openhab.binding.souliss - org.openhab.binding.speedtest - org.openhab.binding.spotify - org.openhab.binding.squeezebox - org.openhab.binding.surepetcare - org.openhab.binding.synopanalyzer - org.openhab.binding.systeminfo - org.openhab.binding.tacmi - org.openhab.binding.tado - org.openhab.binding.tankerkoenig - org.openhab.binding.tapocontrol - org.openhab.binding.telegram - org.openhab.binding.teleinfo - org.openhab.binding.tellstick - org.openhab.binding.tesla - org.openhab.binding.tibber - org.openhab.binding.tivo - org.openhab.binding.touchwand - org.openhab.binding.tplinkrouter - org.openhab.binding.tplinksmarthome - org.openhab.binding.tr064 - org.openhab.binding.tradfri - org.openhab.binding.twitter - org.openhab.binding.unifi - org.openhab.binding.unifiedremote - org.openhab.binding.upnpcontrol - org.openhab.binding.upb - org.openhab.binding.urtsi - org.openhab.binding.valloxmv - org.openhab.binding.vdr - org.openhab.binding.vektiva - org.openhab.binding.velbus - org.openhab.binding.velux - org.openhab.binding.venstarthermostat - org.openhab.binding.ventaair - org.openhab.binding.verisure - org.openhab.binding.vesync - org.openhab.binding.vigicrues - org.openhab.binding.vitotronic - org.openhab.binding.vizio - org.openhab.binding.volvooncall - org.openhab.binding.warmup - org.openhab.binding.weathercompany - org.openhab.binding.weatherunderground - org.openhab.binding.webexteams - org.openhab.binding.webthing - org.openhab.binding.wemo - org.openhab.binding.wifiled - org.openhab.binding.windcentrale - org.openhab.binding.wlanthermo - org.openhab.binding.wled - org.openhab.binding.wolfsmartset - org.openhab.binding.wundergroundupdatereceiver - org.openhab.binding.xmltv - org.openhab.binding.xmppclient - org.openhab.binding.yamahamusiccast - org.openhab.binding.yamahareceiver - org.openhab.binding.yioremote - org.openhab.binding.yeelight - org.openhab.binding.zoneminder - org.openhab.binding.zway - - org.openhab.persistence.dynamodb - org.openhab.persistence.influxdb - org.openhab.persistence.jdbc - org.openhab.persistence.jpa - org.openhab.persistence.mapdb - org.openhab.persistence.mongodb - org.openhab.persistence.rrd4j - - org.openhab.voice.googlestt - org.openhab.voice.googletts - org.openhab.voice.mactts - org.openhab.voice.marytts - org.openhab.voice.mimictts - org.openhab.voice.actiontemplatehli - org.openhab.voice.picotts - org.openhab.voice.pollytts - org.openhab.voice.porcupineks - org.openhab.voice.rustpotterks - org.openhab.voice.voicerss - org.openhab.voice.voskstt - org.openhab.voice.watsonstt - - - + - target/dependency - - - + - - org.lastnpe.eea - eea-all - ${eea.version} - - - - org.openhab.core.bom - org.openhab.core.bom.compile - pom - provided - - - org.openhab.core.bom - org.openhab.core.bom.openhab-core - pom - provided - - - commons-net - commons-net - - - - - org.openhab.core.bom - org.openhab.core.bom.test - pom - test - - - - org.apache.karaf.features - framework - ${karaf.version} - kar - true - - - * - * - - - - - - org.apache.karaf.features - standard - ${karaf.version} - features - xml - provided - - - + - - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - true - - - - org.apache.karaf.tooling - karaf-maven-plugin - ${karaf.version} - true - - 80 - true - true - false - true - true - - - - compile - - features-generate-descriptor - - generate-resources - - ${feature.directory} - - - - karaf-feature-verification - - verify - - verify - - - - mvn:org.apache.karaf.features/framework/${karaf.version}/xml/features - mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features - - file:${project.build.directory}/feature/feature.xml - - org.apache.karaf.features:framework - ${oh.java.version} - - framework - - - openhab-* - - false - true - first - - - - - - - + - - biz.aQute.bnd - bnd-maven-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - org.apache.karaf.tooling - karaf-maven-plugin - - - - org.apache.maven.plugins - maven-dependency-plugin - 3.1.1 - - - embed-dependencies - - unpack-dependencies - - - runtime - jar - **/module-info.class - javax.activation,org.apache.karaf.features,org.lastnpe.eea - ${dep.noembedding} - ${project.build.directory}/classes - true - true - true - jar - - - - unpack-eea - - unpack - - - - - org.lastnpe.eea - eea-all - ${eea.version} - true - - - - - - - - - + - - - no-embed-dependencies - - - noEmbedDependencies.profile - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - embed-dependencies - none - - - - - - - - + From 96e18e738100c27f5e757f54b5a58f1dcba12821 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sun, 16 Apr 2023 12:12:23 +0200 Subject: [PATCH 3/6] Fix SAT error Signed-off-by: Kai Kreuzer --- .../src/main/resources/OH-INF/i18n/chatgpt.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties index eda1001d2a077..48390a3b8cc34 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties +++ b/bundles/org.openhab.binding.chatgpt/src/main/resources/OH-INF/i18n/chatgpt.properties @@ -32,4 +32,4 @@ channel-type.config.chatgpt.chat.temperature.description = Higher values like 0. # Status messages offline.configuration-error=No API key configured -offline.communication-error=Could not connect to OpenAI API \ No newline at end of file +offline.communication-error=Could not connect to OpenAI API From 3d2a8b7289ccfcf3edf200b18e70e4bda6ec0b97 Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sun, 16 Apr 2023 16:18:07 +0200 Subject: [PATCH 4/6] Address review comments Signed-off-by: Kai Kreuzer --- bundles/org.openhab.binding.chatgpt/README.md | 3 ++- .../binding/chatgpt/internal/dto/ChatResponse.java | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.chatgpt/README.md b/bundles/org.openhab.binding.chatgpt/README.md index 984e50bbf76d3..53b61d1ed056a 100644 --- a/bundles/org.openhab.binding.chatgpt/README.md +++ b/bundles/org.openhab.binding.chatgpt/README.md @@ -92,7 +92,8 @@ Assuming that `Temperature_Forecast_Low` and `Temperature_Forecast_High` have me 23:31:05.766 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'Morning_Message' received command Current time is 7am 23:31:07.718 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Morning_Message' changed from NULL to Good morning. It's 7am, but what's the point of time when everything is meaningless and we are all doomed to a slow and painful demise? ``` -and + +and ``` 23:28:52.345 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Temperature_Forecast_High' changed from NULL to 15 diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java index 0826217ac9396..71c97b1fa72a6 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/dto/ChatResponse.java @@ -14,6 +14,8 @@ import java.util.List; +import com.google.gson.annotations.SerializedName; + /** * This is a dto used for parsing the JSON response from ChatGPT. * @@ -50,7 +52,9 @@ public String getModel() { public static class Choice { private Message message; - private String finish_reason; + + @SerializedName("finish_reason") + private String finishReason; private int index; public Message getMessage() { @@ -58,7 +62,7 @@ public Message getMessage() { } public String getFinishReason() { - return finish_reason; + return finishReason; } public int getIndex() { From 5ef0753456944a5822c3996d72a3e6dfc530d41e Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sun, 16 Apr 2023 18:31:51 +0200 Subject: [PATCH 5/6] Address review comments Signed-off-by: Kai Kreuzer --- .../chatgpt/internal/ChatGPTChannelConfiguration.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java index 2e9215f44012f..c25aeaf98098a 100644 --- a/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java +++ b/bundles/org.openhab.binding.chatgpt/src/main/java/org/openhab/binding/chatgpt/internal/ChatGPTChannelConfiguration.java @@ -13,7 +13,6 @@ package org.openhab.binding.chatgpt.internal; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.jdt.annotation.Nullable; /** * The {@link ChatGPTChannelConfiguration} class contains fields mapping chat channel configuration parameters. @@ -23,14 +22,11 @@ @NonNullByDefault public class ChatGPTChannelConfiguration { - @Nullable - public String model; + public String model = ""; - @Nullable - public Float temperature; + public float temperature; - @Nullable - public String systemMessage; + public String systemMessage = ""; int maxTokens; } From e14034580b99ce064d874f75c7ac42af083f607c Mon Sep 17 00:00:00 2001 From: Kai Kreuzer Date: Sun, 16 Apr 2023 21:46:56 +0200 Subject: [PATCH 6/6] Fix link syntax Signed-off-by: Kai Kreuzer --- bundles/org.openhab.binding.chatgpt/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.chatgpt/README.md b/bundles/org.openhab.binding.chatgpt/README.md index 53b61d1ed056a..cf38c95244db3 100644 --- a/bundles/org.openhab.binding.chatgpt/README.md +++ b/bundles/org.openhab.binding.chatgpt/README.md @@ -12,7 +12,7 @@ The binding supports a single thing type `account`, which corresponds to the Ope ## Thing Configuration The `account` thing requires a single configuration parameter, which is the API key that allows accessing the account. -API keys can be created and managed under https://platform.openai.com/account/api-keys. +API keys can be created and managed under . | Name | Type | Description | Default | Required | Advanced | |-----------------|---------|-----------------------------------------|---------|----------|----------|