Compare commits

...

5 Commits

Author SHA1 Message Date
di-sukharev
144f6b4499 0.0.2 2023-03-06 18:52:08 +08:00
di-sukharev
4b7cb77ea4 * 📦 chore(package.json): add repository and author fields
The repository field is added to specify the URL of the project's repository. The author field is updated to include the author's GitHub profile URL.
2023-03-06 18:47:22 +08:00
di-sukharev
58d2eb1b09 * 🎨 style(README.md): update OpenCommit logo filename
The logo filename has been updated to match the new filename of the logo file.
2023-03-06 18:41:36 +08:00
di-sukharev
9897d2ff5f * 📝 docs(README.md): add examples section
Added an examples section to the README.md file to showcase how OpenCommit works. The section includes a link to the relevant commit and a brief description of the configurable options.
2023-03-06 18:40:31 +08:00
di-sukharev
17a28d697b * 🐛 fix(generateCommitMessageFromGitDiff.ts): add length of initial messages prompt to check for maximum request tokens
*  feat(generateCommitMessageFromGitDiff.ts): add support for generating commit messages with chat completion
The length of the initial messages prompt is now added to the check for maximum request tokens to ensure that the request does not exceed the maximum allowed tokens. Support for generating commit messages with chat completion has been added, which allows for more efficient and streamlined commit message generation.
2023-03-06 18:38:33 +08:00
4 changed files with 20 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
<div align="center">
<div>
<img src=".github/OC-grad.svg" alt="OpenCommit logo"/>
<img src=".github/logo-grad.svg" alt="OpenCommit logo"/>
<h1 align="center">OpenCommit</h1>
<h4 align="center">Author <a href="https://github.com/di-sukharev">@di-sukharev</a> <a href="https://twitter.com/io_Y_oi"><img src="https://img.shields.io/twitter/follow/io_Y_oi?style=flat&label=io_Y_oi&logo=twitter&color=0bf&logoColor=fff" align="center"></a>
</h4>
@@ -11,6 +11,10 @@
---
## Examples
Look into [the commits](https://github.com/di-sukharev/opencommit/commit/4795a695800686c42e7c72fca7569103d21cd510) to see how OpenCommit works. Emoji and long commit description text is configurable.
## Setup
> The minimum supported version of Node.js is the latest v14. Check your Node.js version with `node --version`.

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "open-commit",
"version": "0.0.1",
"version": "0.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "open-commit",
"version": "0.0.1",
"version": "0.0.2",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "0.0.1",
"version": "0.0.2",
"description": "AI generates conventional commits with mind-blowing accuracy.",
"keywords": [
"git",
@@ -15,8 +15,11 @@
"opencommit": "./out/cli.mjs",
"oc": "./out/cli.mjs"
},
"repository": {
"url": "https://github.com/di-sukharev/opencommit"
},
"type": "module",
"author": "",
"author": "https://github.com/di-sukharev",
"license": "ISC",
"files": [
"out/**/*"

View File

@@ -77,13 +77,17 @@ interface GenerateCommitMessageError {
error: GenerateCommitMessageErrorEnum;
}
const INIT_MESSAGES_PROMPT_LENGTH = INIT_MESSAGES_PROMPT.map(
(msg) => msg.content
).join('').length;
export const generateCommitMessageWithChatCompletion = async (
diff: string
): Promise<string | GenerateCommitMessageError> => {
try {
const MAX_REQ_TOKENS = 3900;
if (diff.length >= MAX_REQ_TOKENS) {
if (INIT_MESSAGES_PROMPT_LENGTH + diff.length >= MAX_REQ_TOKENS) {
const separator = 'diff --git ';
const diffByFiles = diff.split(separator).slice(1);
@@ -91,11 +95,13 @@ export const generateCommitMessageWithChatCompletion = async (
const commitMessages = [];
for (const diffFile of diffByFiles) {
if (diffFile.length >= MAX_REQ_TOKENS) continue;
if (INIT_MESSAGES_PROMPT_LENGTH + diffFile.length >= MAX_REQ_TOKENS)
continue;
const messages = generateCommitMessageChatCompletionPrompt(
separator + diffFile
);
const commitMessage = await api.generateCommitMessage(messages);
// TODO: handle this edge case