AI rule node: add AiProvider enum
This commit is contained in:
parent
a3a1971a68
commit
ad0161e3df
@ -45,19 +45,18 @@ class AiServiceImpl implements RuleEngineAiService {
|
||||
var aiSettings = aiSettingsOpt.get();
|
||||
|
||||
return switch (aiSettings.getProvider()) {
|
||||
case "openai" -> OpenAiChatModel.builder()
|
||||
case OPENAI -> OpenAiChatModel.builder()
|
||||
.apiKey(aiSettings.getApiKey())
|
||||
.modelName(aiSettings.getModel())
|
||||
.build();
|
||||
case "mistral-ai" -> MistralAiChatModel.builder()
|
||||
case MISTRAL_AI -> MistralAiChatModel.builder()
|
||||
.apiKey(aiSettings.getApiKey())
|
||||
.modelName(aiSettings.getModel())
|
||||
.build();
|
||||
case "google-ai-gemini" -> GoogleAiGeminiChatModel.builder()
|
||||
case GOOGLE_AI_GEMINI -> GoogleAiGeminiChatModel.builder()
|
||||
.apiKey(aiSettings.getApiKey())
|
||||
.modelName(aiSettings.getModel())
|
||||
.build();
|
||||
default -> throw new IllegalArgumentException("Unsupported AI provider: " + aiSettings.getProvider());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright © 2016-2025 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.server.common.data.ai;
|
||||
|
||||
public enum AiProvider {
|
||||
|
||||
OPENAI,
|
||||
GOOGLE_AI_GEMINI,
|
||||
MISTRAL_AI
|
||||
|
||||
}
|
||||
@ -66,15 +66,17 @@ public final class AiSettings extends BaseData<AiSettingsId> implements HasTenan
|
||||
@Schema(
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
accessMode = Schema.AccessMode.READ_WRITE,
|
||||
description = "Name of the LLM provider",
|
||||
example = "openai"
|
||||
description = "Name of the AI provider",
|
||||
example = "OPENAI",
|
||||
allowableValues = {"OPENAI", "GOOGLE_AI_GEMINI", "MISTRAL_AI"},
|
||||
type = "string"
|
||||
)
|
||||
String provider;
|
||||
AiProvider provider;
|
||||
|
||||
@Schema(
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
accessMode = Schema.AccessMode.READ_WRITE,
|
||||
description = "Identifier of the LLM model to use",
|
||||
description = "Identifier of the AI model to use",
|
||||
example = "gpt-4o-mini"
|
||||
)
|
||||
String model;
|
||||
@ -82,7 +84,7 @@ public final class AiSettings extends BaseData<AiSettingsId> implements HasTenan
|
||||
@Schema(
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
accessMode = Schema.AccessMode.WRITE_ONLY,
|
||||
description = "API key for authenticating with the selected LLM provider",
|
||||
description = "API key for authenticating with the selected AI provider",
|
||||
example = "sk-********************************"
|
||||
)
|
||||
String apiKey;
|
||||
|
||||
@ -17,11 +17,14 @@ package org.thingsboard.server.dao.model.sql;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.thingsboard.server.common.data.ai.AiProvider;
|
||||
import org.thingsboard.server.common.data.ai.AiSettings;
|
||||
import org.thingsboard.server.common.data.id.AiSettingsId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
@ -44,8 +47,9 @@ public class AiSettingsEntity extends BaseVersionedEntity<AiSettings> {
|
||||
@Column(name = ModelConstants.AI_SETTINGS_NAME_COLUMN_NAME, nullable = false)
|
||||
private String name;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(name = ModelConstants.AI_SETTINGS_PROVIDER_COLUMN_NAME, nullable = false)
|
||||
private String provider;
|
||||
private AiProvider provider;
|
||||
|
||||
@Column(name = ModelConstants.AI_SETTINGS_MODEL_COLUMN_NAME, nullable = false)
|
||||
private String model;
|
||||
|
||||
@ -48,7 +48,7 @@ import static org.thingsboard.server.dao.service.ConstraintValidator.validateFie
|
||||
type = ComponentType.EXTERNAL,
|
||||
name = "AI",
|
||||
nodeDescription = "Interact with AI",
|
||||
nodeDetails = "This node makes requests to LLM based on a prompt and a input message and returns a response in a form of output message",
|
||||
nodeDetails = "This node makes requests to AI based on a prompt and a input message and returns a response in a form of output message",
|
||||
configClazz = TbAiNodeConfiguration.class
|
||||
)
|
||||
public final class TbAiNode extends TbAbstractExternalNode implements TbNode {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user