ai_git 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3d2a98e6fef0c0ce3deb757a48e43701f1800d8c524f0cea525a92c8b4ae575
4
- data.tar.gz: 054d32afa6032a6bdfb2d4946673466b2b65ec6628dfecfb359bf67442c54e4e
3
+ metadata.gz: bc3e320bc55f08d7665a8a6ae9123b6b032a4b4a3861cf439b5ff018f14b415a
4
+ data.tar.gz: 055a7bd2bc06b4d0e18aacb318a6aa6725e1632f0bb1b5c4c3ad2ca5930013ab
5
5
  SHA512:
6
- metadata.gz: b9064aeb4a13c6719a3847a41e07e3a933d2404cd7be169cf7806d6efa5ade9d5c3b0f1ebeb12c9951ac1386ec9fe40af83bc8cba5017829f788e1211bc9f566
7
- data.tar.gz: 6eacdb5d1ad3be96c5893466e02e28f2e5886091e5f8ca19fcd6814d31fc2629938bfc18447c3e07b98d6fde28e7582b63f483b0e3631deb0829f2e424d619ad
6
+ metadata.gz: d90a349b399361d0c52fcaec15fec584bb4251197a8a282a7632b5e1078ec571753f8085c6edddf51edffd0f3d6c10ef24b7922afdd6c69df700b564f1f446e1
7
+ data.tar.gz: 603b003ec1cefdae26db68cc026ac1d2950ebd00421e9e1c0fe56c663dc8ae202458a8334bfeef1cd6f1e8cfc9a1d29893578e3e1c34c41b239c8245a11dc744
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AIGit
4
+ module Config
5
+ PROVIDERS = {
6
+ "jan" => {
7
+ default_model: "Jan-v3.5-4B-Q4_K_XL",
8
+ base_url: "http://127.0.0.1:1337",
9
+ endpoint: "/v1/chat/completions",
10
+ request_format: :openai
11
+ },
12
+ "ollama" => {
13
+ default_model: "gemma4:e4b",
14
+ base_url: "http://localhost:11434",
15
+ endpoint: "/api/generate",
16
+ request_format: :ollama
17
+ }
18
+ }.freeze
19
+
20
+ def self.provider
21
+ ENV["AI_GIT_AI_PROVIDER"] || "jan"
22
+ end
23
+
24
+ def self.model_name
25
+ ENV["AI_GIT_MODEL_NAME"] || PROVIDERS[provider][:default_model]
26
+ end
27
+
28
+ def self.base_url
29
+ ENV["AI_GIT_BASE_URL"] || PROVIDERS[provider][:base_url]
30
+ end
31
+
32
+ def self.endpoint
33
+ PROVIDERS[provider][:endpoint]
34
+ end
35
+
36
+ def self.request_format
37
+ PROVIDERS[provider][:request_format]
38
+ end
39
+
40
+ def self.config
41
+ PROVIDERS[provider]
42
+ end
43
+ end
44
+ end
@@ -78,30 +78,53 @@ module AIGit
78
78
  Now generate the commit message:
79
79
  PROMPT
80
80
 
81
- json_body = {
82
- model: model_name,
83
- prompt: prompt,
84
- stream: false,
85
- temperature: 0.3,
86
- top_p: 0.9,
87
- stop: ["\n\n\n", "```", "Here is", "The commit message"],
88
- num_predict: 400
89
- }.to_json
90
-
91
- uri = URI("http://localhost:11434/api/generate")
92
- request = Net::HTTP::Post.new(uri)
93
- request["Content-Type"] = "application/json"
94
- request.body = json_body
95
-
96
- response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
97
- http.request(request)
81
+ if AIGit::Config.request_format == :ollama
82
+ json_body = {
83
+ model: model_name,
84
+ prompt: prompt,
85
+ stream: false,
86
+ temperature: 0.3,
87
+ top_p: 0.9,
88
+ stop: ["\n\n\n", "```", "Here is", "The commit message"],
89
+ num_predict: 400
90
+ }.to_json
91
+
92
+ uri = URI("#{AIGit::Config.base_url}#{AIGit::Config.endpoint}")
93
+ request = Net::HTTP::Post.new(uri)
94
+ request["Content-Type"] = "application/json"
95
+ request.body = json_body
96
+
97
+ response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
98
+ http.request(request)
99
+ end
100
+
101
+ raise "Failed to connect to #{AIGit::Config.provider}. Is it running?" unless response.is_a?(Net::HTTPSuccess)
102
+
103
+ data = JSON.parse(response.body)
104
+ message = data["response"].to_s.strip
105
+ else # Jan AI
106
+ json_body = {
107
+ model: model_name,
108
+ messages: [{ role: "user", content: prompt }],
109
+ stream: false,
110
+ temperature: 0.3
111
+ }.to_json
112
+
113
+ uri = URI("#{AIGit::Config.base_url}#{AIGit::Config.endpoint}")
114
+ request = Net::HTTP::Post.new(uri)
115
+ request["Content-Type"] = "application/json"
116
+ request.body = json_body
117
+
118
+ response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
119
+ http.request(request)
120
+ end
121
+
122
+ raise "Failed to connect to #{AIGit::Config.provider}. Is it running?" unless response.is_a?(Net::HTTPSuccess)
123
+
124
+ data = JSON.parse(response.body)
125
+ message = data["choices"][0]["message"]["content"].to_s.strip
98
126
  end
99
127
 
100
- raise "Failed to connect to Ollama. Is it running?" unless response.is_a?(Net::HTTPSuccess)
101
-
102
- data = JSON.parse(response.body)
103
- message = data["response"].to_s.strip
104
-
105
128
  message = message.gsub(/^(Here is|The commit message is|```|json|markdown)/i, "")
106
129
  .gsub(/^>\s*/, "")
107
130
  .gsub(/\\n/, "\n")
@@ -118,7 +141,8 @@ module AIGit
118
141
  end
119
142
 
120
143
  def call
121
- model_name = ENV["AI_GIT_MODEL_NAME"] || "phi4:14b"
144
+ provider = AIGit::Config.provider
145
+ model_name = AIGit::Config.model_name
122
146
 
123
147
  staged = AIGit::Git.staged_files
124
148
  abort "Error: No staged files. Use `git add` first." if staged.to_s.strip.empty?
@@ -126,6 +150,7 @@ module AIGit
126
150
  diff = AIGit::Git.diff
127
151
  branch = AIGit::Git.current_branch
128
152
 
153
+ puts "\e[1mAI Provider:\e[0m #{provider}"
129
154
  puts "\e[1mModel Name:\e[0m #{model_name}"
130
155
  puts "\e[1mStaged Files:\e[0m #{staged}"
131
156
  puts "\e[1mBranch:\e[0m #{branch}"
@@ -141,7 +166,7 @@ module AIGit
141
166
  AIGit::Git.run_command("git", "commit -m \"#{escaped_msg}\"")
142
167
  puts "\e[1mGit Commited\e[0m"
143
168
 
144
- AIGit::Git.run_command("git", "push")
169
+ AIGit::Git.run_command("git", "push -u origin HEAD")
145
170
  puts "\e[1mGit Pushed\e[0m"
146
171
  end
147
172
 
data/lib/ai_git/review.rb CHANGED
@@ -84,30 +84,53 @@ module AIGit
84
84
  Now review the staged changes:
85
85
  PROMPT
86
86
 
87
- json_body = {
88
- model: model_name,
89
- prompt: prompt,
90
- stream: false,
91
- temperature: 0.2,
92
- top_p: 0.9,
93
- stop: ["\n\n\n", "```", "Here is", "The review"],
94
- num_predict: 600
95
- }.to_json
96
-
97
- uri = URI("http://localhost:11434/api/generate")
98
- request = Net::HTTP::Post.new(uri)
99
- request["Content-Type"] = "application/json"
100
- request.body = json_body
101
-
102
- response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
103
- http.request(request)
87
+ if AIGit::Config.request_format == :ollama
88
+ json_body = {
89
+ model: model_name,
90
+ prompt: prompt,
91
+ stream: false,
92
+ temperature: 0.2,
93
+ top_p: 0.9,
94
+ stop: ["\n\n\n", "```", "Here is", "The review"],
95
+ num_predict: 600
96
+ }.to_json
97
+
98
+ uri = URI("#{AIGit::Config.base_url}#{AIGit::Config.endpoint}")
99
+ request = Net::HTTP::Post.new(uri)
100
+ request["Content-Type"] = "application/json"
101
+ request.body = json_body
102
+
103
+ response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
104
+ http.request(request)
105
+ end
106
+
107
+ raise "Failed to connect to #{AIGit::Config.provider}. Is it running?" unless response.is_a?(Net::HTTPSuccess)
108
+
109
+ data = JSON.parse(response.body)
110
+ review = data["response"].to_s.strip
111
+ else # Jan AI
112
+ json_body = {
113
+ model: model_name,
114
+ messages: [{ role: "user", content: prompt }],
115
+ stream: false,
116
+ temperature: 0.2
117
+ }.to_json
118
+
119
+ uri = URI("#{AIGit::Config.base_url}#{AIGit::Config.endpoint}")
120
+ request = Net::HTTP::Post.new(uri)
121
+ request["Content-Type"] = "application/json"
122
+ request.body = json_body
123
+
124
+ response = Net::HTTP.start(uri.host, uri.port, read_timeout: 120) do |http|
125
+ http.request(request)
126
+ end
127
+
128
+ raise "Failed to connect to #{AIGit::Config.provider}. Is it running?" unless response.is_a?(Net::HTTPSuccess)
129
+
130
+ data = JSON.parse(response.body)
131
+ review = data["choices"][0]["message"]["content"].to_s.strip
104
132
  end
105
133
 
106
- raise "Failed to connect to Ollama. Is it running?" unless response.is_a?(Net::HTTPSuccess)
107
-
108
- data = JSON.parse(response.body)
109
- review = data["response"].to_s.strip
110
-
111
134
  review = review.gsub(/^(Here is|The review is|```|json|markdown)/i, "")
112
135
  .gsub(/^>\s*/, "")
113
136
  .gsub(/\\n/, "\n")
@@ -123,7 +146,8 @@ module AIGit
123
146
  end
124
147
 
125
148
  def call
126
- model_name = ENV["AI_GIT_MODEL_NAME"] || "phi4:14b"
149
+ provider = AIGit::Config.provider
150
+ model_name = AIGit::Config.model_name
127
151
 
128
152
  staged = AIGit::Git.staged_files
129
153
  abort "Error: No staged files. Use `git add` first." if staged.to_s.strip.empty?
@@ -131,6 +155,7 @@ module AIGit
131
155
  diff = AIGit::Git.diff
132
156
  branch = AIGit::Git.current_branch
133
157
 
158
+ puts "\e[1mAI Provider:\e[0m #{provider}"
134
159
  puts "\e[1mModel Name:\e[0m #{model_name}"
135
160
  puts "\e[1mStaged Files:\e[0m #{staged}"
136
161
  puts "\e[1mBranch:\e[0m #{branch}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AIGit
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ai_git.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "ai_git/version"
4
+ require_relative "ai_git/config"
4
5
  require_relative "ai_git/git"
5
6
  require_relative "ai_git/review"
6
7
  require_relative "ai_git/default"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaíque Kandy Koga
@@ -17,6 +17,7 @@ extra_rdoc_files: []
17
17
  files:
18
18
  - bin/ai_git
19
19
  - lib/ai_git.rb
20
+ - lib/ai_git/config.rb
20
21
  - lib/ai_git/default.rb
21
22
  - lib/ai_git/git.rb
22
23
  - lib/ai_git/review.rb
@@ -32,7 +33,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
33
  requirements:
33
34
  - - ">="
34
35
  - !ruby/object:Gem::Version
35
- version: '4.0'
36
+ version: '0'
36
37
  required_rubygems_version: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - ">="