mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-12 23:28:16 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
144f6b4499 | ||
|
|
4b7cb77ea4 | ||
|
|
58d2eb1b09 | ||
|
|
9897d2ff5f | ||
|
|
17a28d697b |
@@ -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
4
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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/**/*"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user