dorian-commit 0.4.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/commit +28 -5
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cfd254ac72b0cb783a5617779fb203ed8fe84cec8685702a9f52ab18ac6de0b
|
4
|
+
data.tar.gz: 8158f5df736374fa3c9fc3e203755344dcdd93610d42227c127da25f14d577e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a328add85459b999de4436e92db6ea24cfd03912d3c0672fabe13823d24a88cfbe247db4bb2b0a2c43b1be596e3144ca2cbb5d2e67015bb25cdbcce7b480d1bb
|
7
|
+
data.tar.gz: 9dc85ba07932fc0be0c5781b4c5d6d94bbe5de98d686c61dc8cd234f9982608f350bd3b8436735ca48c483d2466f784c50d09994ac44325b4bf9b30a17adae91
|
data/bin/commit
CHANGED
@@ -5,6 +5,7 @@ require "dorian/arguments"
|
|
5
5
|
require "git"
|
6
6
|
require "json"
|
7
7
|
require "net/http"
|
8
|
+
require "tiktoken_ruby"
|
8
9
|
require "uri"
|
9
10
|
|
10
11
|
TOKEN_FILE = File.join(Dir.home, ".commit")
|
@@ -23,7 +24,7 @@ PROMPT_2 = "for the following diff:"
|
|
23
24
|
PROMPT_3 = "for the following git status:"
|
24
25
|
PROMPT_4 = "for the following comment:"
|
25
26
|
|
26
|
-
parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
|
27
|
+
parsed = Dorian::Arguments.parse(tokens: { type: :integer, alias: :t, default: 1000 }, version: { alias: :v }, help: { alias: :h })
|
27
28
|
|
28
29
|
abort parsed.help if parsed.options.help
|
29
30
|
|
@@ -38,6 +39,30 @@ content_4 += parsed.files.map { |file| File.read(file) }.join("\n")
|
|
38
39
|
|
39
40
|
abort "no staged files" if content_2.empty?
|
40
41
|
|
42
|
+
encoder = Tiktoken.encoding_for_model("gpt-4o")
|
43
|
+
|
44
|
+
content_2_encoded = encoder.encode(content_2)
|
45
|
+
|
46
|
+
if content_2_encoded.length > parsed.options.tokens
|
47
|
+
messages_2 = []
|
48
|
+
else
|
49
|
+
messages_2 = [
|
50
|
+
{ role: :system, content: PROMPT_2 },
|
51
|
+
{ role: :user, content: content_2 }
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
content_3_encoded = encoder.encode(content_3)
|
56
|
+
|
57
|
+
if content_3_encoded.length > parsed.options.tokens
|
58
|
+
messages_3 = []
|
59
|
+
else
|
60
|
+
messages_3 = [
|
61
|
+
{ role: :system, content: PROMPT_3 },
|
62
|
+
{ role: :user, content: content_3 },
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
41
66
|
if content_4.empty?
|
42
67
|
messages_4 = []
|
43
68
|
else
|
@@ -65,10 +90,8 @@ request.body = {
|
|
65
90
|
model: "gpt-4o",
|
66
91
|
messages: [
|
67
92
|
{ role: :system, content: PROMPT_1 },
|
68
|
-
|
69
|
-
|
70
|
-
{ role: :system, content: PROMPT_3 },
|
71
|
-
{ role: :user, content: content_3 },
|
93
|
+
*messages_2,
|
94
|
+
*messages_3,
|
72
95
|
*messages_4
|
73
96
|
]
|
74
97
|
}.to_json
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dorian-arguments
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: git
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,7 +39,7 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: tiktoken_ruby
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|