committed by
GitHub
23 changed files with 372 additions and 67 deletions
@ -0,0 +1,58 @@ |
|||
/** |
|||
* 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.model.chat; |
|||
|
|||
import dev.langchain4j.model.chat.ChatModel; |
|||
import jakarta.validation.Valid; |
|||
import jakarta.validation.constraints.Max; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import jakarta.validation.constraints.NotNull; |
|||
import jakarta.validation.constraints.Positive; |
|||
import jakarta.validation.constraints.PositiveOrZero; |
|||
import lombok.Builder; |
|||
import lombok.With; |
|||
import org.thingsboard.server.common.data.ai.provider.AiProvider; |
|||
import org.thingsboard.server.common.data.ai.provider.OllamaProviderConfig; |
|||
|
|||
@Builder |
|||
public record OllamaChatModelConfig( |
|||
@NotNull @Valid OllamaProviderConfig providerConfig, |
|||
@NotBlank String modelId, |
|||
@PositiveOrZero Double temperature, |
|||
@Positive @Max(1) Double topP, |
|||
@PositiveOrZero Integer topK, |
|||
Integer contextLength, |
|||
Integer maxOutputTokens, |
|||
@With @Positive Integer timeoutSeconds, |
|||
@With @PositiveOrZero Integer maxRetries |
|||
) implements AiChatModelConfig<OllamaChatModelConfig> { |
|||
|
|||
@Override |
|||
public AiProvider provider() { |
|||
return AiProvider.OLLAMA; |
|||
} |
|||
|
|||
@Override |
|||
public ChatModel configure(Langchain4jChatModelConfigurer configurer) { |
|||
return configurer.configureChatModel(this); |
|||
} |
|||
|
|||
@Override |
|||
public boolean supportsJsonMode() { |
|||
return true; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
/** |
|||
* 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.provider; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
import jakarta.validation.Valid; |
|||
import jakarta.validation.constraints.NotNull; |
|||
|
|||
public record OllamaProviderConfig( |
|||
@NotNull String baseUrl, |
|||
@NotNull @Valid OllamaAuth auth |
|||
) implements AiProviderConfig { |
|||
|
|||
@JsonTypeInfo( |
|||
use = JsonTypeInfo.Id.NAME, |
|||
include = JsonTypeInfo.As.PROPERTY, |
|||
property = "type" |
|||
) |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value = OllamaAuth.None.class, name = "NONE"), |
|||
@JsonSubTypes.Type(value = OllamaAuth.Basic.class, name = "BASIC"), |
|||
@JsonSubTypes.Type(value = OllamaAuth.Token.class, name = "TOKEN") |
|||
}) |
|||
public sealed interface OllamaAuth { |
|||
|
|||
record None() implements OllamaAuth {} |
|||
|
|||
record Basic(@NotNull String username, @NotNull String password) implements OllamaAuth {} |
|||
|
|||
record Token(@NotNull String token) implements OllamaAuth {} |
|||
|
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue