ruby_conversations 1.0.0 → 1.0.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: 29d0a2bc2bf832a2bd4a452e1213d024604d73c3be3406851d2ac77dce20278d
4
- data.tar.gz: 973a5a996c8146aa0651dfeb42cb95d27c9a4623c53b1b4f662cefb48f90bc88
3
+ metadata.gz: 6928d1d487d9e5a716b8e9bcdf4f0e4363ae2bb2d2cc1ee4939df4e4aee7764a
4
+ data.tar.gz: ab759bb89535426def0743f50e7e0711adc9012f3c61bd7a2daf7e722d7644e1
5
5
  SHA512:
6
- metadata.gz: bf8a698597f4a53c26a0850ee8afc0552d9280b5ea46ba05b890e5bebaa587e40d666e93349ec1667e1ac438c881b9a1afa79b7482cc970fedc49d7e89d49be5
7
- data.tar.gz: c9b77726ec303b37ad0af8f8e16ad3979802f8d995c254dcd2713a4a60563e0cbd7865b4bb433ade118ff2a597c8cc896940004b0abc874b802c63f666d037ba
6
+ metadata.gz: d875c52d737a2dcf105d5be833c1168282a2c92f3df6f9c781cbe7975778b1916d8b067e0a95a4a5cfc733e656c49390d2453d02889253ea8622985826b800a6
7
+ data.tar.gz: 4ec9eea20a8a9c61535bd4fdfa487c040fa07a779e43adda68baaac59a6a00a44967cf54bdc1c440ae5543e113c8fed988cdf969e9a2e0408afe966a2dba75ac
@@ -19,18 +19,14 @@ module RubyConversations
19
19
  end
20
20
 
21
21
  def build_from_multiple_prompts(prompt_inputs, description: nil)
22
- message = @conversation.ai_messages.build(
23
- request: '',
24
- change_description: description,
25
- llm: @conversation.model_identifier,
26
- tool: @conversation.tool
27
- )
22
+ message = initialize_ai_message(description)
28
23
 
29
24
  prompt_inputs.each do |prompt_name, inputs|
30
25
  process_single_prompt_input(message, prompt_name, inputs)
31
26
  end
32
27
 
33
- message # Return the built message
28
+ message.request = message.request.strip
29
+ message
34
30
  end
35
31
 
36
32
  def process_single_prompt_input(message, prompt_name, inputs)
@@ -38,7 +34,7 @@ module RubyConversations
38
34
  validate_inputs!(prompt, inputs)
39
35
 
40
36
  interpolated_message = prompt.interpolate(inputs)
41
- message.request += interpolated_message
37
+ message.request += "#{interpolated_message}\n\n"
42
38
 
43
39
  message_prompt = message.ai_message_prompts.build(
44
40
  prompt_version_id: prompt.latest_version_id,
@@ -49,6 +45,15 @@ module RubyConversations
49
45
 
50
46
  private
51
47
 
48
+ def initialize_ai_message(description)
49
+ @conversation.ai_messages.build(
50
+ request: '',
51
+ change_description: description,
52
+ llm: @conversation.model_identifier,
53
+ tool: @conversation.tool
54
+ )
55
+ end
56
+
52
57
  def validate_inputs!(prompt, inputs)
53
58
  return unless prompt.valid_placeholders.present?
54
59
 
@@ -63,7 +68,6 @@ module RubyConversations
63
68
 
64
69
  def build_prompt_association(message, prompt, inputs)
65
70
  message_prompt = message.ai_message_prompts.build(
66
- prompt: prompt,
67
71
  prompt_version_id: prompt.latest_version_id,
68
72
  draft: prompt.message
69
73
  )
@@ -16,11 +16,9 @@ module RubyConversations
16
16
  belongs_to :organization, optional: true
17
17
 
18
18
  # Validations
19
- validates :message, presence: true
20
19
  validates :name, presence: true, uniqueness: true
21
20
  validates :temperature, numericality: { greater_than_or_equal_to: 0.0 }, allow_nil: true
22
21
  validates :role, presence: true, inclusion: { in: VALID_ROLES }
23
- validate :validate_placeholders_format
24
22
 
25
23
  # Scopes
26
24
  scope :active, -> { where(active: true) }
@@ -50,55 +48,14 @@ module RubyConversations
50
48
  end
51
49
 
52
50
  def interpolate(inputs = {})
53
- return message if placeholders.empty?
54
-
55
- validate_required_variables!(inputs)
56
-
57
51
  interpolated = message.dup
58
52
  format(interpolated, **inputs)
59
53
  end
60
54
 
61
- def placeholders
62
- return [] if message.nil?
63
-
64
- matches = message.scan(/%<([^>]+)>/)
65
- matches&.flatten&.uniq || []
66
- end
67
-
68
- def active?
69
- active
70
- end
71
-
72
- def deactivate!
73
- update!(active: false)
74
- end
75
-
76
- def activate!
77
- update!(active: true)
78
- end
79
-
80
55
  private
81
56
 
82
57
  def versioned_attributes
83
58
  %i[content role]
84
59
  end
85
-
86
- def validate_placeholders_format
87
- invalid_placeholders = placeholders.grep_v(/\A[a-z_][a-z0-9_]*\z/i)
88
-
89
- return unless invalid_placeholders.any?
90
-
91
- errors.add(:message, "contains invalid placeholders: #{invalid_placeholders.join(', ')}")
92
- end
93
-
94
- def validate_required_variables!(variables)
95
- missing = placeholders - variables.keys.map(&:to_s)
96
- raise ArgumentError, "Missing required variables: #{missing.join(', ')}" if missing.any?
97
-
98
- extra = variables.keys.map(&:to_s) - placeholders
99
- return unless extra.any?
100
-
101
- raise ArgumentError, "Unknown variables provided: #{extra.join(', ')}"
102
- end
103
60
  end
104
61
  end
@@ -3,7 +3,7 @@
3
3
  module RubyConversations
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
- PATCH = 0 # this is automatically incremented by the build process
6
+ PATCH = 2
7
7
 
8
8
  VERSION = "#{RubyConversations::MAJOR}.#{RubyConversations::MINOR}.#{RubyConversations::PATCH}".freeze
9
9
  end
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.0.0
4
+ version: 1.0.2
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-01 00:00:00.000000000 Z
11
+ date: 2025-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday