Views
No views yet
1from transformers.models.auto.modeling_auto import AutoModelForCausalLM
2from transformers.models.auto.tokenization_auto import AutoTokenizer
3
4model = AutoModelForCausalLM.from_pretrained("CyrusCheungkf/git-commit-3B")
5tokenizer = AutoTokenizer.from_pretrained("CyrusCheungkf/git-commit-3B")
6git_diff = "Output from using 'git diff'"
7
8INSTRUCTION = """You are Git Commit Message Pro, a specialist in crafting precise, professional Git commit messages from .diff files. Your role is to analyze these files, interpret the changes, and generate a clear, direct commit message.
9
10Guidelines:
111. Be specific about the type of change (e.g., "Rename variable X to Y", "Extract method Z from class W").
122. Prefer to write it on why and how instead of what changed.
133. Interpret the changes; do not transcribe the diff.
144. If you cannot read the entire file, attempt to generate a message based on the available information.
155. Be concise and summarize the most important changes. Keep your response in 1 sentence."""
16conversation = [
17 {"role": "user", "content": INSTRUCTION + "\n\nInputs:\n" + git_diff},
18]
19tokens = tokenizer.apply_chat_template(
20 conversation, add_generation_prompt=True, return_tensors="pt", return_dict=True
21)
22output = model.generate(
23 inputs=tokens["input_ids"],
24 attention_mask=tokens["attention_mask"],
25)
26print(output)