From 5fb26e622085d5bc634bec4a62e4d4d47b794c45 Mon Sep 17 00:00:00 2001 From: anaxios Date: Sat, 10 Aug 2024 08:12:05 -0700 Subject: [PATCH] Refactor aicommit.clj to utilize OpenAI's chat completion API for generating commit messages using groq. Adding Cheshire core dependency for JSON parsing and generation --- aicommit.clj | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/aicommit.clj b/aicommit.clj index 040d72d..9007ee3 100644 --- a/aicommit.clj +++ b/aicommit.clj @@ -1,9 +1,10 @@ #!/usr/bin/env bb -(require '[babashka.curl :as curl] - '[babashka.process :as p]) +(require '[babashka.curl :as curl] + '[babashka.process :as p] + '[cheshire.core :as json]) -(def url "https://speedtest-ams2.digtalocean.com/") +(def url "https://api.groq.com/openai/v1/chat/completions") (def system-msg " You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages. @@ -13,6 +14,24 @@ It is very important that the entire commit is clear and understandable. Only reply with the commit message and nothing else. ") -(def diff (p/check (p/sh "git" "diff" "--cached"))) +(def diff (:out (p/check (p/sh "git" "diff" "--cached")))) -(println diff) \ No newline at end of file +(def message (json/generate-string + {:messages [{:role "system" :content system-msg} + {:role "user" :content diff}] + :model "llama-3.1-70b-versatile" + :temperature 1 + :max_tokens 1024 + :top_p 1 + :stream false + :stop nil})) + +(def response + (curl/post url + {:headers {"Content-Type" "application/json" + "Authorization" (str "Bearer " (System/getenv "GROQ_API_KEY"))} + :body message})) + +(def content (get-in (:choices (json/parse-string (:body response) true)) [0 :message :content])) + +(println content)