2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.chatgpt.internal;
15 import static org.openhab.binding.chatgpt.internal.ChatGPTBindingConstants.CHANNEL_TYPE_UID_CHAT;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21 import java.util.Locale;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.openhab.core.config.core.ConfigOptionProvider;
26 import org.openhab.core.config.core.ParameterOption;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerService;
31 * The {@link ChatGPTModelOptionProvider} provides the available models from OpenAI as options for the channel
34 * @author Kai Kreuzer - Initial contribution
37 public class ChatGPTModelOptionProvider implements ThingHandlerService, ConfigOptionProvider {
39 private @Nullable ThingHandler thingHandler;
42 public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
43 @Nullable Locale locale) {
44 if (CHANNEL_TYPE_UID_CHAT.getAsString().equals(uri.toString())) {
45 if ("model".equals(param)) {
46 List<ParameterOption> options = new ArrayList<>();
47 if (thingHandler instanceof ChatGPTHandler chatGPTHandler) {
48 chatGPTHandler.getModels().forEach(model -> options.add(new ParameterOption(model, model)));
57 public void setThingHandler(ThingHandler handler) {
58 this.thingHandler = handler;
62 public @Nullable ThingHandler getThingHandler() {
67 public void activate() {