llmed 0.3.15 → 0.3.17
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 +12 -1
- data/lib/llmed/application.rb +1 -0
- data/lib/llmed/configuration.rb +10 -4
- data/lib/llmed/release.rb +20 -3
- data/lib/llmed.rb +1 -1
- 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: 52b2451c2b753bce4e00ee940d19d61f299b95dbf78503f6338b12732ec90e34
|
4
|
+
data.tar.gz: 59b763a108c1823fe8a81517386a5cc11d7a41d3171aab09d0d977baf4154f6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72e2cb9a8e97fcb9025a4c830e37b637a92cc0a0a997715fc1e60456d62b2fec337c0c57f85d03ff14488aa038b45737f2e8204714c6c425925bd78cfef64efe
|
7
|
+
data.tar.gz: 90b0df91f71029a50fe254b851799e201bb6b26170d2c9ebb5beb71085d1c272357d2568527ea2cc3b16179e3dee5b92b27d5de1b0cae4bc61b077d3731eebcd
|
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
|
|
data/lib/llmed/application.rb
CHANGED
@@ -102,6 +102,7 @@ class LLMed
|
|
102
102
|
output_release = Release.load(File.read(release_source_code), @code_comment)
|
103
103
|
input_release = Release.load(output, @code_comment)
|
104
104
|
output_content = output_release.merge!(input_release, user_contexts).content
|
105
|
+
|
105
106
|
output_release.changes.each do |change|
|
106
107
|
action, ctx = change
|
107
108
|
case action
|
data/lib/llmed/configuration.rb
CHANGED
@@ -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.
|
@@ -14,9 +15,11 @@ There is always a one-to-one correspondence between context and source code.
|
|
14
15
|
Always include the properly escaped comment: LLMED-COMPILED.
|
15
16
|
|
16
17
|
You must only modify the following source code:
|
18
|
+
```
|
17
19
|
{source_code}
|
20
|
+
```
|
18
21
|
|
19
|
-
Only generate source code of the context who digest belongs to {update_context_digests}
|
22
|
+
Only generate source code of the context who digest belongs to {update_context_digests}.
|
20
23
|
|
21
24
|
Wrap with comment every code that belongs to the indicated context, example in {language}:
|
22
25
|
{code_comment_begin}<llmed-code context='context name' digest='....' after='digest next context'>{code_comment_end}
|
@@ -70,16 +73,19 @@ Wrap with comment every code that belongs to the indicated context, example in {
|
|
70
73
|
case @provider
|
71
74
|
when :openai
|
72
75
|
LLMed::LLM::OpenAI.new(
|
76
|
+
logger: @logger,
|
73
77
|
api_key: @provider_api_key,
|
74
|
-
default_options: { temperature: 0.7, chat_model: @provider_model }
|
78
|
+
default_options: { max_tokens: nil, temperature: 0.7, chat_model: @provider_model }
|
75
79
|
)
|
76
80
|
when :anthropic
|
77
81
|
LLMed::LLM::Anthropic.new(
|
82
|
+
logger: @logger,
|
78
83
|
api_key: @provider_api_key,
|
79
|
-
default_options: { temperature: 0.7, chat_model: @provider_model }
|
84
|
+
default_options: { max_tokens: nil, temperature: 0.7, chat_model: @provider_model }
|
80
85
|
)
|
81
86
|
when :like_openai
|
82
87
|
LLMed::LLM::LikeOpenAI.new(
|
88
|
+
logger: @logger,
|
83
89
|
api_key: @provider_api_key,
|
84
90
|
default_options: { temperature: 0.7, chat_model: @provider_model },
|
85
91
|
llm_options: @provider_options
|
data/lib/llmed/release.rb
CHANGED
@@ -106,13 +106,30 @@ class LLMed
|
|
106
106
|
# insertions missed user contexts
|
107
107
|
user_contexts.each do |name, digest|
|
108
108
|
next if contexts.any? { |ctx| ctx.name == name }
|
109
|
-
|
110
|
-
new_ctx = ContextCode.new(name, digest,
|
109
|
+
code = release.context_by(name).code
|
110
|
+
new_ctx = ContextCode.new(name, digest, code, '')
|
111
111
|
contexts.prepend(new_ctx)
|
112
112
|
@changes << [:added, new_ctx]
|
113
113
|
end
|
114
114
|
|
115
|
-
|
115
|
+
contexts_sorted = []
|
116
|
+
# prioritize user order
|
117
|
+
user_contexts.each do |name, _digest|
|
118
|
+
contexts.each do |ctx|
|
119
|
+
if ctx.name == name
|
120
|
+
contexts_sorted << ctx
|
121
|
+
break
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
@contexts = contexts_sorted.sort {|a,b|
|
127
|
+
if a.digest == b.after
|
128
|
+
1
|
129
|
+
else
|
130
|
+
0
|
131
|
+
end
|
132
|
+
}
|
116
133
|
self
|
117
134
|
end
|
118
135
|
|
data/lib/llmed.rb
CHANGED