Compare commits

5 Commits

Author SHA1 Message Date
b9caddd286 Added instruction to put each change on its own line as a separate sentence in the commit message.
Added instruction not to put quotation marks around the commit message.
2024-08-16 17:30:49 -07:00
4e9a32f501 Added dependency on babashka.fs and babashka.cli.
Introduced functions to find git repository and read/write commit message.
Modified response processing to append to COMMIT_EDITMSG and open in editor.
2024-08-10 11:40:21 -07:00
5fb26e6220 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
2024-08-10 08:12:05 -07:00
abd32275ba Added aicommit.clj script to migrate to babashka clojure. 2024-08-10 06:26:06 -07:00
7476e27e01 Refactor instructions to generate concise and informative git commit messages, removing redundant guidelines and emphasizing clarity and understandability 2024-08-09 18:31:44 -07:00
2 changed files with 58 additions and 7 deletions

View File

@ -7,13 +7,10 @@ system=$(
cat - <<EOF
You are an expert programmer that values clear, unambiguous communication and are specialized in generating concise and informative git commit messages.
Only reply with the commit message and nothing else.
Give description for every change.
Do not include quotes from the diff.
Description should not include a reason only a description.
Description should be one sentence per difference.
Do not include urls.
Do not include headings. for example: 'URLS:'
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.
EOF
)

54
aicommit.clj Executable file
View 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*))