This repository was archived by the owner on Jul 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff-summarizer-deepseek.mjs
More file actions
58 lines (50 loc) · 1.93 KB
/
diff-summarizer-deepseek.mjs
File metadata and controls
58 lines (50 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import OpenAI from 'openai';
import { copyToClipboard, getGitDiff } from './utils.mjs';
import { aiPrompt } from './ai-prompt.mjs';
async function generateCommitMessage() {
const openai = new OpenAI({
apiKey: 'lm-studio',
baseURL: 'http://localhost:1234/v1',
});
// Truncate the Git diff to avoid exceeding context length
const diffContent = getGitDiff().slice(0, 20000); // Adjust as needed
try {
const response = await openai.chat.completions.create({
model: 'deepseek-r1-distill-qwen-32b',
messages: [
{
role: 'system',
content: aiPrompt + '\n\nDo not explain your reasoning or show chain of thought. Provide only the final output.'
},
{
role: 'user',
content: diffContent
}
],
temperature: 0.1, // Lower temperature for less creativity
max_tokens: 512, // Reduce max_tokens to leave room for input
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
stream: false
});
// Extract the model's response
let commitMessage = response.choices[0].message.content.trim();
// Remove the <think> section and its contents
commitMessage = removeThinkSection(commitMessage);
// Copy the cleaned commit message to the clipboard
copyToClipboard(commitMessage);
} catch (error) {
console.error('Error generating commit message:', error);
}
}
/**
* Removes the <think> section and its contents from the model's output.
* @param {string} text - The model's output.
* @returns {string} - The cleaned output.
*/
function removeThinkSection(text) {
// Use a regex to remove the <think> section and its contents
return text.replace(/<think>[\s\S]*?<\/think>/g, '').trim();
}
generateCommitMessage();