Updating version, removing deprecated classes

This commit is contained in:
Dario Ghunney Ware
2025-11-05 12:50:09 +00:00
parent e0ad76eeab
commit 949e8eb2c3
15 changed files with 93 additions and 5 deletions

View File

@@ -634,6 +634,7 @@ public class ApplicationProperties {
private String primary = "gpt-5-nano";
private String fallback = "gpt-5-mini";
private String embedding = "text-embedding-3-small";
private String apiKey;
}
@Data

View File

@@ -59,6 +59,7 @@ posthog.api.key=phc_fiR65u5j6qmXTYL56MNrLZSWqLaDW74OrZH0Insd2xq
posthog.host=https://eu.i.posthog.com
spring.main.allow-bean-definition-overriding=true
spring.ai.openai.enabled=false
# Set up a consistent temporary directory location
java.io.tmpdir=${stirling.tempfiles.directory:${java.io.tmpdir}/stirling-pdf}

View File

@@ -102,6 +102,7 @@ premium:
primary: gpt-5-nano # Default lightweight model
fallback: gpt-5-mini # Escalation model for complex prompts
embedding: text-embedding-3-small # Embedding model for vector store usage
apiKey: '' # Provide your OpenAI-compatible API key (or use SPRING_AI_OPENAI_API_KEY env var)
rag:
chunkSizeTokens: 512 # Token window used when chunking text
chunkOverlapTokens: 128 # Overlap between successive chunks

View File

@@ -52,7 +52,7 @@ dependencies {
api 'org.springframework.boot:spring-boot-starter-cache'
api 'com.github.ben-manes.caffeine:caffeine'
api 'io.swagger.core.v3:swagger-core-jakarta:2.2.38'
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter:1.0.0-M6'
implementation 'org.springframework.ai:spring-ai-openai'
implementation 'com.bucket4j:bucket4j_jdk17-core:8.15.0'
// https://mvnrepository.com/artifact/com.bucket4j/bucket4j_jdk17

View File

@@ -0,0 +1,52 @@
package stirling.software.proprietary.config;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.OpenAiEmbeddingModel;
import org.springframework.ai.openai.OpenAiEmbeddingOptions;
import org.springframework.ai.openai.api.OpenAiApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import stirling.software.proprietary.service.chatbot.ChatbotFeatureProperties;
import stirling.software.proprietary.service.chatbot.ChatbotFeatureProperties.ChatbotSettings;
@Configuration
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
public class ChatbotAiConfiguration {
@Bean
public OpenAiApi chatbotOpenAiApi(ChatbotFeatureProperties properties) {
ChatbotSettings settings = properties.current();
String apiKey = settings.models().apiKey();
if (!StringUtils.hasText(apiKey)) {
throw new IllegalStateException(
"premium.proFeatures.chatbot.models.apiKey must be set (or provide SPRING_AI_OPENAI_API_KEY)");
}
return new OpenAiApi(apiKey);
}
@Bean
public ChatModel chatbotChatModel(
OpenAiApi chatbotOpenAiApi, ChatbotFeatureProperties properties) {
OpenAiChatOptions options =
OpenAiChatOptions.builder()
.withModel(properties.current().models().primary())
.build();
return new OpenAiChatModel(chatbotOpenAiApi, options);
}
@Bean
public EmbeddingModel chatbotEmbeddingModel(
OpenAiApi chatbotOpenAiApi, ChatbotFeatureProperties properties) {
OpenAiEmbeddingOptions options =
OpenAiEmbeddingOptions.builder()
.withModel(properties.current().models().embedding())
.build();
return new OpenAiEmbeddingModel(chatbotOpenAiApi, options);
}
}

View File

@@ -3,6 +3,7 @@ package stirling.software.proprietary.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -32,6 +33,7 @@ import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
@RequestMapping("/api/internal/chatbot")
@RequiredArgsConstructor
@Slf4j
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
public class ChatbotController {
private final ChatbotService chatbotService;

View File

@@ -3,6 +3,7 @@ package stirling.software.proprietary.controller;
import java.time.Instant;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -15,6 +16,7 @@ import stirling.software.proprietary.service.chatbot.exception.NoTextDetectedExc
@RestControllerAdvice(assignableTypes = ChatbotController.class)
@Slf4j
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
public class ChatbotExceptionHandler {
@ExceptionHandler(NoTextDetectedException.class)

View File

@@ -9,6 +9,7 @@ import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import com.github.benmanes.caffeine.cache.Cache;
@@ -25,6 +26,7 @@ import stirling.software.proprietary.model.chatbot.ChatbotTextChunk;
import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
@Service
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
@Slf4j
public class ChatbotCacheService {

View File

@@ -16,6 +16,7 @@ import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -36,6 +37,7 @@ import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
@Service
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
public class ChatbotConversationService {
private final ChatModel chatModel;

View File

@@ -2,7 +2,9 @@ package stirling.software.proprietary.service.chatbot;
import java.util.Optional;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import stirling.software.common.model.ApplicationProperties;
import stirling.software.common.model.ApplicationProperties.Premium;
@@ -13,13 +15,23 @@ import stirling.software.common.model.ApplicationProperties.Premium.ProFeatures.
public class ChatbotFeatureProperties {
private final ApplicationProperties applicationProperties;
private final Environment environment;
public ChatbotFeatureProperties(ApplicationProperties applicationProperties) {
public ChatbotFeatureProperties(
ApplicationProperties applicationProperties, Environment environment) {
this.applicationProperties = applicationProperties;
this.environment = environment;
}
public ChatbotSettings current() {
Chatbot chatbot = resolveChatbot();
String configuredKey = Optional.ofNullable(chatbot.getModels().getApiKey()).orElse("");
String fallbackKey = environment.getProperty("spring.ai.openai.api-key", "");
String apiKey =
StringUtils.hasText(configuredKey)
? configuredKey
: (StringUtils.hasText(fallbackKey) ? fallbackKey : "");
return new ChatbotSettings(
chatbot.isEnabled(),
chatbot.isAlphaWarning(),
@@ -28,7 +40,8 @@ public class ChatbotFeatureProperties {
new ChatbotSettings.ModelSettings(
chatbot.getModels().getPrimary(),
chatbot.getModels().getFallback(),
chatbot.getModels().getEmbedding()),
chatbot.getModels().getEmbedding(),
apiKey),
new ChatbotSettings.RagSettings(
chatbot.getRag().getChunkSizeTokens(),
chatbot.getRag().getChunkOverlapTokens(),
@@ -64,7 +77,8 @@ public class ChatbotFeatureProperties {
OcrSettings ocr,
AuditSettings audit) {
public record ModelSettings(String primary, String fallback, String embedding) {}
public record ModelSettings(
String primary, String fallback, String embedding, String apiKey) {}
public record RagSettings(int chunkSizeTokens, int chunkOverlapTokens, int topK) {}

View File

@@ -8,6 +8,7 @@ import java.util.UUID;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -22,6 +23,7 @@ import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
import stirling.software.proprietary.service.chatbot.exception.NoTextDetectedException;
@Service
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
@Slf4j
@RequiredArgsConstructor
public class ChatbotIngestionService {

View File

@@ -7,6 +7,7 @@ import java.util.Optional;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.embedding.EmbeddingResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -21,6 +22,7 @@ import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
@Service
@RequiredArgsConstructor
@Slf4j
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
public class ChatbotRetrievalService {
private final ChatbotCacheService cacheService;

View File

@@ -3,6 +3,7 @@ package stirling.software.proprietary.service.chatbot;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
@@ -16,6 +17,7 @@ import stirling.software.proprietary.service.AuditService;
import stirling.software.proprietary.service.chatbot.exception.ChatbotException;
@Service
@ConditionalOnProperty(value = "premium.proFeatures.chatbot.enabled", havingValue = "true")
@Slf4j
@RequiredArgsConstructor
public class ChatbotService {