Allows forcing of chatgpt

This commit is contained in:
2024-06-26 20:34:54 -07:00
parent 06b9e6e02c
commit 161218655e

View File

@@ -325,6 +325,10 @@
[:maybe entity-id]] [:maybe entity-id]]
[:force-vendor {:optional true} [:force-vendor {:optional true}
[:maybe entity-id]] [:maybe entity-id]]
[:force-chatgpt {:optional true :default false}
[:maybe [ :boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]]
[:force-location {:optional true} [:force-location {:optional true}
[:maybe [:string {:decode/string strip :min 2 :max 2}]]]]) [:maybe [:string {:decode/string strip :min 2 :max 2}]]]])
@@ -351,7 +355,7 @@
:id "upload"} :id "upload"}
(fc/start-form (fc/start-form
form-params form-errors form-params form-errors
[:div.flex.gap-4 [:div.flex.gap-4.items-center
(fc/with-field :force-client (fc/with-field :force-client
(com/validated-field {:label "Force client" (com/validated-field {:label "Force client"
@@ -381,7 +385,13 @@
:placeholder "Search..." :placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :vendor-search) :url (bidi/path-for ssr-routes/only-routes :vendor-search)
:value (fc/field-value) :value (fc/field-value)
:content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})]))]) :content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})]))
(fc/with-field :force-chatgpt
(com/validated-field { :errors (fc/field-errors)
:label " "}
(com/checkbox {:name (fc/field-name)
:error? (fc/error?) }
"Only use ChatGPT")))])
[:div.border-2.border-dashed.rounded-lg.p-4.w-full.text-center.cursor-pointer.h-64.flex.items-center.justify-center.text-lg.relative [:div.border-2.border-dashed.rounded-lg.p-4.w-full.text-center.cursor-pointer.h-64.flex.items-center.justify-center.text-lg.relative
{ :x-data (hx/json {"files" nil { :x-data (hx/json {"files" nil
@@ -687,7 +697,7 @@
{:template (:template (first imports))}))) {:template (:template (first imports))})))
tx))) tx)))
(defn import-internal [tempfile filename force-client force-location force-vendor identity] (defn import-internal [tempfile filename force-client force-location force-vendor force-chatgpt identity]
(mu/with-context {:parsing-file filename} (mu/with-context {:parsing-file filename}
(try (try
(let [extension (last (str/split (.getName (io/file filename)) #"\.")) (let [extension (last (str/split (.getName (io/file filename)) #"\."))
@@ -699,7 +709,9 @@
"text/csv" "text/csv"
"application/pdf") "application/pdf")
:content-length (.length tempfile)}) :content-length (.length tempfile)})
imports (->> (parse/parse-file (.getPath tempfile) filename) imports (->> (if force-chatgpt
(parse/glimpse2 (.getPath tempfile))
(parse/parse-file (.getPath tempfile) filename))
(map #(assoc % (map #(assoc %
:client-override force-client :client-override force-client
:location-override force-location :location-override force-location
@@ -726,14 +738,14 @@
(defn import-file [request] (defn import-file [request]
#_(html-response [:div]) #_(html-response [:div])
(let [{:keys [file force-client force-vendor force-location]} (:multipart-params request) (let [{:keys [file force-client force-vendor force-location force-chatgpt]} (:multipart-params request)
file (if (vector? file) file (if (vector? file)
file file
[file]) [file])
results (reduce results (reduce
(fn [result {:keys [filename tempfile]}] (fn [result {:keys [filename tempfile]}]
(try (try
(let [i (import-internal tempfile filename force-client force-location force-vendor (:identity request) )] (let [i (import-internal tempfile filename force-client force-location force-vendor force-chatgpt (:identity request) )]
(update result :results conj {:filename filename (update result :results conj {:filename filename
:response "success!" :response "success!"
:template (:template (first i))})) :template (:template (first i))}))
@@ -753,8 +765,7 @@
[:table [:table
[:thead [:thead
[:tr [:td "File"] [:td "Result"] [:tr [:td "File"] [:td "Result"]
(if (:error? results) [:td "Template"]
[:td "Template"])
(if (:error? results) (if (:error? results)
[:td "Sample match"])] [:td "Sample match"])]
#_[:tr "Result"] #_[:tr "Result"]
@@ -772,16 +783,17 @@
"bg-red-50 text-red-700 border-red-300" "bg-red-50 text-red-700 border-red-300"
"bg-primary-50 text-primary-700 border-green-500")} "bg-primary-50 text-primary-700 border-green-500")}
(:response r)] (:response r)]
(if (:error? results ) [:td.p-2.border
[:td.p-2.border {:class (if (:error? results)
{:class "bg-red-50 text-red-700 border-red-300"} "bg-red-50 text-red-700 border-red-300"
"Template: " (:template r)]) "bg-primary-50 text-primary-700 border-green-500")}
"Template: " (:template r)]
(if (:error? results ) (if (:error? results )
[:td.p-2.border [:td.p-2.border
{:class "bg-red-50 text-red-700 border-red-300"} {:class "bg-red-50 text-red-700 border-red-300"}
[:ul [:ul
(for [[k v] (dissoc (:sample r) :template :source-url)] (for [[k v] (dissoc (:sample r) :template :source-url :full-text :text)]
[:li (name k) ": " (str v)])] [:li (name k) ": " (str v)])]
#_(:template r)])])]] #_(:template r)])])]]
:headers :headers