2 * Copyright (c) 2010-2023 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;
16 import java.util.ArrayList;
17 import java.util.Collection;
18 import java.util.List;
19 import java.util.Locale;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.config.core.ConfigOptionProvider;
24 import org.openhab.core.config.core.ParameterOption;
25 import org.openhab.core.thing.binding.ThingHandler;
26 import org.openhab.core.thing.binding.ThingHandlerService;
29 * The {@link ChatGPTModelOptionProvider} provides the available models from OpenAI as options for the channel
32 * @author Kai Kreuzer - Initial contribution
35 public class ChatGPTModelOptionProvider implements ThingHandlerService, ConfigOptionProvider {
37 private @Nullable ThingHandler thingHandler;
40 public @Nullable Collection<ParameterOption> getParameterOptions(URI uri, String param, @Nullable String context,
41 @Nullable Locale locale) {
42 String accountParameterUrl = "thing-type:" + ChatGPTBindingConstants.THING_TYPE_ACCOUNT.getAsString();
43 if (accountParameterUrl.equals(uri.toString())) {
44 if ("model".equals(param)) {
45 List<ParameterOption> options = new ArrayList<>();
46 if (thingHandler instanceof ChatGPTHandler chatGPTHandler) {
47 chatGPTHandler.getModels().forEach(model -> options.add(new ParameterOption(model, model)));
56 public void setThingHandler(ThingHandler handler) {
57 this.thingHandler = handler;
61 public @Nullable ThingHandler getThingHandler() {
66 public void activate() {