ruby_conversations 1.0.14 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce57aae2af7a87f50877f69671efef0753458e9cce7b7add9947c327143b3861
|
4
|
+
data.tar.gz: 7d94fdd743f9a0c7180dcc1625ad73d10fcd0fe46c95b9d9d6c418258a3e57ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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.
|
66
|
-
chat
|
81
|
+
tools&.each { |tool| chat.with_tool(tool) }
|
67
82
|
end
|
68
83
|
end
|
69
84
|
end
|
@@ -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
|
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.
|
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-
|
11
|
+
date: 2025-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|