Compare commits
4 Commits
master
...
refactor-t
Author | SHA1 | Date | |
---|---|---|---|
b9caddd286 | |||
4e9a32f501 | |||
5fb26e6220 | |||
abd32275ba |
54
aicommit.clj
Executable file
54
aicommit.clj
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(require '[babashka.curl :as curl]
|
||||||
|
'[babashka.process :as p]
|
||||||
|
'[cheshire.core :as json]
|
||||||
|
'[babashka.fs :as fs]
|
||||||
|
'[babashka.cli :as cli])
|
||||||
|
|
||||||
|
(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.
|
||||||
|
Your task is to generate a concise, informative git commit message based on the following git diff.
|
||||||
|
Be sure that the commit message reflects the entire diff.
|
||||||
|
It is very important that the entire commit is clear and understandable.
|
||||||
|
Only reply with the commit message and nothing else.
|
||||||
|
Put each change on it's own line as a separate sentance.
|
||||||
|
Don't put quotation marks around the message.
|
||||||
|
")
|
||||||
|
|
||||||
|
(def diff (:out (p/check (p/sh "git" "diff" "--cached"))))
|
||||||
|
|
||||||
|
(defn find-git
|
||||||
|
[dir]
|
||||||
|
(loop [d dir]
|
||||||
|
(if (fs/directory? (fs/path d ".git"))
|
||||||
|
(fs/path d ".git")
|
||||||
|
(recur (fs/parent d)))))
|
||||||
|
|
||||||
|
(def commit-message-path (fs/unixify (fs/path (find-git (fs/cwd)) "COMMIT_EDITMSG")))
|
||||||
|
|
||||||
|
(def commit-message (slurp commit-message-path))
|
||||||
|
|
||||||
|
(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]))
|
||||||
|
|
||||||
|
(spit commit-message-path (str content "\n" commit-message))
|
||||||
|
|
||||||
|
(p/shell (System/getenv "EDITOR") (first *command-line-args*))
|
Loading…
Reference in New Issue
Block a user