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]]
[:force-vendor {:optional true}
[:maybe entity-id]]
[:force-chatgpt {:optional true :default false}
[:maybe [ :boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]]
[:force-location {:optional true}
[:maybe [:string {:decode/string strip :min 2 :max 2}]]]])
@@ -351,7 +355,7 @@
:id "upload"}
(fc/start-form
form-params form-errors
[:div.flex.gap-4
[:div.flex.gap-4.items-center
(fc/with-field :force-client
(com/validated-field {:label "Force client"
@@ -381,7 +385,13 @@
:placeholder "Search..."
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
: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
{ :x-data (hx/json {"files" nil
@@ -687,7 +697,7 @@
{:template (:template (first imports))})))
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}
(try
(let [extension (last (str/split (.getName (io/file filename)) #"\."))
@@ -699,7 +709,9 @@
"text/csv"
"application/pdf")
: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 %
:client-override force-client
:location-override force-location
@@ -726,14 +738,14 @@
(defn import-file [request]
#_(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
[file])
results (reduce
(fn [result {:keys [filename tempfile]}]
(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
:response "success!"
:template (:template (first i))}))
@@ -753,8 +765,7 @@
[:table
[:thead
[:tr [:td "File"] [:td "Result"]
(if (:error? results)
[:td "Template"])
[:td "Template"]
(if (:error? results)
[:td "Sample match"])]
#_[:tr "Result"]
@@ -772,16 +783,17 @@
"bg-red-50 text-red-700 border-red-300"
"bg-primary-50 text-primary-700 border-green-500")}
(:response r)]
(if (:error? results )
[:td.p-2.border
{:class "bg-red-50 text-red-700 border-red-300"}
"Template: " (:template r)])
[:td.p-2.border
{:class (if (:error? results)
"bg-red-50 text-red-700 border-red-300"
"bg-primary-50 text-primary-700 border-green-500")}
"Template: " (:template r)]
(if (:error? results )
[:td.p-2.border
{:class "bg-red-50 text-red-700 border-red-300"}
[: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)])]
#_(:template r)])])]]
:headers