@twsc/coder
v1.1.1
Published
Git operator with ai gpt
Downloads
2
Readme
Coder
A CLI write in JS language that writes git commit message or do a code review brief for you using LLama AI (codeLLama, llama2) and easy install git hooks for prepare commit.
Installation
node version >= 16 Currently, support method of installation with npm, and binary:
- install with npm
npm install -g @twsc/coder
Uninstall
npm uninstall -g @twsc/coder
Setup
Please get your llm api key and url (default is demo side for now)
Please do not copy the provided sample
coder config set LLM_URL https://api-ffm.twcc.ai/text-generation
coder config set LLM_TOKEN oooooooo-1af4-49cb-8ccf-xxxxxxxxxxxx
coder config set MODEL <your model name>
Usage
There are two methods for generating a commit message using the coder command. The first is CLI mode, and the second is Git Hook.
CLI mode
You can use coder
to generate a code review message for your staged changes:
coder review
You can call coder
directly to generate a commit message for your staged changes:
--preview
: you can preview the ummarize from ai model
git add <file...>
coder commit --preview
--diffUnifed
: Generate diffs with<n>
lines
coder commit --preview --diffUnifed 5
--excludeList
: can ingore staged file
coder commit --preview --excludeList README.md .env
--model
: change the default model (meta-codellama-34b-instruct
,meta-llama2-70b-chat
)
coder commit --preview --model meta-llama2-70b-chat
--promptOnly
: show the prompt, not send the request to gpt
coder commit --preview --promptOnly
--amend
: to replace current commit.
coder commit --amend
--maxTokens
: set the maxumun number of tokens to genreate(defualt 1000)
coder commit --preview --maxTokens 2000
--templateFolder
: set the git commit message custom format
# make sure you format file name is 'commit.message.hbs'
coder commit --preview --templateFolder /Users/custom/folder
--promptFolder
: set the custom system prompt
# summarize.title.hbs: to summary your commit title
# summarize.file.diff.hbs: to summary your commit change
# conventional.commit.hbs: to summary your commit types (feat, modify...)
coder commit --preview --promptFolder /Users/custom/folder
--language
: change commit message language (en, tw, cn, ja)
coder commit --language tw
You can set config with cli
coder config set LLM_URL https://api-ffm.twcc.ai/text-generation
coder config set TEMPERATURE 0.1
and verify the /Users/user/.config/coder/.env
cat /Users/user/.config/coder/.env
LLM_URL=https://api-ffm.twcc.ai/text-generation
TEMPERATURE=0.1
echo $LLM_URL
https://api-ffm.twcc.ai/text-generation
echo $TEMPERATURE
0.1
You also can modify the /Users/<user>/.config/coder/.env
directly.
If you set the config to .env, the coder will priority use .env
coder config set MAXTOKENS 500
coder commit --maxTokens 1000
# the max tokens will be 500
If you want remove the env variable from .env, you have two options to do this
- remove from .env
- use CLI
coder config unset TEMPERATURE
Available ENVS
- DIFFUNIFIED
- MAXTOKENS
- LANGUAGE
- MODEL
- TEMPLATEFOLDER
- PROMPTFOLDER
- TEMPERATURE
- TOP_K
- TOP_P
- LLM_URL
- LLM_TOKEN
Git hook
You can use the prepare-commit-msg
hook to integrate coder
with Git. This allows you to use Git normally and edit the commit message before committing.
git commit will trigger coder to summary message to your editor, and It will force commit the message whatever you use
q!
or:wq
. If you want abort the message, please usegit reset HEAD^
Install
coder hook install
Uninstall
coder hook uninstall
Custom
If you want custom the system prompt, you can create the tempalte in /Users/<user>/.config/coder/
or set up your own template path coder config set PROMPTFOLDER <your path>
.
!Notice the file name must be correct
Default template
!
{{ key }}
please do not change
- commit.message.hbs
{{ summarizePrefix }}: {{ summarizeTitle }}
{{ summarizeMessage }}
- summarize.title.hbs
You are an expert programmer, and you are trying to title a pull request.
You went over every file that was changed in it.
For some of these files changes were too big and were omitted in the files diff summary.
Please summarize the pull request into a single specific theme.
Write your response using the imperative tense following the kernel git commit style guide.
Write a high level title.
Do not repeat the commit summaries or the file summaries.
Do not list individual changes in the title.
EXAMPLE SUMMARY COMMENTS:
Raise the amount of returned recordings
Switch to internal API for completions
Lower numeric tolerance for test files
THE FILE SUMMARIES:
###
{{ summaryPoints }}
###
To write only one line, no more than 50 characters.
- summarize.file.diff.hbs
You are an expert programmer, and you are trying to summarize a git diff.
Reminders about the git diff format:
For every file, there are a few metadata lines, like (for example):
diff --git a/lib/index.js b/lib/index.js
index aadf691..bfef603 100644
--- a/lib/index.js
+++ b/lib/index.js
This means that `lib/index.js` was modified in this commit. Note that this is only an example.
Then there is a specifier of the lines that were modified.
A line starting with `+` means it was added.
A line that starting with `-` means that line was deleted.
A line that starts with neither `+` nor `-` is code given for context and better understanding.
It is not part of the diff.
After the git diff of the first file, there will be an empty line, and then the git diff of the next file.
Do not include the file name as another part of the comment.
Do not use the characters `[` or `]` in the summary.
Write every summary comment in a new line.
Comments should be in a bullet point list, each line starting with a `-`.
The summary should not include comments copied from the code.
The output should be easily readable. When in doubt, write less comments and not more. Do not output comments that
simply repeat the contents of the file.
Readability is top priority. Write only the most important comments about the diff.
THE GIT DIFF TO BE SUMMARIZED:
###
{{ fileDiffs }}
###
- conventional.commit.hbs
You are an expert programmer, and you are trying to summarize a code change.
You went over every file that was changed in it.
For some of these files changes where too big and were omitted in the files diff summary.
Determine the best label for the commit.
Only label please.
Here are the labels you can choose from:
- build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
- chore: Updating libraries, copyrights or other repo setting, includes updating dependencies.
- ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, GitHub Actions)
- docs: Non-code changes, such as fixing typos or adding new documentation (example scopes: Markdown file)
- feat: a commit of the type feat introduces a new feature to the codebase
- fix: A commit of the type fix patches a bug in your codebase
- perf: A code change that improves performance
- refactor: A code change that neither fixes a bug nor adds a feature
- style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
- test: Adding missing tests or correcting existing tests
THE FILE SUMMARIES:
###
{{ summaryPoints }}
###
Based on the changes described in the file summaries, What's the best label for the commit? Your answer must be one of
the labels above. Don't describe the changes, just write the label.