-
Notifications
You must be signed in to change notification settings - Fork 74
Feature/commit more changes #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Arthur-MONNET
wants to merge
14
commits into
insulineru:main
Choose a base branch
from
Arthur-MONNET:feature/commit-more-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
156d081
first commit
35caf89
feat: enhance diff parsing and introduce interactive commit process
3338191
🚑 fix: increase MAX_TOKENS to 128000 in index.js and openai.js
13499fe
🚑 fix: update console log to dynamically display token and character …
5177af2
Delete .idea/.gitignore
Arthur-MONNET c126e43
Delete .idea/ai-commit.iml
Arthur-MONNET 756c8e5
Delete .idea/modules.xml
Arthur-MONNET 70960d6
Delete .idea/php.xml
Arthur-MONNET 94de501
Delete .idea/vcs.xml
Arthur-MONNET 4bdfb7f
🔧 chore: update .gitignore to ignore '.idea/' directory
a5d910f
fix: update dependencies to latest versions
1675f16
fix: update comments and improve function descriptions for clarity
d88a681
✨ feat: add logging of prompts to generateAICommit function
4adefda
🚑 fix: remove console.log statement from generateAICommit function to…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,79 +1,83 @@ | ||
| import { ChatGPTAPI } from "chatgpt"; | ||
|
|
||
| import { encode } from 'gpt-3-encoder'; | ||
| import inquirer from "inquirer"; | ||
| import { AI_PROVIDER } from "./config.js" | ||
|
|
||
| const FEE_PER_1K_TOKENS = 0.02; | ||
| const MAX_TOKENS = 128000; | ||
| //this is the approximate cost of a completion (answer) fee from CHATGPT | ||
| // this is the approximate cost of a completion (answer) fee from CHATGPT | ||
| const FEE_COMPLETION = 0.001; | ||
|
|
||
| const openai = { | ||
| sendMessage: async (input, {apiKey, model}) => { | ||
| console.log("prompting chat gpt..."); | ||
| console.log("prompt: ", input); | ||
| const api = new ChatGPTAPI({ | ||
| apiKey, | ||
| completionParams: { | ||
| model: "gpt-4-1106-preview", | ||
| }, | ||
| }); | ||
| const { text } = await api.sendMessage(input); | ||
|
|
||
| return text; | ||
| }, | ||
|
|
||
| getPromptForSingleCommit: (diff, {commitType, language}) => { | ||
| sendMessage: async (input, {apiKey, model}) => { | ||
| console.log("prompting chat gpt..."); | ||
| console.log("prompt: ", input); | ||
| const api = new ChatGPTAPI({ | ||
| apiKey, | ||
| completionParams: { | ||
| model: "gpt-4-1106-preview", | ||
| }, | ||
| }); | ||
| const { text } = await api.sendMessage(input); | ||
|
|
||
| return ( | ||
| "I want you to act as the author of a commit message in git." + | ||
| `I'll enter a git diff, and your job is to convert it into a useful commit message in ${language} language` + | ||
| (commitType ? ` with commit type '${commitType}'. ` : ". ") + | ||
| "Do not preface the commit with anything, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>): " + | ||
| '\n\n'+ | ||
| diff | ||
| ); | ||
| }, | ||
| return text; | ||
| }, | ||
|
|
||
| getPromptForMultipleCommits: (diff, {commitType, numOptions, language}) => { | ||
| const prompt = | ||
| "I want you to act as the author of a commit message in git." + | ||
| `I'll enter a git diff, and your job is to convert it into a useful commit message in ${language} language` + | ||
| (commitType ? ` with commit type '${commitType}.', ` : ", ") + | ||
| `and make ${numOptions} options that are separated by ";".` + | ||
| "For each option, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>):" + | ||
| diff; | ||
| getPromptForSingleCommit: (diff, {commitType, language}) => { | ||
| return ( | ||
| "I want you to act as the author of a commit message in git. " + | ||
| `I'll enter a git diff, and your job is to convert it into a useful commit message in ${language} language` + | ||
| (commitType ? ` with commit type '${commitType}'. ` : ". ") + | ||
| "Do not preface the commit with anything, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>): " + | ||
| '\n\n'+ | ||
| diff | ||
| ); | ||
| }, | ||
|
|
||
| return prompt; | ||
| }, | ||
| getPromptForMultipleCommits: (diff, {commitType, numOptions, language}) => { | ||
| const prompt = | ||
| "I want you to act as the author of a commit message in git. " + | ||
| `I'll enter a git diff, and your job is to convert it into a useful commit message in ${language} language` + | ||
| (commitType ? ` with commit type '${commitType}.', ` : ", ") + | ||
| `and make ${numOptions} options that are separated by ";".` + | ||
| "For each option, use the present tense, return the full sentence, and use the conventional commits specification (<type in lowercase>: <subject>):" + | ||
| diff; | ||
|
|
||
| filterApi: async ({ prompt, numCompletion = 1, filterFee }) => { | ||
| const numTokens = encode(prompt).length; | ||
| const fee = numTokens / 1000 * FEE_PER_1K_TOKENS + (FEE_COMPLETION * numCompletion); | ||
| return prompt; | ||
| }, | ||
|
|
||
| if (numTokens > MAX_TOKENS) { | ||
| console.log("The commit diff is too large for the ChatGPT API. Max 4k tokens or ~8k characters. "); | ||
| return false; | ||
| } | ||
| // New function to prompt for a summary of the diff | ||
| getPromptForDiffSummary: (diff, filename, {language}) => { | ||
| return ( | ||
| `Summarize the following git diff for the file '${filename}' in ${language} language. Be concise and focus on the main changes:\n\n` + | ||
| diff | ||
| ); | ||
| }, | ||
|
|
||
| if (filterFee) { | ||
| console.log(`This will cost you ~$${+fee.toFixed(3)} for using the API.`); | ||
| const answer = await inquirer.prompt([ | ||
| { | ||
| type: "confirm", | ||
| name: "continue", | ||
| message: "Do you want to continue 💸?", | ||
| default: true, | ||
| }, | ||
| ]); | ||
| if (!answer.continue) return false; | ||
| } | ||
| filterApi: async ({ prompt, numCompletion = 1, filterFee }) => { | ||
| const numTokens = encode(prompt).length; | ||
| const fee = numTokens / 1000 * FEE_PER_1K_TOKENS + (FEE_COMPLETION * numCompletion); | ||
|
|
||
| return true; | ||
| } | ||
| if (numTokens > MAX_TOKENS) { | ||
| console.log(`The commit diff is too large for the ChatGPT API. Max ${MAX_TOKENS/1000}k tokens or ~${MAX_TOKENS/500} characters.`); | ||
| return false; | ||
| } | ||
|
|
||
| if (filterFee) { | ||
| console.log(`This will cost you ~$${+fee.toFixed(3)} for using the API.`); | ||
| const answer = await inquirer.prompt([ | ||
| { | ||
| type: "confirm", | ||
| name: "continue", | ||
| message: "Do you want to continue 💸?", | ||
| default: true, | ||
| }, | ||
| ]); | ||
| if (!answer.continue) return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| export default openai; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.