llmed 0.3.14 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 485aa021e818c5cc74716df4f669e06f6a711be804ad1666a6084f0036441cd3
4
- data.tar.gz: 33483d05a483a45bda88e549b3811dc0576527a11f681b9ff7b5c0f01242d945
3
+ metadata.gz: 3d5362d8a48de51f33d6cc43bdd166387d7d36f0242cca147c126da4678721fc
4
+ data.tar.gz: 25d0960a155f4c8abb600eae9853b28215808635a4d0da812f381db31bf74a1a
5
5
  SHA512:
6
- metadata.gz: 7a61cdcc702a428e6cdf6d3d1b9576236dff9b7239484aaaaf5806b8b29a3e6303244868748607ce1ba5f0807e63348c220d95fbb63fe7880ecc73ee23d3b0d0
7
- data.tar.gz: 5e3c6ed4de279a33e73d268b144d0febb38fc1679f4954ec0d75df356a0e663a7f82b3a84a9ec93ca6500d94936a7f5209b2dc515a1952a6faec8e274745c721
6
+ metadata.gz: d9fbca340377b6b8370426839faa236ce23b803870651d00da2d2c719ded31cbd4d5a9929fd8855fd486bb79f60780f13acc3f82b228e29d4df5ebdd8fcf9d5c
7
+ data.tar.gz: 697c10a3fd025fc31cb3e8ef0f33765eb686ebf6fb174f33bbc79a51eed1020615489a33cd0557b97b058ab10badc446c3e74665deb6ccc448ffabbd4dddaa96
data/lib/llm.rb CHANGED
@@ -21,8 +21,10 @@ class LLMed
21
21
  class OpenAI
22
22
 
23
23
  DEFAULT_URI_BASE = "https://api.openai.com/".freeze
24
+ MAX_TOKENS = 8192
24
25
 
25
26
  def initialize(**args)
27
+ @logger = args.delete(:logger)
26
28
  @llm = Langchain::LLM::OpenAI.new(**llm_arguments(args))
27
29
  end
28
30
 
@@ -37,7 +39,9 @@ class LLMed
37
39
  end
38
40
 
39
41
  start = Time.now
40
- llm_response = @llm.chat(messages: messages)
42
+ llm_response = @llm.chat(messages: messages, max_tokens: MAX_TOKENS)
43
+ warn_token_limits(llm_response)
44
+
41
45
  stop = Time.now
42
46
  Response.new({ provider: provider,
43
47
  model: @llm.chat_parameters[:model],
@@ -47,6 +51,12 @@ class LLMed
47
51
  end
48
52
 
49
53
  private
54
+ def warn_token_limits(llm_response)
55
+ if llm_response.completion_tokens >= MAX_TOKENS
56
+ @logger.warn("POSSIBLE INCONSISTENCY COMPLETED TOKENS REACHED MAX TOKENS #{MAX_TOKENS}")
57
+ end
58
+ end
59
+
50
60
  def llm_arguments(args)
51
61
  args
52
62
  end
@@ -64,6 +74,7 @@ class LLMed
64
74
  private
65
75
 
66
76
  def llm_arguments(args)
77
+ @logger = args.delete(:logger)
67
78
  args.merge({ llm_options: { uri_base: 'https://api.anthropic.com/v1/' } })
68
79
  end
69
80
 
@@ -3,7 +3,8 @@
3
3
 
4
4
  class LLMed
5
5
  class Configuration
6
- def initialize
6
+ def initialize(logger:)
7
+ @logger = logger
7
8
  # Manual tested, pass 5 times execution
8
9
  @prompt = LLMed::LLM::Template.build(template: "
9
10
  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.
@@ -70,16 +71,19 @@ Wrap with comment every code that belongs to the indicated context, example in {
70
71
  case @provider
71
72
  when :openai
72
73
  LLMed::LLM::OpenAI.new(
74
+ logger: @logger,
73
75
  api_key: @provider_api_key,
74
- default_options: { temperature: 0.7, chat_model: @provider_model }
76
+ default_options: { max_tokens: nil, temperature: 0.7, chat_model: @provider_model }
75
77
  )
76
78
  when :anthropic
77
79
  LLMed::LLM::Anthropic.new(
80
+ logger: @logger,
78
81
  api_key: @provider_api_key,
79
- default_options: { temperature: 0.7, chat_model: @provider_model }
82
+ default_options: { max_tokens: nil, temperature: 0.7, chat_model: @provider_model }
80
83
  )
81
84
  when :like_openai
82
85
  LLMed::LLM::LikeOpenAI.new(
86
+ logger: @logger,
83
87
  api_key: @provider_api_key,
84
88
  default_options: { temperature: 0.7, chat_model: @provider_model },
85
89
  llm_options: @provider_options
data/lib/llmed/context.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # Copyright 2025 Jovany Leandro G.C <bit4bit@riseup.net>
2
2
  # frozen_string_literal: true
3
+ require 'erb'
3
4
 
4
5
  class LLMed
5
6
  class Context
@@ -47,6 +48,12 @@ class LLMed
47
48
  File.read(path)
48
49
  end
49
50
 
51
+ # Example:
52
+ # context("application") { from_erb("application.cllmed.erb") }
53
+ def from_erb(path)
54
+ ERB.new(File.read(path)).result(binding)
55
+ end
56
+
50
57
  # Example:
51
58
  # context("source") { from_source_code("sourcepathtoinclude") }
52
59
  def from_source_code(path)
@@ -0,0 +1,50 @@
1
+ require 'toml-rb'
2
+
3
+ class LLMed
4
+ class LiterateProgramming
5
+ ContentString = Struct.new(:content, keyword_init: true) do
6
+ def to_s
7
+ content
8
+ end
9
+ end
10
+ ContentFencedBlock = Struct.new(:format, :arguments, :content, keyword_init: true)
11
+ Context = Struct.new(:name, :content, :content_desc, keyword_init: true)
12
+ Application = Struct.new(:configuration, :contexts, keyword_init: true)
13
+
14
+ class Markdown
15
+
16
+ def parse(content)
17
+ content.scan(/^---(.+?)---\n(.+)/m) => [[configuration_data, application_data]]
18
+
19
+ app = Application.new(configuration: TomlRB.parse(configuration_data), contexts: [])
20
+
21
+ application_data.split(/^# /)
22
+ .reject{|c| c.empty?}
23
+ .each do |context_data|
24
+ case context_data.split("\n", 2)
25
+ in ["", ""]
26
+ # omit
27
+ in [name, content]
28
+ context_desc = []
29
+ content.split(/(```.*```)/mi).each do |line|
30
+ if line.start_with?("```")
31
+ line.scan(/```(.+?)\n(.+)```/mi) => [[fenced_data, fenced_content]]
32
+ fenced_params = fenced_data.split(",")
33
+ format = fenced_params.shift
34
+ arguments = fenced_params.map{|item| item.split("=", 2)}.to_h
35
+
36
+ context_desc << ContentFencedBlock.new(format: format, arguments: arguments, content: fenced_content)
37
+ else
38
+ context_desc << ContentString.new(content: line)
39
+ end
40
+ end
41
+
42
+ app.contexts << Context.new(name: name, content: content, content_desc: context_desc)
43
+ end
44
+ end
45
+
46
+ app
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ class LLMed
2
+ class LiterateProgramming::Markdown
3
+ end
4
+ end
data/lib/llmed.rb CHANGED
@@ -17,7 +17,7 @@ class LLMed
17
17
  @logger = logger
18
18
  @applications = []
19
19
  @deploys = []
20
- @configuration = Configuration.new
20
+ @configuration = Configuration.new(logger: logger)
21
21
  @release_dir = release_dir || output_dir
22
22
  @output_dir = output_dir
23
23
  end
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.3.14
4
+ version: 0.3.16
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-18 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: langchainrb
@@ -104,6 +104,8 @@ files:
104
104
  - lib/llmed/context.rb~
105
105
  - lib/llmed/deployment.rb
106
106
  - lib/llmed/deployment.rb~
107
+ - lib/llmed/literate_programming.rb
108
+ - lib/llmed/literate_programming.rb~
107
109
  - lib/llmed/release.rb
108
110
  - lib/llmed/release.rb~
109
111
  homepage: https://github.com/bit4bit/llmed