ruby_conversations 1.0.15 → 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,39 +3,51 @@
|
|
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
|
-
|
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
|
14
|
+
private
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def env_credentials
|
17
|
+
{
|
18
|
+
api_key: ENV.fetch('AWS_ACCESS_KEY_ID', nil),
|
19
|
+
secret_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
|
20
|
+
session_token: ENV.fetch('AWS_SESSION_TOKEN', nil)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def provider_credentials
|
25
|
+
provider = AwsCredentialProvider.instance
|
26
|
+
provider.refresh_if_expired!
|
27
|
+
{
|
28
|
+
api_key: provider.access_key_id,
|
29
|
+
secret_key: provider.secret_access_key,
|
30
|
+
session_token: provider.session_token
|
31
|
+
}
|
20
32
|
end
|
21
33
|
end
|
22
34
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
29
47
|
end
|
30
48
|
|
31
|
-
def
|
32
|
-
|
33
|
-
credential_provider.refresh_if_expired!
|
34
|
-
{
|
35
|
-
api_key: credential_provider.access_key_id,
|
36
|
-
secret_key: credential_provider.secret_access_key,
|
37
|
-
session_token: credential_provider.session_token
|
38
|
-
}
|
49
|
+
def configure_llm_credentials
|
50
|
+
self.class.configure_llm_credentials
|
39
51
|
end
|
40
52
|
end
|
41
53
|
end
|
@@ -14,7 +14,7 @@ module RubyConversations
|
|
14
14
|
|
15
15
|
# Define attributes needed for API interaction & local state
|
16
16
|
attr_accessor :chat, :id, :conversationable_type, :conversationable_id, :conversationable,
|
17
|
-
:messages, :tool, :tools, :created_at, :updated_at
|
17
|
+
:messages, :tool, :tools, :created_at, :updated_at, :persist
|
18
18
|
|
19
19
|
# Validations
|
20
20
|
validates :messages, presence: { message: 'At least one message is required' }, on: :update
|
@@ -23,11 +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') || []
|
27
|
+
messages_attrs = extract_message_attributes(attributes)
|
28
|
+
@persist = extract_persist_flag(attributes)
|
31
29
|
|
32
30
|
super # Initialize with remaining attributes using ActiveModel::Model
|
33
31
|
initialize_messages(messages_attrs)
|
@@ -35,8 +33,26 @@ module RubyConversations
|
|
35
33
|
build_chat
|
36
34
|
end
|
37
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
|
+
|
38
50
|
def build_chat
|
39
|
-
@chat =
|
51
|
+
@chat = if @persist && RubyConversations.configuration.persistence_model
|
52
|
+
resolve_persistence_model.create!(model_id: llm, provider: provider)
|
53
|
+
else
|
54
|
+
RubyLLM.chat(model: llm, provider: provider).with_temperature(0.0)
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
58
|
def model_identifier
|
@@ -64,6 +80,19 @@ module RubyConversations
|
|
64
80
|
|
65
81
|
private
|
66
82
|
|
83
|
+
def resolve_persistence_model
|
84
|
+
model_config = RubyConversations.configuration.persistence_model
|
85
|
+
unless model_config.is_a?(String)
|
86
|
+
raise ConfigurationError, "Invalid persistence_model configured: Must be a String, got #{model_config.class}"
|
87
|
+
end
|
88
|
+
|
89
|
+
model_config.safe_constantize ||
|
90
|
+
raise(ConfigurationError, "Invalid persistence_model configured: '#{model_config}' could not be resolved.")
|
91
|
+
rescue NameError => e
|
92
|
+
# Catch potential NameError from constantize if the class name is invalid
|
93
|
+
raise ConfigurationError, "Invalid persistence_model configured: #{e.message}"
|
94
|
+
end
|
95
|
+
|
67
96
|
def base_attributes
|
68
97
|
{
|
69
98
|
id: id
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module RubyConversations
|
4
4
|
# Configuration options for RubyConversations
|
5
5
|
class Configuration
|
6
|
-
attr_accessor :api_url, :jwt_secret, :default_llm_model, :default_llm_provider
|
6
|
+
attr_accessor :api_url, :jwt_secret, :default_llm_model, :default_llm_provider, :persistence_model
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@default_llm_model = 'claude-3-7-sonnet'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_conversations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Shippy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|