llmed 0.1.14 → 0.1.16
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 +4 -4
- data/lib/llm.rb +15 -16
- data/lib/llmed.rb +16 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09c50ad00371154217526840bd23d9905bdd41db9603e677a94508f27518c09f'
|
4
|
+
data.tar.gz: fdea6c57beeb69aa45a5324f4533431ca732da087538130e4c483c22b6ceef0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25adbc23488893e2c29ba284e3da0ab45fc466d5258bc6f54753a87bf2eb7273d0eafbfe95eda1b77d1deaad58bc897d47d3d6cdc7e83eac4f3cb43a712bf0ba
|
7
|
+
data.tar.gz: f1fe49760f451316f9ff3155c482155c3fb6653139f386602175dab09dc95b578d90cc9147218ede345246cfb2fdbbebf44b5e7e271d01c7ab30e04aeafe138b
|
data/lib/llm.rb
CHANGED
@@ -16,20 +16,7 @@ class LLMed
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
def initialize(response, tokens)
|
21
|
-
@response = response
|
22
|
-
@tokens = tokens
|
23
|
-
end
|
24
|
-
|
25
|
-
def source_code
|
26
|
-
@response
|
27
|
-
end
|
28
|
-
|
29
|
-
def total_tokens
|
30
|
-
@tokens
|
31
|
-
end
|
32
|
-
end
|
19
|
+
Response = Struct.new(:provider, :model, :source_code, :total_tokens, keyword_init: true)
|
33
20
|
|
34
21
|
class OpenAI
|
35
22
|
def initialize(**args)
|
@@ -47,7 +34,16 @@ class LLMed
|
|
47
34
|
end
|
48
35
|
|
49
36
|
llm_response = @llm.chat(messages: messages)
|
50
|
-
Response.new(
|
37
|
+
Response.new({ provider: :openai,
|
38
|
+
model: @llm.chat_parameters[:model],
|
39
|
+
source_code: source_code(llm_response.chat_completion),
|
40
|
+
total_tokens: llm_response.total_tokens })
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def source_code(content)
|
46
|
+
content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|c(pp)?)/, '')
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
@@ -59,7 +55,10 @@ class LLMed
|
|
59
55
|
def chat(messages: [])
|
60
56
|
@output = messages.map { |m| m[:content] }.join("\n")
|
61
57
|
|
62
|
-
Response.new(
|
58
|
+
Response.new({ provider: :test,
|
59
|
+
model: 'test',
|
60
|
+
source_code: @output,
|
61
|
+
total_tokens: 0 })
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
data/lib/llmed.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'pp'
|
5
5
|
require 'csv'
|
6
|
+
require 'json'
|
6
7
|
require 'pathname'
|
7
8
|
require 'fileutils'
|
8
9
|
require 'forwardable'
|
@@ -176,14 +177,21 @@ You must only modify the following source code:
|
|
176
177
|
end
|
177
178
|
end
|
178
179
|
|
179
|
-
def write_statistics(release_dir,
|
180
|
+
def write_statistics(release_dir, response)
|
180
181
|
return unless @output_file.is_a?(String)
|
181
182
|
|
182
183
|
statistics_file = Pathname.new(release_dir) + "#{@output_file}.statistics"
|
183
184
|
|
184
185
|
File.open(statistics_file, 'a') do |file|
|
185
|
-
|
186
|
-
|
186
|
+
stat = {
|
187
|
+
inserted_at: Time.now.to_i,
|
188
|
+
name: @name,
|
189
|
+
provider: response.provider,
|
190
|
+
model: response.model,
|
191
|
+
release: @release,
|
192
|
+
total_tokens: response.total_tokens
|
193
|
+
}
|
194
|
+
file.puts stat.to_json
|
187
195
|
end
|
188
196
|
@logger.info("APPLICATION #{@name} WROTE STATISTICS FILE #{statistics_file}")
|
189
197
|
end
|
@@ -217,13 +225,13 @@ You must only modify the following source code:
|
|
217
225
|
end
|
218
226
|
|
219
227
|
def compile(output_dir:, release_dir: nil)
|
220
|
-
@applications.each
|
221
|
-
app.notify(
|
228
|
+
@applications.each do |app|
|
229
|
+
app.notify('COMPILE START')
|
222
230
|
_, elapsed_seconds = measure do
|
223
231
|
compile_application(app, output_dir, release_dir)
|
224
232
|
end
|
225
233
|
app.notify("COMPILE DONE #{elapsed_seconds}")
|
226
|
-
|
234
|
+
end
|
227
235
|
end
|
228
236
|
|
229
237
|
private
|
@@ -247,19 +255,13 @@ You must only modify the following source code:
|
|
247
255
|
end
|
248
256
|
|
249
257
|
llm_response = llm.chat(messages: messages)
|
250
|
-
response = llm_response.source_code
|
251
258
|
@logger.info("APPLICATION #{app.name} TOTAL TOKENS #{llm_response.total_tokens}")
|
252
|
-
write_output(app, output_dir, source_code
|
259
|
+
write_output(app, output_dir, llm_response.source_code)
|
253
260
|
write_statistics(app, release_dir, llm_response)
|
254
261
|
end
|
255
262
|
|
256
|
-
def source_code(content)
|
257
|
-
# TODO: by provider?
|
258
|
-
content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|c(pp)?)/, '')
|
259
|
-
end
|
260
|
-
|
261
263
|
def write_statistics(app, release_dir, response)
|
262
|
-
app.write_statistics(release_dir, response
|
264
|
+
app.write_statistics(release_dir, response)
|
263
265
|
end
|
264
266
|
|
265
267
|
def write_output(app, output_dir, output)
|