ruby_conversations 1.1.0 → 1.1.1

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: dd956939c0daaea90e866266a6ab8a5bba2b3ec9bb295c81a6f2e902b163d968
4
- data.tar.gz: a03a9a78205f79a6d4850cb7cd58ca0fc7413b0754e62563b541b8adc1b32917
3
+ metadata.gz: b5c99da86fb4fd6958f8bbd252656dcfcbf08e375731b1f0f45c62f14eb1e9a7
4
+ data.tar.gz: df34a7844a5a9a41b770c1ac2144542642d6082c22d17b9af7282994e89fe5c4
5
5
  SHA512:
6
- metadata.gz: abab8e151b670375b5486c7915eb921f1c24943b6f20d65f56229428d7254afe8ef18d98fe957df82de16e6219d9b4196489044fcee6e04887b201c8b2528833
7
- data.tar.gz: 3f4e262b42234bb4ed48a18d11a165edc932f75999c64f13afe8aa2b93ccd04b2e4370c3ad4b90470882e299947133831ff712a71d6418a3f36773127b21d7f2
6
+ metadata.gz: 38f26a3074bb9579e7ef547208273346b85b9255b3c41a1ceb812c758467168494d4b29d602d1f2401c79961835eefb6fa25791b33fb99228c6b73d3da4a225d
7
+ data.tar.gz: 4b952f7d55e15e22727fb155e6a52e388d9b82900f9f0cbe08fe72bffa4ba898939b651ef070837b43296adb1dec72543a6e18cf2b2ae327def4bac665cce773
@@ -3,22 +3,14 @@
3
3
  module RubyConversations
4
4
  module Concerns
5
5
  # Handles the management of LLM credentials for AI conversations.
6
- # This concern provides methods for configuring LLM credentials from either
6
+ # Provides methods for configuring LLM credentials from either
7
7
  # environment variables or an AWS credential provider.
8
8
  module LlmCredentials
9
9
  extend ActiveSupport::Concern
10
10
 
11
- class_methods do
12
- def configure_llm_credentials
13
- RubyLLM.configure do |config|
14
- credentials = provider_credentials
15
- config.bedrock_region = ENV.fetch('AWS_REGION', 'us-west-2')
16
- config.bedrock_api_key = credentials[:api_key]
17
- config.bedrock_secret_key = credentials[:secret_key]
18
- config.bedrock_session_token = credentials[:session_token]
19
- end
20
- end
21
-
11
+ # Helper methods for retrieving AWS credentials from different sources
12
+ # These methods are meant to be used as class methods in the LlmCredentials module
13
+ module CredentialHelpers
22
14
  private
23
15
 
24
16
  def env_credentials
@@ -30,16 +22,30 @@ module RubyConversations
30
22
  end
31
23
 
32
24
  def provider_credentials
33
- credential_provider = AwsCredentialProvider.instance
34
- credential_provider.refresh_if_expired!
25
+ provider = AwsCredentialProvider.instance
26
+ provider.refresh_if_expired!
35
27
  {
36
- api_key: credential_provider.access_key_id,
37
- secret_key: credential_provider.secret_access_key,
38
- session_token: credential_provider.session_token
28
+ api_key: provider.access_key_id,
29
+ secret_key: provider.secret_access_key,
30
+ session_token: provider.session_token
39
31
  }
40
32
  end
41
33
  end
42
34
 
35
+ class_methods do
36
+ include CredentialHelpers
37
+
38
+ def configure_llm_credentials
39
+ RubyLLM.configure do |config|
40
+ creds = provider_credentials
41
+ config.bedrock_region = ENV.fetch('AWS_REGION', 'us-west-2')
42
+ config.bedrock_api_key = creds[:api_key]
43
+ config.bedrock_secret_key = creds[:secret_key]
44
+ config.bedrock_session_token = creds[:session_token]
45
+ end
46
+ end
47
+ end
48
+
43
49
  def configure_llm_credentials
44
50
  self.class.configure_llm_credentials
45
51
  end
@@ -23,13 +23,9 @@ module RubyConversations
23
23
  # Initialization
24
24
  def initialize(attributes = nil)
25
25
  attributes ||= {}
26
- # Ensure messages is always an array before super assigns other attributes
27
26
  @messages = []
28
- # Extract nested attributes before super tries to assign them
29
- messages_attrs = attributes.delete(:messages) || attributes.delete('messages') ||
30
- attributes.delete(:messages_attributes) || attributes.delete('messages_attributes') || []
31
- # Extract persist flag, default to false
32
- @persist = attributes.delete(:persist) || attributes.delete('persist') || false
27
+ messages_attrs = extract_message_attributes(attributes)
28
+ @persist = extract_persist_flag(attributes)
33
29
 
34
30
  super # Initialize with remaining attributes using ActiveModel::Model
35
31
  initialize_messages(messages_attrs)
@@ -37,6 +33,20 @@ module RubyConversations
37
33
  build_chat
38
34
  end
39
35
 
36
+ def extract_message_attributes(attributes)
37
+ attributes.delete(:messages) ||
38
+ attributes.delete('messages') ||
39
+ attributes.delete(:messages_attributes) ||
40
+ attributes.delete('messages_attributes') ||
41
+ []
42
+ end
43
+
44
+ def extract_persist_flag(attributes)
45
+ attributes.delete(:persist) ||
46
+ attributes.delete('persist') ||
47
+ false
48
+ end
49
+
40
50
  def build_chat
41
51
  @chat = if @persist && RubyConversations.configuration.persistence_model
42
52
  resolve_persistence_model.create!(model_id: llm, provider: provider)
@@ -76,8 +86,8 @@ module RubyConversations
76
86
  raise ConfigurationError, "Invalid persistence_model configured: Must be a String, got #{model_config.class}"
77
87
  end
78
88
 
79
- model_config.safe_constantize || raise(ConfigurationError,
80
- "Invalid persistence_model configured: '#{model_config}' could not be resolved.")
89
+ model_config.safe_constantize ||
90
+ raise(ConfigurationError, "Invalid persistence_model configured: '#{model_config}' could not be resolved.")
81
91
  rescue NameError => e
82
92
  # Catch potential NameError from constantize if the class name is invalid
83
93
  raise ConfigurationError, "Invalid persistence_model configured: #{e.message}"
@@ -3,7 +3,7 @@
3
3
  module RubyConversations
4
4
  MAJOR = 1
5
5
  MINOR = 1
6
- PATCH = 0
6
+ PATCH = 1
7
7
 
8
8
  VERSION = "#{RubyConversations::MAJOR}.#{RubyConversations::MINOR}.#{RubyConversations::PATCH}".freeze
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_conversations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Shippy