Disallows chatgpt for emailed invoices.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -62,7 +62,7 @@
|
||||
:input-stream (io/input-stream filename)
|
||||
:metadata {:content-type "application/pdf"
|
||||
:content-length (.length (io/file filename))})
|
||||
(let [imports (->> (parse/parse-file filename filename)
|
||||
(let [imports (->> (parse/parse-file filename filename :allow-glimpse? false)
|
||||
(map #(assoc %
|
||||
:source-url (str "https://" (:data-bucket env)
|
||||
"/"
|
||||
|
||||
@@ -61,14 +61,20 @@
|
||||
(extract-template text)))
|
||||
|
||||
|
||||
(defmulti parse-file (fn [_ filename] (.toLowerCase (last (str/split filename #"\." )))))
|
||||
|
||||
(defmulti parse-file
|
||||
"Parses a file based on its extension. Accepts options as additional arguments.
|
||||
Options:
|
||||
- :allow-glimpse? (default false) - If true, allows parsing a glimpse of the file."
|
||||
(fn [_ filename & opts]
|
||||
(.toLowerCase (last (str/split filename #"\.")))))
|
||||
|
||||
(defn invoke-glimpse2 [f]
|
||||
(let [result (slurp (:payload (lambda/invoke {:client-config {:request-timeout 120000
|
||||
:socket-timeout 120000}} {:function-name "glimpse2" :payload
|
||||
(json/write-str
|
||||
(alog/peek ::x {"url" (str "https://" "data.prod.app.integreatconsult.com" "/" f ) }))
|
||||
})))]
|
||||
(alog/peek ::x {"url" (str "https://" "data.prod.app.integreatconsult.com" "/" f)}))})))]
|
||||
|
||||
|
||||
(alog/info ::glimpse2-payload :payload result)
|
||||
(-> result
|
||||
@@ -92,35 +98,35 @@
|
||||
(get "label"))
|
||||
:total (get i "total")
|
||||
:invoice-number (get i "invoice_number")
|
||||
:template "None found - defaulting to ChatGPT"})
|
||||
)
|
||||
:template "None found - defaulting to ChatGPT"}))
|
||||
|
||||
(catch Exception e
|
||||
(alog/warn ::glimpse2-not-work :error e)
|
||||
nil)))
|
||||
|
||||
(defmethod parse-file
|
||||
"pdf"
|
||||
[file _]
|
||||
[file _ & {:keys [allow-glimpse?] :or {allow-glimpse? false}}]
|
||||
(or
|
||||
(-> (sh/sh "pdftotext" "-layout" file "-")
|
||||
:out
|
||||
parse)
|
||||
(alog/peek ::glimpse2-result (glimpse2 file))))
|
||||
(and allow-glimpse? (alog/peek ::glimpse2-result (glimpse2 file)))))
|
||||
|
||||
(defmethod parse-file
|
||||
"csv"
|
||||
[file filename]
|
||||
[file filename & _]
|
||||
(csv/parse-file file filename))
|
||||
|
||||
(defmethod parse-file
|
||||
"xls"
|
||||
[file filename]
|
||||
[file filename & _]
|
||||
(excel/parse-file file filename))
|
||||
|
||||
|
||||
(defmethod parse-file
|
||||
"xlsx"
|
||||
[file filename]
|
||||
[file filename & _]
|
||||
(excel/parse-file file filename))
|
||||
|
||||
(defn best-match
|
||||
|
||||
@@ -278,7 +278,7 @@
|
||||
"text/csv"
|
||||
"application/pdf")
|
||||
:content-length (.length tempfile)})
|
||||
imports (->> (parse/parse-file (.getPath tempfile) filename)
|
||||
imports (->> (parse/parse-file (.getPath tempfile) filename :allow-glimpse? true)
|
||||
(map #(assoc %
|
||||
:client-override client
|
||||
:location-override location
|
||||
|
||||
@@ -716,7 +716,7 @@
|
||||
:content-length (.length tempfile)})
|
||||
imports (->> (if force-chatgpt
|
||||
(parse/glimpse2 (.getPath tempfile))
|
||||
(parse/parse-file (.getPath tempfile) filename))
|
||||
(parse/parse-file (.getPath tempfile) filename :allow-glimpse? true))
|
||||
(map #(assoc %
|
||||
:client-override force-client
|
||||
:location-override force-location
|
||||
|
||||
Reference in New Issue
Block a user