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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fba3b2761904f5e3c504125737f783a19e3ad253a02997f200ca360df354c254
4
- data.tar.gz: 2a1cfb269c2caf2c8aae9c68d767bedc43a42f021758371f878247c83562f457
3
+ metadata.gz: 931aa3bf94ee48a2021c8ec6f5de047e593f2f94bc5ba01e20b48bd1b2e96d3c
4
+ data.tar.gz: fcbab1174c9dbefb317fdae26a0c0a763f4a3b8026b19f8fe8f08a54d222f8fb
5
5
  SHA512:
6
- metadata.gz: f83c0afbb650c71b9961d2ca5a1185b45a806a1c8689484bb4524deb097b0acc5df3dbc105b48df9181b4b2303caef8e1346775a2558ff05d13008791c71b22a
7
- data.tar.gz: 859f77a997f4b589b946a47ebcd987d55127ef35540578b525c92e22e1d59c860386dfde672dad02a1a7d145db54ea2718d030a4fe6b7f17c59b5b326ecd2372
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Locallingo
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locallingo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson