locallingo 0.2.1 → 0.2.2
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/locallingo/providers/ruby_llm.rb +21 -0
- data/lib/locallingo/version.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: 931aa3bf94ee48a2021c8ec6f5de047e593f2f94bc5ba01e20b48bd1b2e96d3c
|
|
4
|
+
data.tar.gz: fcbab1174c9dbefb317fdae26a0c0a763f4a3b8026b19f8fe8f08a54d222f8fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bc87c498dcc47fbda209f58005ce265f09ef5432107bbced4f9185e32ae51873b6aae014f7f11f650cd4905328169cb32e8f477c9ab1d310f2b4692da350ce8
|
|
7
|
+
data.tar.gz: 65f2c9cbf024baa4cb89202da61fff2d4feb0de544c2ea85371525714e83a322ac93f065ae08239e67f562d0158b0ddf01acd199e9d9060614f3c02afa8f37a5
|
|
@@ -54,6 +54,7 @@ module Locallingo
|
|
|
54
54
|
# the model and return the parsed JSON object as a Hash.
|
|
55
55
|
def chat(model:, instructions:, payload:)
|
|
56
56
|
require "ruby_llm"
|
|
57
|
+
configure_credentials!
|
|
57
58
|
|
|
58
59
|
conversation = ::RubyLLM.chat(
|
|
59
60
|
model:,
|
|
@@ -64,6 +65,26 @@ module Locallingo
|
|
|
64
65
|
response = conversation.ask(JSON.pretty_generate(payload))
|
|
65
66
|
JsonExtraction.extract_object(response.content)
|
|
66
67
|
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
# RubyLLM does not read provider API keys from ENV on its own, so a
|
|
72
|
+
# standalone CLI run (no Rails initializer to call RubyLLM.configure)
|
|
73
|
+
# would raise "Missing configuration for <provider>". Fill the
|
|
74
|
+
# provider's key from ENV — unless the host app already configured
|
|
75
|
+
# one, which always wins.
|
|
76
|
+
def configure_credentials!
|
|
77
|
+
env = CREDENTIAL_ENV[provider]
|
|
78
|
+
return unless env
|
|
79
|
+
|
|
80
|
+
setting = "#{provider}_api_key"
|
|
81
|
+
config = ::RubyLLM.config
|
|
82
|
+
return unless config.respond_to?(setting) && config.respond_to?("#{setting}=")
|
|
83
|
+
return unless config.public_send(setting).to_s.strip.empty?
|
|
84
|
+
|
|
85
|
+
key = ENV.fetch(env, "")
|
|
86
|
+
config.public_send("#{setting}=", key) unless key.strip.empty?
|
|
87
|
+
end
|
|
67
88
|
end
|
|
68
89
|
end
|
|
69
90
|
end
|
data/lib/locallingo/version.rb
CHANGED