get config and is_tech working
This commit is contained in:
parent
77ae02c8b8
commit
8e0d00035a
5 changed files with 109 additions and 0 deletions
26
src/micro_blog/config.clj
Normal file
26
src/micro_blog/config.clj
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(ns micro-blog.config
|
||||
(:require [environ.core :refer [env]]))
|
||||
|
||||
(def ^:private env-overrides
|
||||
{:minstral-api-key "MISTRAL_API_KEY"})
|
||||
|
||||
(defn- load-config []
|
||||
(println "config is being loaded")
|
||||
(merge (read-string (slurp "config.edn"))
|
||||
(into {} (for [[k env-var] env-overrides
|
||||
:let [env-val (env env-var)]
|
||||
:when env-val]
|
||||
[k env-val]))))
|
||||
|
||||
(def config (atom (load-config)))
|
||||
|
||||
(defn reload-config []
|
||||
(reset! config (load-config)))
|
||||
|
||||
(comment
|
||||
;; Example usage:
|
||||
;; Access the config
|
||||
@config
|
||||
|
||||
;; Reload the config at runtime
|
||||
(reload-config))
|
||||
26
src/micro_blog/is_tech.clj
Normal file
26
src/micro_blog/is_tech.clj
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(ns micro-blog.is-tech
|
||||
(:require
|
||||
[micro-blog.config :refer [config]]
|
||||
[clj-http.client :as client]))
|
||||
|
||||
(defn call-mistral-api [post-text]
|
||||
(let [url (str (:mistral-host @config) "/v1/conversations")
|
||||
headers {"Content-Type" "application/json"
|
||||
"Accept" "application/json"
|
||||
"Authorization" (str "Bearer " (@config :mistral-api-key))}
|
||||
body {:inputs post-text
|
||||
:stream false
|
||||
:agent_id (@config :mistral-agent-id)}]
|
||||
(->
|
||||
(client/post url {:headers headers
|
||||
:form-params body
|
||||
:content-type :json
|
||||
:as :json})
|
||||
:body
|
||||
:outputs
|
||||
first
|
||||
:content
|
||||
(#(if (= "1" %) true false)))))
|
||||
|
||||
(defn is-tech? [post-text]
|
||||
(call-mistral-api post-text))
|
||||
Loading…
Add table
Add a link
Reference in a new issue