ruby_conversations 1.0.13 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aff2d69d93269766f9c467bf51769bf4fa6e96843fff2019b7920f7229aabd1c
4
- data.tar.gz: d9bfcd7fc3f4c1900c51dc8576e5f51d9725cbc284eec25fa5bbe60fda419ad6
3
+ metadata.gz: ce57aae2af7a87f50877f69671efef0753458e9cce7b7add9947c327143b3861
4
+ data.tar.gz: 7d94fdd743f9a0c7180dcc1625ad73d10fcd0fe46c95b9d9d6c418258a3e57ff
5
5
  SHA512:
6
- metadata.gz: 6d8b57d3de0e5344ba6bd9eb8ff84a62ba0eb0bf81553604113bd6f40146148d9cffcc60d65c91922e97e3703021e5898bd7362a3b97b555e47c826985e50d76
7
- data.tar.gz: 755d57ff124a880a2a1f70fe9f1d573206e7c3002c8f813bfdff960adb30211110728cd4a9487ba8afc7599b273a59e2d0939f996157cbfcc43c9c04a0097a32
6
+ metadata.gz: e1970d41c9944ee5ca5df9faa3407f36328a0551c9b16dc4330172da7a682fc22225aa62c4406018f5ea97b787dc1369162f2bc81a92ffd44780472df4c94272
7
+ data.tar.gz: 1b1ecae17f206f2c2799318bfc7b94e53d765abf9c407d1391ba926022d8297bacad0eea305cd09b38753b65be5fbf672463486048dfe9d4be2ab433de8a32b5
@@ -10,14 +10,30 @@ module RubyConversations
10
10
  validate_conversation_state
11
11
  chat_messages = generate_chat_response(system_message)
12
12
 
13
- if tool.present?
14
- tool_calls = chat_messages.filter { |message| message.tool_calls.present? }
15
- raise "No tool call found for tool '#{tool}'. Please check the prompt." if tool_calls.empty?
16
- end
13
+ validate_tool_calls(chat_messages)
17
14
 
18
15
  store_and_update_conversation(chat_messages)
19
16
  end
20
17
 
18
+ def validate_tool_calls(chat_messages)
19
+ return unless tools_configured?
20
+ return if tool_calls?(chat_messages)
21
+
22
+ raise "No tool call found for tool(s): '#{tool_names}'. Please check the prompt."
23
+ end
24
+
25
+ def tools_configured?
26
+ tool.present? || tools&.present?
27
+ end
28
+
29
+ def tool_names
30
+ tool&.name || tools&.map(&:name)
31
+ end
32
+
33
+ def tool_calls?(chat_messages)
34
+ chat_messages.any? { |message| message.tool_calls.present? }
35
+ end
36
+
21
37
  def llm
22
38
  case model_identifier
23
39
  when 'claude-3-7-sonnet'
@@ -35,7 +51,7 @@ module RubyConversations
35
51
  end
36
52
 
37
53
  def generate_chat_response(system_message)
38
- chat = setup_llm_chat(system_message: system_message)
54
+ setup_llm_chat(system_message: system_message)
39
55
  chat.ask(messages.last.request)
40
56
  chat.messages
41
57
  end
@@ -52,18 +68,17 @@ module RubyConversations
52
68
 
53
69
  def setup_llm_chat(system_message: nil)
54
70
  configure_llm_credentials
55
- build_chat(system_message)
71
+ configure_tools
72
+ chat.add_message(role: :system, content: system_message) if system_message.present?
56
73
  end
57
74
 
58
75
  def update_last_message_response(message, chat_messages)
59
76
  message.response = chat_messages.map(&:to_h).to_json
60
77
  end
61
78
 
62
- def build_chat(system_message)
63
- chat = RubyLLM.chat(model: llm, provider: provider).with_temperature(0.0)
79
+ def configure_tools
64
80
  chat.with_tool(tool) if tool.present?
65
- chat.add_message(role: :system, content: system_message) if system_message.present?
66
- chat
81
+ tools&.each { |tool| chat.with_tool(tool) }
67
82
  end
68
83
  end
69
84
  end
@@ -12,7 +12,7 @@ module RubyConversations
12
12
 
13
13
  def configure_llm_credentials
14
14
  RubyLLM.configure do |config|
15
- credentials = ENV['AWS_ACCESS_KEY_ID'].present? ? env_credentials : provider_credentials
15
+ credentials = provider_credentials
16
16
  config.bedrock_region = ENV.fetch('AWS_REGION', 'us-west-2')
17
17
  config.bedrock_api_key = credentials[:api_key]
18
18
  config.bedrock_secret_key = credentials[:secret_key]
@@ -13,8 +13,8 @@ module RubyConversations
13
13
  include RubyConversations::Concerns::MessageProcessing
14
14
 
15
15
  # Define attributes needed for API interaction & local state
16
- attr_accessor :id, :conversationable_type, :conversationable_id, :conversationable,
17
- :messages, :tool, :created_at, :updated_at
16
+ attr_accessor :chat, :id, :conversationable_type, :conversationable_id, :conversationable,
17
+ :messages, :tool, :tools, :created_at, :updated_at
18
18
 
19
19
  # Validations
20
20
  validates :messages, presence: { message: 'At least one message is required' }, on: :update
@@ -31,6 +31,12 @@ module RubyConversations
31
31
 
32
32
  super # Initialize with remaining attributes using ActiveModel::Model
33
33
  initialize_messages(messages_attrs)
34
+
35
+ build_chat
36
+ end
37
+
38
+ def build_chat
39
+ @chat = RubyLLM.chat(model: llm, provider: provider).with_temperature(0.0)
34
40
  end
35
41
 
36
42
  def model_identifier
@@ -54,7 +54,7 @@ module RubyConversations
54
54
  end
55
55
 
56
56
  def use_mock_credentials?
57
- ENV['RAILS_ENV'] != 'production'
57
+ ENV['RAILS_ENV'] == 'test'
58
58
  end
59
59
 
60
60
  def set_mock_credentials
@@ -3,7 +3,7 @@
3
3
  module RubyConversations
4
4
  MAJOR = 1
5
5
  MINOR = 0
6
- PATCH = 13
6
+ PATCH = 15
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.13
4
+ version: 1.0.15
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-17 00:00:00.000000000 Z
11
+ date: 2025-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport