llmed 0.1.13 → 0.1.15
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 -13
- 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: 7dd74c504b8024dde4755e051de6d6ca6333b185ee7f4ff0866931ba81792af5
|
4
|
+
data.tar.gz: 89da5796998cff94a9712c082aa8e8adfb197e4ff08755b597e3da5d8cfd810f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4efd2e38dd85bf7b38044fa4bc69916fcfa664762d18fe64059ec69fda636e90357664f9e260ffc35a46b83de703097a050f8064454729ad68a94a1d117ee5ca
|
7
|
+
data.tar.gz: e7a1026830d65666850550d3eaea06c9d9ff9f80333d72f109ccc6a70ce99c32d649c2b6e142d3e6936a34d12be30154395833c8b35db6fed76638eaa20d66f7
|
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 << stat.to_json
|
187
195
|
end
|
188
196
|
@logger.info("APPLICATION #{@name} WROTE STATISTICS FILE #{statistics_file}")
|
189
197
|
end
|
@@ -217,12 +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
|
228
|
+
@applications.each do |app|
|
229
|
+
app.notify('COMPILE START')
|
221
230
|
_, elapsed_seconds = measure do
|
222
231
|
compile_application(app, output_dir, release_dir)
|
223
232
|
end
|
224
233
|
app.notify("COMPILE DONE #{elapsed_seconds}")
|
225
|
-
|
234
|
+
end
|
226
235
|
end
|
227
236
|
|
228
237
|
private
|
@@ -246,19 +255,13 @@ You must only modify the following source code:
|
|
246
255
|
end
|
247
256
|
|
248
257
|
llm_response = llm.chat(messages: messages)
|
249
|
-
response = llm_response.source_code
|
250
258
|
@logger.info("APPLICATION #{app.name} TOTAL TOKENS #{llm_response.total_tokens}")
|
251
|
-
write_output(app, output_dir, source_code
|
259
|
+
write_output(app, output_dir, llm_response.source_code)
|
252
260
|
write_statistics(app, release_dir, llm_response)
|
253
261
|
end
|
254
262
|
|
255
|
-
def source_code(content)
|
256
|
-
# TODO: by provider?
|
257
|
-
content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|c(pp)?)/, '')
|
258
|
-
end
|
259
|
-
|
260
263
|
def write_statistics(app, release_dir, response)
|
261
|
-
app.write_statistics(release_dir, response
|
264
|
+
app.write_statistics(release_dir, response)
|
262
265
|
end
|
263
266
|
|
264
267
|
def write_output(app, output_dir, output)
|