llmed 0.3.15 → 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 +4 -4
- data/lib/llm.rb +12 -1
- data/lib/llmed/configuration.rb +7 -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: 3d5362d8a48de51f33d6cc43bdd166387d7d36f0242cca147c126da4678721fc
|
4
|
+
data.tar.gz: 25d0960a155f4c8abb600eae9853b28215808635a4d0da812f381db31bf74a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
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.
|
@@ -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.rb
CHANGED