ruby_llm-responses_api 0.1.0 → 0.2.0
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: ba5d18029ff9e07a0577fa0fc92b5946fe0b43768e495b5550dc6e3b396520b5
|
|
4
|
+
data.tar.gz: 67f47ef8f9ca80c54ad4765f0ade6f84a2dbdc04dfc9c9e42136c5c5aa8d1fe3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d943d82abf6f1afe6c268fbdbc8b9c0179321f67f188c3c1c25058387591673e91356616b1fafdf868da79ee1084aca90ad0117d0835fcd3dd0a238fb96cb712
|
|
7
|
+
data.tar.gz: 6b5906f1a604543b7a7cd34e25eb21faf500b2dd14558b174c6165da60cad656576b12af5e72cc49cd6960e9ad5e1210a6836bcc706be92e0b9ac77fea45c3ca
|
|
@@ -9,8 +9,9 @@ module RubyLLM
|
|
|
9
9
|
# This is automatically applied when Rails loads ActiveRecord.
|
|
10
10
|
# Just add a migration: add_column :messages, :response_id, :string
|
|
11
11
|
#
|
|
12
|
+
|
|
13
|
+
# Extension for the NEW MessageMethods (RubyLLM 2.0+)
|
|
12
14
|
module MessageMethodsExtension
|
|
13
|
-
# Override to_llm to include response_id for Responses API support
|
|
14
15
|
def to_llm
|
|
15
16
|
cached = has_attribute?(:cached_tokens) ? self[:cached_tokens] : nil
|
|
16
17
|
cache_creation = has_attribute?(:cache_creation_tokens) ? self[:cache_creation_tokens] : nil
|
|
@@ -31,13 +32,52 @@ module RubyLLM
|
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
#
|
|
35
|
+
# Extension for the NEW ChatMethods (RubyLLM 2.0+)
|
|
35
36
|
module ChatMethodsExtension
|
|
36
|
-
# Override persist_message_completion to also save response_id
|
|
37
37
|
def persist_message_completion(message)
|
|
38
38
|
super
|
|
39
|
+
save_response_id(message)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
def save_response_id(message)
|
|
45
|
+
return unless message
|
|
46
|
+
return unless message.respond_to?(:response_id) && message.response_id
|
|
47
|
+
return unless @message.has_attribute?(:response_id)
|
|
48
|
+
|
|
49
|
+
@message.update_column(:response_id, message.response_id)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Extension for LEGACY MessageLegacyMethods (RubyLLM 1.x)
|
|
54
|
+
module MessageLegacyMethodsExtension
|
|
55
|
+
def to_llm
|
|
56
|
+
resp_id = has_attribute?(:response_id) ? self[:response_id] : nil
|
|
57
|
+
|
|
58
|
+
RubyLLM::Message.new(
|
|
59
|
+
role: role.to_sym,
|
|
60
|
+
content: extract_content,
|
|
61
|
+
tool_calls: extract_tool_calls,
|
|
62
|
+
tool_call_id: extract_tool_call_id,
|
|
63
|
+
input_tokens: input_tokens,
|
|
64
|
+
output_tokens: output_tokens,
|
|
65
|
+
model_id: model_id,
|
|
66
|
+
response_id: resp_id
|
|
67
|
+
)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Extension for LEGACY ChatLegacyMethods (RubyLLM 1.x)
|
|
72
|
+
module ChatLegacyMethodsExtension
|
|
73
|
+
def persist_message_completion(message)
|
|
74
|
+
super
|
|
75
|
+
save_response_id_legacy(message)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def save_response_id_legacy(message)
|
|
41
81
|
return unless message
|
|
42
82
|
return unless message.respond_to?(:response_id) && message.response_id
|
|
43
83
|
return unless @message.has_attribute?(:response_id)
|
|
@@ -53,16 +93,37 @@ module RubyLLM
|
|
|
53
93
|
def self.apply_active_record_extensions!
|
|
54
94
|
return if @active_record_extensions_applied
|
|
55
95
|
|
|
56
|
-
|
|
57
|
-
require 'ruby_llm/active_record/chat_methods'
|
|
96
|
+
applied = false
|
|
58
97
|
|
|
59
|
-
RubyLLM
|
|
60
|
-
|
|
98
|
+
# Try to apply to NEW modules (RubyLLM 2.0+)
|
|
99
|
+
begin
|
|
100
|
+
require 'ruby_llm/active_record/message_methods'
|
|
101
|
+
require 'ruby_llm/active_record/chat_methods'
|
|
102
|
+
|
|
103
|
+
RubyLLM::ActiveRecord::MessageMethods.prepend(MessageMethodsExtension)
|
|
104
|
+
RubyLLM::ActiveRecord::ChatMethods.prepend(ChatMethodsExtension)
|
|
105
|
+
applied = true
|
|
106
|
+
rescue LoadError, NameError
|
|
107
|
+
# New modules not available
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Try to apply to LEGACY modules (RubyLLM 1.x)
|
|
111
|
+
begin
|
|
112
|
+
require 'ruby_llm/active_record/acts_as_legacy'
|
|
113
|
+
|
|
114
|
+
if defined?(RubyLLM::ActiveRecord::MessageLegacyMethods)
|
|
115
|
+
RubyLLM::ActiveRecord::MessageLegacyMethods.prepend(MessageLegacyMethodsExtension)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
if defined?(RubyLLM::ActiveRecord::ChatLegacyMethods)
|
|
119
|
+
RubyLLM::ActiveRecord::ChatLegacyMethods.prepend(ChatLegacyMethodsExtension)
|
|
120
|
+
end
|
|
121
|
+
applied = true
|
|
122
|
+
rescue LoadError, NameError
|
|
123
|
+
# Legacy modules not available
|
|
124
|
+
end
|
|
61
125
|
|
|
62
|
-
@active_record_extensions_applied =
|
|
63
|
-
rescue LoadError, NameError
|
|
64
|
-
# RubyLLM ActiveRecord support not available, skip silently
|
|
65
|
-
nil
|
|
126
|
+
@active_record_extensions_applied = applied
|
|
66
127
|
end
|
|
67
128
|
end
|
|
68
129
|
end
|