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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5c99da86fb4fd6958f8bbd252656dcfcbf08e375731b1f0f45c62f14eb1e9a7
|
4
|
+
data.tar.gz: df34a7844a5a9a41b770c1ac2144542642d6082c22d17b9af7282994e89fe5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
34
|
-
|
25
|
+
provider = AwsCredentialProvider.instance
|
26
|
+
provider.refresh_if_expired!
|
35
27
|
{
|
36
|
-
api_key:
|
37
|
-
secret_key:
|
38
|
-
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
|
-
|
29
|
-
|
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 ||
|
80
|
-
|
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}"
|