ruby_conversations 1.1.14 → 1.1.15
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/{app/models → lib}/ruby_conversations/concerns/conversation_chat.rb +3 -0
- data/{app/models → lib}/ruby_conversations/concerns/conversation_messages.rb +3 -0
- data/{app/models → lib}/ruby_conversations/concerns/conversation_templates.rb +3 -0
- data/{app/models → lib}/ruby_conversations/concerns/llm_credentials.rb +2 -0
- data/{app/models → lib}/ruby_conversations/concerns/message_api_attributes.rb +2 -0
- data/{app/models → lib}/ruby_conversations/concerns/message_attributes.rb +2 -0
- data/{app/models → lib}/ruby_conversations/concerns/message_processing.rb +2 -0
- data/{app/models/ruby_conversations/conversation.rb → lib/ruby_conversations/conversation_manager.rb} +18 -21
- data/{app/models → lib}/ruby_conversations/message.rb +0 -3
- data/{app/models → lib}/ruby_conversations/message_input.rb +8 -12
- data/{app/models → lib}/ruby_conversations/prompt.rb +13 -14
- data/lib/ruby_conversations/version.rb +1 -1
- data/lib/ruby_conversations.rb +15 -1
- metadata +14 -15
- data/app/models/ruby_conversations/concerns/message_validation.rb +0 -46
- /data/{app/models → lib}/ruby_conversations/message_builder.rb +0 -0
- /data/{app/models → lib}/ruby_conversations/message_prompt.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c699cebb71c6b474fc4d69f0303a09df442a3005b40a211aa2948da20bc4979
|
4
|
+
data.tar.gz: 59532ffda0093a97a4e3fbee0efb1544901efc6dcc6c31fbe13649768dd7644f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17f693b90549a70c3f8639934c264c00bdde4000b674405e99f8ecd2c4e5696b13a1df18800180bc8ce6b0d2652e154ab81fee6f80bda46d4c824214dbeaa56f
|
7
|
+
data.tar.gz: 6c4caab21a4028c519a5a7d381e264494a752235b22424d144afc2c101bd61b295ed0ae004b7f38c2d2d3d39cf6ddc0b1e8a6edf3a3dad6a78fd80861d5f6162
|
@@ -1,33 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
4
4
|
|
5
5
|
module RubyConversations
|
6
|
-
#
|
7
|
-
class
|
8
|
-
include ActiveModel::Model
|
6
|
+
# Manages a conversation, including message storage, relationships, and LLM integration.
|
7
|
+
class ConversationManager
|
9
8
|
include RubyConversations::Concerns::ConversationChat
|
10
9
|
include RubyConversations::Concerns::ConversationMessages
|
11
10
|
include RubyConversations::Concerns::ConversationTemplates
|
12
11
|
include RubyConversations::Concerns::LlmCredentials
|
13
|
-
|
12
|
+
|
14
13
|
include RubyConversations::Concerns::MessageProcessing
|
15
14
|
|
16
15
|
attr_accessor :id, :conversationable_type, :conversationable_id, :conversationable,
|
17
16
|
:messages, :tool, :tools, :created_at, :updated_at
|
18
17
|
|
19
|
-
validates :messages, presence: { message: 'At least one message is required' }, on: :update
|
20
|
-
validate :validate_messages
|
21
|
-
|
22
18
|
def initialize(attributes = {})
|
23
|
-
|
24
|
-
@model_identifier = attributes.delete(:model_identifier)
|
25
|
-
@provider = attributes.delete(:provider)
|
26
|
-
@tools_optional = attributes.delete(:tools_optional)
|
27
|
-
@messages = []
|
28
|
-
|
19
|
+
setup_attributes(attributes)
|
29
20
|
configure_llm_credentials
|
30
|
-
|
21
|
+
configure_prompt_caching
|
31
22
|
end
|
32
23
|
|
33
24
|
def chat
|
@@ -73,14 +64,20 @@ module RubyConversations
|
|
73
64
|
}
|
74
65
|
end
|
75
66
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
67
|
+
def setup_attributes(attributes)
|
68
|
+
@chat = attributes.delete(:chat)
|
69
|
+
@model_identifier = attributes.delete(:model_identifier)
|
70
|
+
@provider = attributes.delete(:provider)
|
71
|
+
@tools_optional = attributes.delete(:tools_optional)
|
72
|
+
@messages = []
|
79
73
|
|
80
|
-
|
81
|
-
|
82
|
-
end
|
74
|
+
attributes.each do |key, value|
|
75
|
+
public_send("#{key}=", value) if respond_to?("#{key}=")
|
83
76
|
end
|
84
77
|
end
|
78
|
+
|
79
|
+
def configure_prompt_caching
|
80
|
+
chat.cache_prompts(system: true, tools: true, user: true)
|
81
|
+
end
|
85
82
|
end
|
86
83
|
end
|
@@ -1,19 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
4
|
|
5
5
|
module RubyConversations
|
6
6
|
# Represents an input value for a message prompt
|
7
7
|
class MessageInput
|
8
|
-
include ActiveModel::Model
|
9
|
-
|
10
8
|
# Define attributes
|
11
9
|
attr_accessor :id, :message_prompt_id, :placeholder_name, :value,
|
12
10
|
:created_at, :updated_at
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
attr_reader :message_prompt
|
13
|
+
|
14
|
+
def initialize(attributes = {})
|
15
|
+
attributes.each do |key, value|
|
16
|
+
public_send("#{key}=", value) if respond_to?("#{key}=")
|
17
|
+
end
|
18
|
+
end
|
17
19
|
|
18
20
|
# Association-like methods
|
19
21
|
def message_prompt=(prompt)
|
@@ -21,8 +23,6 @@ module RubyConversations
|
|
21
23
|
@message_prompt_id = prompt&.id
|
22
24
|
end
|
23
25
|
|
24
|
-
attr_reader :message_prompt
|
25
|
-
|
26
26
|
# Scopes
|
27
27
|
def self.ordered
|
28
28
|
all.sort_by(&:placeholder_name)
|
@@ -48,10 +48,6 @@ module RubyConversations
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def value_not_nil
|
52
|
-
errors.add(:value, "can't be blank") if value.nil?
|
53
|
-
end
|
54
|
-
|
55
51
|
def base_attributes
|
56
52
|
{
|
57
53
|
'id' => id,
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
4
|
|
5
5
|
module RubyConversations
|
6
6
|
# Represents a prompt template used to generate AI messages.
|
7
7
|
class Prompt
|
8
|
-
include ActiveModel::Model
|
9
|
-
|
10
8
|
# Define attributes
|
11
9
|
attr_accessor :id, :name, :role, :message, :valid_placeholders, :temperature, :metadata, :created_at, :updated_at,
|
12
10
|
:latest_version_id, :llm
|
@@ -14,6 +12,12 @@ module RubyConversations
|
|
14
12
|
# Constants
|
15
13
|
ROLES = %w[system user assistant].freeze
|
16
14
|
|
15
|
+
def initialize(attributes = {})
|
16
|
+
attributes.each do |key, value|
|
17
|
+
public_send("#{key}=", value) if respond_to?("#{key}=")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
17
21
|
# Class methods
|
18
22
|
def self.roles
|
19
23
|
ROLES
|
@@ -31,19 +35,14 @@ module RubyConversations
|
|
31
35
|
find_by_name!(name)
|
32
36
|
end
|
33
37
|
|
34
|
-
# Validations
|
35
|
-
validates :name, presence: true
|
36
|
-
validates :role, presence: true, inclusion: { in: ROLES }
|
37
|
-
validates :message, presence: true
|
38
|
-
|
39
|
-
# Initialization
|
40
|
-
def initialize(attributes = {})
|
41
|
-
super
|
42
|
-
end
|
43
|
-
|
44
38
|
# Basic attributes method
|
45
39
|
def attributes
|
46
|
-
|
40
|
+
{
|
41
|
+
'id' => id, 'name' => name, 'role' => role, 'message' => message,
|
42
|
+
'valid_placeholders' => valid_placeholders, 'temperature' => temperature,
|
43
|
+
'metadata' => metadata, 'created_at' => created_at, 'updated_at' => updated_at,
|
44
|
+
'latest_version_id' => latest_version_id, 'llm' => llm
|
45
|
+
}
|
47
46
|
end
|
48
47
|
|
49
48
|
# Method for API serialization
|
data/lib/ruby_conversations.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'zeitwerk'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
4
5
|
require 'ruby_conversations/version'
|
5
6
|
require 'ruby_conversations/configuration'
|
6
7
|
require 'ruby_conversations/errors'
|
7
8
|
require 'ruby_conversations/client'
|
8
9
|
require 'ruby_conversations/aws_credential_provider'
|
10
|
+
require 'ruby_conversations/concerns/conversation_chat'
|
11
|
+
require 'ruby_conversations/concerns/conversation_messages'
|
12
|
+
require 'ruby_conversations/concerns/conversation_templates'
|
13
|
+
require 'ruby_conversations/concerns/llm_credentials'
|
14
|
+
|
15
|
+
require 'ruby_conversations/concerns/message_processing'
|
16
|
+
require 'ruby_conversations/concerns/message_attributes'
|
17
|
+
require 'ruby_conversations/concerns/message_api_attributes'
|
18
|
+
require 'ruby_conversations/message_input'
|
19
|
+
require 'ruby_conversations/message_prompt'
|
20
|
+
require 'ruby_conversations/message'
|
21
|
+
require 'ruby_conversations/prompt'
|
22
|
+
require 'ruby_conversations/message_builder'
|
23
|
+
require 'ruby_conversations/conversation_manager'
|
9
24
|
require 'ruby_llm'
|
10
25
|
|
11
26
|
# Main module for RubyConversations
|
@@ -44,5 +59,4 @@ end
|
|
44
59
|
|
45
60
|
# Set up Zeitwerk autoloading
|
46
61
|
loader = Zeitwerk::Loader.new
|
47
|
-
loader.push_dir("#{__dir__}/../app/models")
|
48
62
|
loader.setup
|
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.
|
4
|
+
version: 1.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Shippy
|
@@ -256,26 +256,25 @@ extensions: []
|
|
256
256
|
extra_rdoc_files: []
|
257
257
|
files:
|
258
258
|
- README.md
|
259
|
-
- app/models/ruby_conversations/concerns/conversation_chat.rb
|
260
|
-
- app/models/ruby_conversations/concerns/conversation_messages.rb
|
261
|
-
- app/models/ruby_conversations/concerns/conversation_templates.rb
|
262
|
-
- app/models/ruby_conversations/concerns/llm_credentials.rb
|
263
|
-
- app/models/ruby_conversations/concerns/message_api_attributes.rb
|
264
|
-
- app/models/ruby_conversations/concerns/message_attributes.rb
|
265
|
-
- app/models/ruby_conversations/concerns/message_processing.rb
|
266
|
-
- app/models/ruby_conversations/concerns/message_validation.rb
|
267
|
-
- app/models/ruby_conversations/conversation.rb
|
268
|
-
- app/models/ruby_conversations/message.rb
|
269
|
-
- app/models/ruby_conversations/message_builder.rb
|
270
|
-
- app/models/ruby_conversations/message_input.rb
|
271
|
-
- app/models/ruby_conversations/message_prompt.rb
|
272
|
-
- app/models/ruby_conversations/prompt.rb
|
273
259
|
- lib/ruby_conversations.rb
|
274
260
|
- lib/ruby_conversations/aws_credential_provider.rb
|
275
261
|
- lib/ruby_conversations/client.rb
|
262
|
+
- lib/ruby_conversations/concerns/conversation_chat.rb
|
263
|
+
- lib/ruby_conversations/concerns/conversation_messages.rb
|
264
|
+
- lib/ruby_conversations/concerns/conversation_templates.rb
|
265
|
+
- lib/ruby_conversations/concerns/llm_credentials.rb
|
266
|
+
- lib/ruby_conversations/concerns/message_api_attributes.rb
|
267
|
+
- lib/ruby_conversations/concerns/message_attributes.rb
|
268
|
+
- lib/ruby_conversations/concerns/message_processing.rb
|
276
269
|
- lib/ruby_conversations/configuration.rb
|
270
|
+
- lib/ruby_conversations/conversation_manager.rb
|
277
271
|
- lib/ruby_conversations/engine.rb
|
278
272
|
- lib/ruby_conversations/errors.rb
|
273
|
+
- lib/ruby_conversations/message.rb
|
274
|
+
- lib/ruby_conversations/message_builder.rb
|
275
|
+
- lib/ruby_conversations/message_input.rb
|
276
|
+
- lib/ruby_conversations/message_prompt.rb
|
277
|
+
- lib/ruby_conversations/prompt.rb
|
279
278
|
- lib/ruby_conversations/version.rb
|
280
279
|
homepage: https://github.com/StrongMind/ruby-conversations
|
281
280
|
licenses:
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
module Concerns
|
5
|
-
# Handles validation-related functionality for Message
|
6
|
-
module MessageValidation
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def validate_messages
|
12
|
-
messages.each do |message|
|
13
|
-
next if message.valid?
|
14
|
-
|
15
|
-
message.errors.full_messages.each do |msg|
|
16
|
-
errors.add(:messages, "invalid: #{msg}")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def validate_message_level(message)
|
22
|
-
return if message.valid?
|
23
|
-
|
24
|
-
message.errors.full_messages.each do |msg|
|
25
|
-
errors.add(:base, "Message error: #{msg}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def validate_prompt_level(prompt)
|
30
|
-
return if prompt.valid?
|
31
|
-
|
32
|
-
prompt.errors.full_messages.each do |msg|
|
33
|
-
errors.add(:base, "Message prompt error: #{msg}")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def validate_input_level(input)
|
38
|
-
return if input.valid?
|
39
|
-
|
40
|
-
input.errors.full_messages.each do |msg|
|
41
|
-
errors.add(:base, "Message prompt input error: #{msg}")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
File without changes
|
File without changes
|