From 702bb918468b8aa419f31bac54d83052b8ae6537 Mon Sep 17 00:00:00 2001 From: Frank <29271979+FrankyHollywood@users.noreply.github.com> Date: Tue, 13 Aug 2024 10:03:04 +0200 Subject: [PATCH] Conversation cache --- .../templates/project/configmap-saturn.yaml | 1 + .../templates/project/stateful-set.yaml | 25 +++++++++++ .../mercury/src/layout/__tests__/MainMenu.js | 45 +++++++++++-------- projects/saturn/build.gradle | 4 +- .../io/fairspace/saturn/config/Config.java | 2 + .../saturn/services/llm/AiSearchApp.java | 4 +- 6 files changed, 57 insertions(+), 24 deletions(-) diff --git a/charts/fairspace/templates/project/configmap-saturn.yaml b/charts/fairspace/templates/project/configmap-saturn.yaml index 8e8dc5a9a..755bc7b1d 100644 --- a/charts/fairspace/templates/project/configmap-saturn.yaml +++ b/charts/fairspace/templates/project/configmap-saturn.yaml @@ -10,6 +10,7 @@ data: port: 8090 livenessPort: 8091 publicUrl: {{ template "fairspace.url" . }} + llmConversationCachePath: "/data/saturn/conversations" jena: metadataBaseIRI: http://{{ .Values.fairspace.ingress.domain }}/iri/ datasetPath: "/data/saturn/db" diff --git a/charts/fairspace/templates/project/stateful-set.yaml b/charts/fairspace/templates/project/stateful-set.yaml index 57384cb4e..6c84252cc 100644 --- a/charts/fairspace/templates/project/stateful-set.yaml +++ b/charts/fairspace/templates/project/stateful-set.yaml @@ -102,6 +102,10 @@ spec: {{- if has "ExtraStorage" .Values.fairspace.features }} - name: extra-file-storage mountPath: /data/saturn/extra-files +{{- end }} +{{- if has "LlmSearch" .Values.fairspace.features }} + - name: llm + mountPath: /data/saturn/conversations {{- end }} livenessProbe: httpGet: @@ -204,6 +208,27 @@ spec: {{- else }} storageClassName: {{ .Values.saturn.persistence.files.storageClass | quote }} {{- end }} +{{- end }} + - metadata: + name: llm + labels: + app: saturn +{{- include "fairspace.labels" . | nindent 8 }} +{{- if .Values.saturn.persistence.llm.annotations }} + annotations: +{{ toYaml .Values.saturn.persistence.llm.annotations | indent 8 }} +{{- end }} + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.saturn.persistence.llm.size | quote }} +{{- if .Values.saturn.persistence.llm.storageClass }} + {{- if (eq "-" .Values.saturn.persistence.llm.storageClass) }} + storageClassName: "" + {{- else }} + storageClassName: {{ .Values.saturn.persistence.llm.storageClass | quote }} + {{- end }} {{- end }} {{- if has "ExtraStorage" .Values.fairspace.features }} - metadata: diff --git a/projects/mercury/src/layout/__tests__/MainMenu.js b/projects/mercury/src/layout/__tests__/MainMenu.js index 0ce585ab5..a85f39cbc 100644 --- a/projects/mercury/src/layout/__tests__/MainMenu.js +++ b/projects/mercury/src/layout/__tests__/MainMenu.js @@ -6,36 +6,43 @@ import ServicesContext from '../../common/contexts/ServicesContext'; import UserContext from '../../users/UserContext'; import ExternalStoragesContext from '../../external-storage/ExternalStoragesContext'; import ExternalMetadataSourceContext from '../../metadata/metadata-sources/ExternalMetadataSourceContext'; +import FeaturesContext from '../../common/contexts/FeaturesContext'; import InternalMetadataSourceContext from '../../metadata/metadata-sources/InternalMetadataSourceContext'; import MetadataViewContext from '../../metadata/views/MetadataViewContext'; import MainMenu from '../MainMenu'; import {DEFAULT_METADATA_VIEW_MENU_LABEL} from '../../constants'; import theme from '../../App.theme'; +const mockFeatureContext = { + isFeatureEnabled: jest.fn() +}; + describe('MainMenu', () => { const setup = (user, services, externalStorages, externalMetadataSources, internalMetadata, views) => { return render( - - - - - - - - - - - - - + + + + + + + + + + + + + + + ); diff --git a/projects/saturn/build.gradle b/projects/saturn/build.gradle index 486354bb8..d8dfa404e 100644 --- a/projects/saturn/build.gradle +++ b/projects/saturn/build.gradle @@ -52,7 +52,7 @@ dependencies { implementation "com.sparkjava:spark-core:2.9.4" implementation 'com.pivovarit:throwing-function:1.5.1' implementation 'com.google.guava:guava:33.0.0-jre' - // implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0' // To be updated when Jena 5 is released. +// implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0' // To be updated when Jena 5 is released. implementation('com.io-informatics.oss:jackson-jsonld:0.1.1') { exclude group: 'com.github.jsonld-java' } @@ -69,8 +69,6 @@ dependencies { implementation "org.postgresql:postgresql:${postgresqlVersion}" implementation "com.zaxxer:HikariCP:5.1.0" - implementation("org.json:json:20240303") - runtimeOnly 'org.apache.logging.log4j:log4j-api:2.23.0' runtimeOnly 'org.apache.logging.log4j:log4j-core:2.23.0' runtimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.23.0' diff --git a/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java b/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java index 7eb428b60..bb29f0ee1 100644 --- a/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java +++ b/projects/saturn/src/main/java/io/fairspace/saturn/config/Config.java @@ -59,6 +59,8 @@ public class Config { public Search search = new Search(); + public String llmConversationCachePath = "data/conversations"; + public static class Jena { public String metadataBaseIRI = "http://localhost/iri/"; diff --git a/projects/saturn/src/main/java/io/fairspace/saturn/services/llm/AiSearchApp.java b/projects/saturn/src/main/java/io/fairspace/saturn/services/llm/AiSearchApp.java index ead11114e..073fea880 100644 --- a/projects/saturn/src/main/java/io/fairspace/saturn/services/llm/AiSearchApp.java +++ b/projects/saturn/src/main/java/io/fairspace/saturn/services/llm/AiSearchApp.java @@ -7,13 +7,13 @@ import java.util.stream.Collectors; import lombok.extern.log4j.*; -import io.fairspace.saturn.services.llm.LlmConversation; import org.json.JSONObject; import spark.Request; import io.fairspace.saturn.services.BaseApp; import static io.fairspace.saturn.auth.RequestContext.getAccessToken; +import static io.fairspace.saturn.config.ConfigLoader.CONFIG; import static org.eclipse.jetty.http.MimeTypes.Type.APPLICATION_JSON; import static spark.Spark.get; @@ -21,7 +21,7 @@ @Log4j2 public class AiSearchApp extends BaseApp { - final String CACHE_DIR = "./data/conversations/"; + final String CACHE_DIR = CONFIG.llmConversationCachePath; public AiSearchApp(String basePath) { super(basePath);