llmed 0.2.7 → 0.2.10

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: a7d55c3e9d616ed161996ef1c03fd1aa760359bb7bdbb77086519f25ab1f88fd
4
- data.tar.gz: 5bdffc77b3c78566d42c4351609148aded536fe177229b8aec0369748c75e442
3
+ metadata.gz: 8f0373ddc4cb49e5ddeffd7a31cc5e100f6130447f4789d58c2440e94f48605e
4
+ data.tar.gz: 2fe8f237cd784cd24a86408090b495e7eae0c1308e94188a79b33a9be01e3403
5
5
  SHA512:
6
- metadata.gz: 765e21e7901b35bb8c670873d8d7e1f27988f732a425373c8d3a91467a6703d4ac684daf96b9880837dadf916d3463d4d1265249cc8a3989f445f144f1b27202
7
- data.tar.gz: 4f261c925f6c3302570e79f38e89a243c1560030497553efcd71c5028f05f10d5c85f6bac1153c2eabe683482e10dfdb4e108f498022f71210d9abe4273e1278
6
+ metadata.gz: 4d5204f34243a5e25ee09e8f2b54bbb0cd3b7ff683e3d720d4f8a8c16b921d99de694337156bd9ff0c3d2790802eb55efda2bd3adb5230e9b2c88cabf0dae389
7
+ data.tar.gz: 5398a611b114dd185b5b16b18b7022231e9cb36a41c624832b18c8cc8d7c5aaea012137cff2678f8e043004fbba0b9265b7c5a933d29dcaaf73b483a0abfd92e
data/lib/llm.rb CHANGED
@@ -20,7 +20,7 @@ class LLMed
20
20
 
21
21
  class OpenAI
22
22
  def initialize(**args)
23
- @llm = Langchain::LLM::OpenAI.new(**args)
23
+ @llm = Langchain::LLM::OpenAI.new(**llm_arguments(args))
24
24
  end
25
25
 
26
26
  def chat(messages: [])
@@ -36,7 +36,7 @@ class LLMed
36
36
  start = Time.now
37
37
  llm_response = @llm.chat(messages: messages)
38
38
  stop = Time.now
39
- Response.new({ provider: :openai,
39
+ Response.new({ provider: provider,
40
40
  model: @llm.chat_parameters[:model],
41
41
  duration_seconds: stop.to_i - start.to_i,
42
42
  source_code: source_code(llm_response.chat_completion),
@@ -45,8 +45,28 @@ class LLMed
45
45
 
46
46
  private
47
47
 
48
+ def llm_arguments(args)
49
+ args
50
+ end
51
+
52
+ def provider
53
+ :openai
54
+ end
55
+
48
56
  def source_code(content)
49
- content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|html|c(pp)?)/, '')
57
+ content.gsub('```', '').sub(/^(node(js)?|javascript|ruby|python(\d*)|elixir|perl|bash|html|c(pp)?)([ \n])/, '')
58
+ end
59
+ end
60
+
61
+ class Anthropic < OpenAI
62
+ private
63
+
64
+ def llm_arguments(args)
65
+ args.merge({ llm_options: { uri_base: 'https://api.anthropic.com/v1/' } })
66
+ end
67
+
68
+ def provider
69
+ :anthropic
50
70
  end
51
71
  end
52
72
 
@@ -83,10 +83,18 @@ class LLMed
83
83
  end
84
84
  end
85
85
 
86
- @logger.info("APPLICATION #{@name} PATCHING CONTEXT #{name} \n\tFROM #{digest}\n\tTO DIGEST #{new_digest}")
87
86
  release_source_code_content = release_source_code_content.sub(%r{(.*?)(<llmed-code context='#{name}' digest='.*?'>)(.+?)(</llmed-code>)(.*?)}m) do
88
87
  "#{::Regexp.last_match(1)}<llmed-code context='#{name}' digest='#{new_digest}'>#{new_code}#{::Regexp.last_match(4)}#{::Regexp.last_match(5)}"
89
88
  end
89
+
90
+ if release_contexts[name].nil?
91
+ @logger.info("APPLICATION #{@name} ADDING NEW CONTEXT #{name}")
92
+ release_source_code_content += "<llmed-code context='#{name}' digest='#{new_digest}'>
93
+ #{new_code}
94
+ #{code_comment}</llmed-code>"
95
+ else
96
+ @logger.info("APPLICATION #{@name} PATCHING CONTEXT #{name} \n\tFROM #{digest}\n\tTO DIGEST #{new_digest}")
97
+ end
90
98
  end
91
99
 
92
100
  output_content = release_source_code_content
@@ -110,7 +118,11 @@ class LLMed
110
118
  !digests_of_context_to_update.tap do |digests|
111
119
  digests.each do |digest|
112
120
  context_by_digest = release_contexts.invert
113
- @logger.info("APPLICATION #{@name} REBUILDING CONTEXT #{context_by_digest[digest]}")
121
+ if context_by_digest[digest].nil?
122
+ @logger.info("APPLICATION #{@name} ADDING CONTEXT #{user_contexts.invert[digest]}")
123
+ else
124
+ @logger.info("APPLICATION #{@name} REBUILDING CONTEXT #{context_by_digest[digest]}")
125
+ end
114
126
  end
115
127
  end.empty?
116
128
  end
@@ -141,6 +153,10 @@ class LLMed
141
153
 
142
154
  private
143
155
 
156
+ def code_comment
157
+ { ruby: '#' }.fetch(@language.to_sym)
158
+ end
159
+
144
160
  def digests_of_context_to_update
145
161
  update_context_digest = []
146
162
 
@@ -152,8 +168,15 @@ class LLMed
152
168
  update_rest = false
153
169
  @contexts.each do |ctx|
154
170
  release_context_digest = release_contexts[ctx.name]
155
- # maybe the context is not connected to the source code
156
- next if release_context_digest.nil?
171
+
172
+ # added new context
173
+ if release_context_digest.nil? and !user_contexts[ctx.name].nil?
174
+ update_context_digest << user_contexts[ctx.name]
175
+ next
176
+ elsif release_context_digest.nil?
177
+ # maybe the context is not connected to the source code
178
+ next
179
+ end
157
180
 
158
181
  if update_rest
159
182
  update_context_digest << release_context_digest
@@ -177,6 +200,12 @@ class LLMed
177
200
  Pathname.new(@release_dir) + "#{@output_file}.release"
178
201
  end
179
202
 
203
+ def user_contexts
204
+ @contexts.map do |ctx|
205
+ [ctx.name, ctx.digest]
206
+ end.to_h
207
+ end
208
+
180
209
  def release_contexts
181
210
  return {} unless @release
182
211
 
@@ -14,7 +14,7 @@ Always include the properly escaped comment: LLMED-COMPILED.
14
14
  You must only modify the following source code:
15
15
  {source_code}
16
16
 
17
- Only generate source code of the context who digest belongs to {update_context_digests}.
17
+ Only generate source code of the context who digest belongs to {update_context_digests} or a is a new context.
18
18
 
19
19
  Wrap with comment every code that belongs to the indicated context, example in ruby:
20
20
  #<llmed-code context='context name' digest='....'>
@@ -66,6 +66,11 @@ Wrap with comment every code that belongs to the indicated context, example in r
66
66
  api_key: @provider_api_key,
67
67
  default_options: { temperature: 0.7, chat_model: @provider_model }
68
68
  )
69
+ when :anthropic
70
+ LLMed::LLM::Anthropic.new(
71
+ api_key: @provider_api_key,
72
+ default_options: { temperature: 0.7, chat_model: @provider_model }
73
+ )
69
74
  when :test
70
75
  LLMed::LLM::Test.new
71
76
  when nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llmed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jovany Leandro G.C
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-07 00:00:00.000000000 Z
11
+ date: 2025-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: langchainrb