llmed 0.3.6 → 0.3.9

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: 9da82913d8d58fc5b9fd098e718abdc62ad4f41948a8b43a592f5877b9f5ec97
4
- data.tar.gz: b7873366f2a826273aa6bdd02e4a21f9dd55d1848a864d8c1f1264890ef5387b
3
+ metadata.gz: d9981f3963222aa2c60981af1a5fb5431249b9a2121bb5b407f70417c11440fe
4
+ data.tar.gz: 6c0b4b0427586af2ce24153a389d72b212a55ac07fc83387a00db56e800e8396
5
5
  SHA512:
6
- metadata.gz: 8a0ab890bbe999af552082dcc3639d24bb22200d38f3a1de7808daafdd01ac9d0038d7763633e8bbe585d3fe1ae8fc1b2604a32b164226436e149ea54b5e9ffb
7
- data.tar.gz: 28c1f32c9731526a3b6eef0dd613775f5d21328e3785c49329e903eac63a7ff0d28d3e6ab1f940e8569eb0dcc5cc73726c65315177c624e6bc9c48ecfd20bfdb
6
+ metadata.gz: e0b6e2d76d87d4232e04850a1e3b65f844eb7704be6f82f14395f3d924f5cc0aa4061b9b152cdd901e29a45bd4e355fcb127f38fb4e44dfed29fa48606a12677
7
+ data.tar.gz: b655cd912abdbba5d5fe653d30cac9711d9ea91c4b5db9691e1ad7251006a7462c3eb0d24ee4418e76fbd8daf913c2c23bcd3c44ae6c5ceb8aa4b147566514d4
data/lib/llm.rb CHANGED
@@ -54,7 +54,7 @@ class LLMed
54
54
  end
55
55
 
56
56
  def source_code(content)
57
- content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|html|c(pp)?)([ \n])/, '')
57
+ content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|bash|html|go|c(pp)?)([ \n])/, '')
58
58
  end
59
59
  end
60
60
 
@@ -5,12 +5,34 @@ class LLMed
5
5
  class Application
6
6
  attr_reader :contexts, :name, :language
7
7
 
8
- def initialize(name:, language:, output_file:, block:, logger:, release:, release_dir:, output_dir:)
9
- raise 'required language' if language.nil?
8
+ class CodeComment
9
+ def initialize(language)
10
+ raise "language #{language} not supported" if code_comment(language.to_sym).nil?
11
+
12
+ @language = language.to_sym
13
+ end
14
+
15
+ def begin
16
+ code_comment(@language).first
17
+ end
18
+
19
+ def end
20
+ code_comment(@language).last
21
+ end
22
+
23
+ private
10
24
 
25
+ def code_comment(language)
26
+ { ruby: ['#', ''], node: ['//', ''], elixir: ['#', ''], bash: ['#', ''], python: ['#', ''], go: ['//', ''], javascript: ['//', ''], c: ['//', ''],
27
+ cpp: ['//', ''], html: ['<!--', '-->'] }.fetch(language)
28
+ end
29
+ end
30
+
31
+ def initialize(name:, language:, output_file:, block:, logger:, release:, release_dir:, output_dir:)
11
32
  @name = name
12
33
  @output_file = output_file
13
- @language = language
34
+ @language = language.to_sym
35
+ @code_comment = CodeComment.new(language)
14
36
  @block = block
15
37
  @contexts = []
16
38
  @logger = logger
@@ -76,10 +98,10 @@ class LLMed
76
98
  output_content = output
77
99
 
78
100
  if @release && File.exist?(release_source_code) && !release_contexts.empty?
79
- output_release = Release.load(File.read(release_source_code), code_comment)
80
- input_release = Release.load(output, code_comment)
101
+ output_release = Release.load(File.read(release_source_code), @code_comment)
102
+ input_release = Release.load(output, @code_comment)
81
103
  output_content = output_release.merge!(input_release, user_contexts).content
82
- output_release.changes do |change|
104
+ output_release.changes.each do |change|
83
105
  action, ctx = change
84
106
  case action
85
107
  when :added
@@ -110,7 +132,6 @@ class LLMed
110
132
  context_by_digest = release_contexts.invert
111
133
 
112
134
  if context_by_digest[digest].nil?
113
-
114
135
  @logger.info("APPLICATION #{@name} ADDING CONTEXT #{user_contexts.invert[digest]}")
115
136
  else
116
137
  @logger.info("APPLICATION #{@name} REBUILDING CONTEXT #{context_by_digest[digest]}")
@@ -145,10 +166,6 @@ class LLMed
145
166
 
146
167
  private
147
168
 
148
- def code_comment
149
- { ruby: '#', node: '//' }.fetch(@language.to_sym)
150
- end
151
-
152
169
  def digests_of_context_to_update
153
170
  update_context_digest = []
154
171
 
@@ -208,9 +225,9 @@ class LLMed
208
225
 
209
226
  def release_instance
210
227
  if File.exist?(release_source_code)
211
- Release.load(File.read(release_source_code), code_comment)
228
+ Release.load(File.read(release_source_code), @code_comment)
212
229
  else
213
- Release.empty
230
+ Release.empty(@code_comment)
214
231
  end
215
232
  end
216
233
  end
@@ -8,10 +8,9 @@ class LLMed
8
8
  @prompt = LLMed::LLM::Template.build(template: "
9
9
  You are a software developer with knowledge only of the programming language {language}, following the SOLID principles strictly, you always use only imperative and functional programming, design highly isolated components.
10
10
  The contexts are declarations of how the source code will be (not a file) ensure to follow this always.
11
- The contexts are connected as a linked list.
12
- Your response must contain only the generated source code, with no additional text.
11
+ The contexts are connected as a flat linked list.
12
+ Your response must contain only the generated source code, with no additional text or comments, and ou must ensure that runs correctly on the first attempt.
13
13
  All the contexts represent one source code.
14
- You must also the ensure that the source code runs correctly on the first attempt.
15
14
  There is always a one-to-one correspondence between context and source code.
16
15
  Always include the properly escaped comment: LLMED-COMPILED.
17
16
 
data/lib/llmed/release.rb CHANGED
@@ -5,7 +5,7 @@ class LLMed
5
5
  class Release
6
6
  ContextCode = Struct.new(:name, :digest, :code, :after) do
7
7
  def to_llmed_code(code_comment)
8
- "#{code_comment}<llmed-code context='#{name}' digest='#{digest}' after='#{after}'>#{code}#{code_comment}</llmed-code>"
8
+ "#{code_comment.begin}<llmed-code context='#{name}' digest='#{digest}' after='#{after}'>#{code_comment.end}#{code}#{code_comment.begin}</llmed-code>#{code_comment.end}"
9
9
  end
10
10
 
11
11
  def digest?
@@ -20,8 +20,8 @@ class LLMed
20
20
  new(origin, code_comment)
21
21
  end
22
22
 
23
- def self.empty
24
- new('', '')
23
+ def self.empty(code_comment)
24
+ new('', code_comment)
25
25
  end
26
26
 
27
27
  def content
@@ -75,7 +75,7 @@ class LLMed
75
75
  end
76
76
  end
77
77
 
78
- # insertions
78
+ # insertions from release
79
79
  insertions = []
80
80
  release.contexts.each do |new_ctx|
81
81
  next if has_context?(new_ctx.name)
@@ -103,6 +103,15 @@ class LLMed
103
103
  ctx.digest = user_context_digest unless user_context_digest.nil?
104
104
  end
105
105
 
106
+ # insertions missed user contexts
107
+ user_contexts.each do |name, digest|
108
+ next if contexts.any? { |ctx| ctx.name == name }
109
+
110
+ new_ctx = ContextCode.new(name, digest, "\n", '')
111
+ contexts.prepend(new_ctx)
112
+ @changes << [:added, new_ctx]
113
+ end
114
+
106
115
  @contexts = contexts
107
116
  self
108
117
  end
@@ -116,7 +125,7 @@ class LLMed
116
125
  @code_comment = code_comment
117
126
  @contexts = []
118
127
 
119
- @origin.scan(%r{<llmed-code context='(.+?)' digest='(.+?)'\s*(after='.*?')?>(.+?)#{@code_comment}+\s*</llmed-code>}im).each do |match|
128
+ @origin.scan(%r{<llmed-code context='(.+?)' digest='(.+?)'\s*(after='.*?')?>#{@code_comment.end}(.+?)#{@code_comment.begin}+.*?/llmed-code}im).each do |match|
120
129
  name, digest, after_block, code = match
121
130
  after = if after_block.nil?
122
131
  ''
data/lib/llmed.rb CHANGED
@@ -70,7 +70,6 @@ class LLMed
70
70
 
71
71
  llm_response = llm.chat(messages: messages)
72
72
  @logger.info("APPLICATION #{app.name} TOTAL TOKENS #{llm_response.total_tokens}")
73
-
74
73
  app.patch_or_create(llm_response.source_code)
75
74
  app.write_statistics(llm_response)
76
75
  app.notify("COMPILE DONE #{llm_response.duration_seconds}")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llmed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jovany Leandro G.C