Pārlūkot izejas kodu

add local embedding model settings

Tienson Qin 3 mēneši atpakaļ
vecāks
revīzija
00405d98d3

+ 4 - 2
shadow-cljs.edn

@@ -39,7 +39,7 @@
         :output-dir       "./static/js"
         :asset-path       "/static/js"
         :release          {:asset-path "https://asset.logseq.com/static/js"}
-        :compiler-options {:infer-externs      :auto
+        :compiler-options {:infer-externs      false
                            :output-feature-set :es-next-in
                            :source-map true
                            :externs ["datascript/externs.js"
@@ -66,7 +66,9 @@
                    :after-load frontend.core/start          ;; after live-reloading finishes call this function
                    :watch-path "/static"
                    :preloads [devtools.preload
-                              shadow.remote.runtime.cljs.browser]}}
+                              shadow.remote.runtime.cljs.browser]
+                   ;; :ignore-warnings true
+                   }}
 
   :workers {:target        :browser
             :module-loader true

+ 75 - 1
src/main/frontend/components/settings.cljs

@@ -1,7 +1,9 @@
 (ns frontend.components.settings
   (:require [clojure.string :as string]
             [electron.ipc :as ipc]
+            [fipp.edn :as fipp]
             [frontend.colors :as colors]
+            [frontend.common.missionary :as c.m]
             [frontend.components.assets :as assets]
             [frontend.components.file-sync :as fs]
             [frontend.components.shortcut :as shortcut]
@@ -13,6 +15,7 @@
             [frontend.dicts :as dicts]
             [frontend.handler.config :as config-handler]
             [frontend.handler.db-based.rtc :as rtc-handler]
+            [frontend.handler.db-based.vector-search-flows :as vector-search-flows]
             [frontend.handler.file-sync :as file-sync-handler]
             [frontend.handler.global-config :as global-config-handler]
             [frontend.handler.notification :as notification]
@@ -35,6 +38,7 @@
             [logseq.db :as ldb]
             [logseq.shui.hooks :as hooks]
             [logseq.shui.ui :as shui]
+            [missionary.core :as m]
             [promesa.core :as p]
             [reitit.frontend.easy :as rfe]
             [rum.core :as rum]))
@@ -1189,6 +1193,70 @@
                            (rtc-handler/<rtc-invite-email graph-uuid user-email)))))}
         "Invite")]]]))
 
+(rum/defc settings-ai
+  []
+  (let [[model-info set-model-info] (hooks/use-state nil)
+        [load-model-progress set-load-model-progress] (hooks/use-state nil)
+        repo (state/get-current-repo)
+        current-model (:graph-text-embedding-model-name model-info)
+        model-ready? (= "ready" (get load-model-progress "status"))]
+    (hooks/use-effect!
+     (fn []
+       (c.m/run-task
+         ::fetch-model-info
+         (m/reduce
+          (constantly nil)
+          (m/ap
+            (m/?> vector-search-flows/infer-worker-ready-flow)
+            (let [model-info (c.m/<? (state/<invoke-db-worker :thread-api/vec-search-embedding-model-info repo))]
+              (set-model-info model-info))))
+         :succ (constantly nil)))
+     [])
+    (hooks/use-effect!
+     (fn []
+       (c.m/run-task
+         ::update-load-model-progress
+         (m/reduce
+          (fn [_ v] (set-load-model-progress v))
+          vector-search-flows/load-model-progress-flow)
+         :succ (constantly nil)))
+     [])
+    [:div.panel-wrap
+     [:div.flex.flex-col.gap-2
+      [:div.it.sm:grid.sm:grid-cols-3.sm:gap-4.sm:items-start
+       [:label.block.text-sm.font-medium.leading-8.opacity-70
+        {:for "local-embedding-model"}
+        "Local embedding model"]
+       [:div.rounded-md.sm:max-w-tss.sm:col-span-2
+        [:div.flex.flex-col.gap-2
+         (shui/select
+          {:on-value-change (fn [model-name]
+                              (c.m/run-task
+                                ::load-model
+                                (m/sp
+                                  (c.m/<?
+                                   (state/<invoke-db-worker :thread-api/vec-search-load-model repo model-name))
+                                  (set-model-info (assoc model-info :graph-text-embedding-model-name model-name)))
+                                :succ (constantly nil)))
+           :value current-model}
+          (shui/select-trigger
+           {:class "h-8"}
+           (shui/select-value
+            {:placeholder "Select a model"}))
+
+          (shui/select-content
+           (shui/select-group
+            (for [model-name (:available-model-names model-info)]
+              (shui/select-item {:value model-name} model-name)))))
+
+         [:div.text-muted-foreground.text-sm
+          (str "Model is "
+               (case (get load-model-progress "status")
+                 ("initiate" "progress") "loading"
+                 "ready" "ready"
+                 "not ready")
+               (when model-ready? " 🚀"))]]]]]]))
+
 (rum/defcs ^:large-vars/cleanup-todo settings
   < (rum/local DEFAULT-ACTIVE-TAB-STATE ::active)
   {:will-mount
@@ -1212,7 +1280,8 @@
         _installed-plugins (state/sub :plugin/installed-plugins)
         plugins-of-settings (and config/lsp-enabled? (seq (plugin-handler/get-enabled-plugins-if-setting-schema)))
         *active (::active state)
-        logged-in? (user-handler/logged-in?)]
+        logged-in? (user-handler/logged-in?)
+        db-based? (config/db-based-graph?)]
 
     [:div#settings.cp__settings-main
      (settings-effect @*active)
@@ -1228,6 +1297,8 @@
                [:editor "editor" (t :settings-page/tab-editor) (ui/icon "writing")]
                [:keymap "keymap" (t :settings-page/tab-keymap) (ui/icon "keyboard")]
 
+               (when db-based?
+                 [:ai "AI" (t :settings-page/ai) (ui/icon "wand")])
                (when (util/electron?)
                  [:version-control "git" (t :settings-page/tab-version-control) (ui/icon "history")])
 
@@ -1293,4 +1364,7 @@
          :collaboration
          (settings-collaboration)
 
+         :ai
+         (settings-ai)
+
          nil)]]]))

+ 2 - 0
src/resources/dicts/en.edn

@@ -213,6 +213,8 @@
  :context-menu/input-template-name "What's the template's name?"
  :context-menu/template-include-parent-block "Including the parent block in the template?"
  :context-menu/template-exists-warning "Template already exists!"
+ :settings-page/ai "AI"
+ :settings-page/tab-ai "AI"
  :settings-page/git-tip "If you have Logseq Sync enabled, you can view a page's edit history directly. This section is for tech-savvy only."
  :settings-page/git-desc-1 "To view page's edit history, click the three horizontal dots in the top-right corner and select \"View page history\"."
  :settings-page/git-desc-2 "For professional users, Logseq also supports using "