ruby_conversations 1.0.7 → 1.0.9
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/README.md +5 -41
- data/app/models/concerns/ruby_conversations/conversation_chat.rb +49 -0
- data/app/models/concerns/ruby_conversations/conversation_messages.rb +18 -0
- data/app/models/{ruby_conversations/concerns → concerns/ruby_conversations}/llm_credentials.rb +1 -0
- data/app/models/concerns/ruby_conversations/message_api_attributes.rb +39 -0
- data/app/models/concerns/ruby_conversations/message_attributes.rb +44 -0
- data/app/models/concerns/ruby_conversations/message_processing.rb +48 -0
- data/app/models/{ruby_conversations/concerns → concerns/ruby_conversations}/message_validation.rb +2 -2
- data/app/models/concerns/ruby_conversations/storable.rb +13 -0
- data/app/models/ruby_conversations/conversation.rb +102 -0
- data/app/models/ruby_conversations/message.rb +108 -0
- data/app/models/ruby_conversations/message_builder.rb +45 -20
- data/app/models/ruby_conversations/message_input.rb +69 -0
- data/app/models/ruby_conversations/message_prompt.rb +110 -0
- data/app/models/ruby_conversations/prompt.rb +48 -39
- data/lib/ruby_conversations/aws_credential_provider.rb +11 -5
- data/lib/ruby_conversations/client.rb +90 -0
- data/lib/ruby_conversations/configuration.rb +3 -13
- data/lib/ruby_conversations/engine.rb +2 -0
- data/lib/ruby_conversations/errors.rb +9 -0
- data/lib/ruby_conversations/version.rb +1 -1
- data/lib/ruby_conversations.rb +15 -42
- metadata +43 -81
- data/Rakefile +0 -12
- data/app/models/concerns/ruby_conversations/messageable.rb +0 -13
- data/app/models/concerns/ruby_conversations/versionable.rb +0 -20
- data/app/models/ruby_conversations/ai_conversation.rb +0 -91
- data/app/models/ruby_conversations/ai_message.rb +0 -28
- data/app/models/ruby_conversations/ai_message_input.rb +0 -22
- data/app/models/ruby_conversations/ai_message_prompt.rb +0 -28
- data/app/models/ruby_conversations/prompt_version.rb +0 -16
- data/lib/generators/ruby_conversations/install/install_generator.rb +0 -60
- data/lib/generators/ruby_conversations/install/templates/README.md +0 -42
- data/lib/generators/ruby_conversations/install/templates/initializer.rb.erb +0 -18
- data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_conversations.rb.erb +0 -13
- data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_inputs.rb.erb +0 -13
- data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_prompts.rb.erb +0 -18
- data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_messages.rb.erb +0 -18
- data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_tool_calls.rb.erb +0 -15
- data/lib/generators/ruby_conversations/install/templates/migrations/create_prompt_versions.rb.erb +0 -14
- data/lib/generators/ruby_conversations/install/templates/migrations/create_prompts.rb.erb +0 -16
- data/lib/ruby_conversations/jwt_client.rb +0 -23
- data/lib/ruby_conversations/storage/base.rb +0 -28
- data/lib/ruby_conversations/storage/local.rb +0 -30
- data/lib/ruby_conversations/storage/remote.rb +0 -93
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.9
|
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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '7.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: aws-sdk-core
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,21 +67,21 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '2.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: ruby_llm
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - "
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '1.1'
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - "
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '1.1'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: strongmind-auth
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
@@ -86,14 +100,14 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
103
|
+
version: '2.6'
|
90
104
|
type: :runtime
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: '2.
|
110
|
+
version: '2.6'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: bootsnap
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +122,6 @@ dependencies:
|
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '1.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: database_cleaner-active_record
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: dotenv-rails
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,21 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: parallel_tests
|
140
|
+
name: factory_bot
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
143
|
- - ">="
|
@@ -165,7 +151,7 @@ dependencies:
|
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: '0'
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
154
|
+
name: pry-byebug
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
170
156
|
requirements:
|
171
157
|
- - ">="
|
@@ -179,7 +165,7 @@ dependencies:
|
|
179
165
|
- !ruby/object:Gem::Version
|
180
166
|
version: '0'
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
|
-
name:
|
168
|
+
name: rspec
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|
184
170
|
requirements:
|
185
171
|
- - ">="
|
@@ -248,21 +234,7 @@ dependencies:
|
|
248
234
|
- - ">="
|
249
235
|
- !ruby/object:Gem::Version
|
250
236
|
version: '0'
|
251
|
-
|
252
|
-
name: sqlite3
|
253
|
-
requirement: !ruby/object:Gem::Requirement
|
254
|
-
requirements:
|
255
|
-
- - ">="
|
256
|
-
- !ruby/object:Gem::Version
|
257
|
-
version: '0'
|
258
|
-
type: :development
|
259
|
-
prerelease: false
|
260
|
-
version_requirements: !ruby/object:Gem::Requirement
|
261
|
-
requirements:
|
262
|
-
- - ">="
|
263
|
-
- !ruby/object:Gem::Version
|
264
|
-
version: '0'
|
265
|
-
description: 'A Rails engine for managing AI conversations with support for both '
|
237
|
+
description: A Ruby client library for managing AI conversations via a remote API.
|
266
238
|
email:
|
267
239
|
- paul.shippy@strongmind.com
|
268
240
|
executables: []
|
@@ -270,36 +242,26 @@ extensions: []
|
|
270
242
|
extra_rdoc_files: []
|
271
243
|
files:
|
272
244
|
- README.md
|
273
|
-
-
|
274
|
-
- app/models/concerns/ruby_conversations/
|
275
|
-
- app/models/concerns/ruby_conversations/
|
276
|
-
- app/models/ruby_conversations/
|
277
|
-
- app/models/ruby_conversations/
|
278
|
-
- app/models/ruby_conversations/
|
279
|
-
- app/models/ruby_conversations/
|
280
|
-
- app/models/ruby_conversations/
|
281
|
-
- app/models/ruby_conversations/
|
245
|
+
- app/models/concerns/ruby_conversations/conversation_chat.rb
|
246
|
+
- app/models/concerns/ruby_conversations/conversation_messages.rb
|
247
|
+
- app/models/concerns/ruby_conversations/llm_credentials.rb
|
248
|
+
- app/models/concerns/ruby_conversations/message_api_attributes.rb
|
249
|
+
- app/models/concerns/ruby_conversations/message_attributes.rb
|
250
|
+
- app/models/concerns/ruby_conversations/message_processing.rb
|
251
|
+
- app/models/concerns/ruby_conversations/message_validation.rb
|
252
|
+
- app/models/concerns/ruby_conversations/storable.rb
|
253
|
+
- app/models/ruby_conversations/conversation.rb
|
254
|
+
- app/models/ruby_conversations/message.rb
|
282
255
|
- app/models/ruby_conversations/message_builder.rb
|
256
|
+
- app/models/ruby_conversations/message_input.rb
|
257
|
+
- app/models/ruby_conversations/message_prompt.rb
|
283
258
|
- app/models/ruby_conversations/prompt.rb
|
284
|
-
- app/models/ruby_conversations/prompt_version.rb
|
285
|
-
- lib/generators/ruby_conversations/install/install_generator.rb
|
286
|
-
- lib/generators/ruby_conversations/install/templates/README.md
|
287
|
-
- lib/generators/ruby_conversations/install/templates/initializer.rb.erb
|
288
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_ai_conversations.rb.erb
|
289
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_inputs.rb.erb
|
290
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_prompts.rb.erb
|
291
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_ai_messages.rb.erb
|
292
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_ai_tool_calls.rb.erb
|
293
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_prompt_versions.rb.erb
|
294
|
-
- lib/generators/ruby_conversations/install/templates/migrations/create_prompts.rb.erb
|
295
259
|
- lib/ruby_conversations.rb
|
296
260
|
- lib/ruby_conversations/aws_credential_provider.rb
|
261
|
+
- lib/ruby_conversations/client.rb
|
297
262
|
- lib/ruby_conversations/configuration.rb
|
298
263
|
- lib/ruby_conversations/engine.rb
|
299
|
-
- lib/ruby_conversations/
|
300
|
-
- lib/ruby_conversations/storage/base.rb
|
301
|
-
- lib/ruby_conversations/storage/local.rb
|
302
|
-
- lib/ruby_conversations/storage/remote.rb
|
264
|
+
- lib/ruby_conversations/errors.rb
|
303
265
|
- lib/ruby_conversations/version.rb
|
304
266
|
homepage: https://github.com/StrongMind/ruby-conversations
|
305
267
|
licenses:
|
@@ -327,5 +289,5 @@ requirements: []
|
|
327
289
|
rubygems_version: 3.4.10
|
328
290
|
signing_key:
|
329
291
|
specification_version: 4
|
330
|
-
summary:
|
292
|
+
summary: Client library for interacting with the AI Conversation Service
|
331
293
|
test_files: []
|
data/Rakefile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# Provides message-related functionalities for conversations.
|
5
|
-
module Messageable
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
has_many :ai_conversations, as: :conversationable, dependent: :destroy
|
10
|
-
has_many :ai_messages, through: :ai_conversations
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# Provides versioning functionalities for models.
|
5
|
-
module Versionable
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
has_many :versions, class_name: 'PromptVersion', dependent: :destroy
|
10
|
-
has_one :latest_version, -> { order(version: :desc) }, class_name: 'PromptVersion'
|
11
|
-
|
12
|
-
delegate :content, :metadata, to: :latest_version, allow_nil: true
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_version!(content:, metadata: {})
|
16
|
-
next_version = versions.maximum(:version).to_i + 1
|
17
|
-
versions.create!(content: content, metadata: metadata, version: next_version)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'concerns/message_validation'
|
4
|
-
require_relative 'concerns/llm_credentials'
|
5
|
-
|
6
|
-
module RubyConversations
|
7
|
-
# An AI conversation is a conversation between an AI and a user.
|
8
|
-
class AiConversation < ActiveRecord::Base
|
9
|
-
include RubyConversations::MessageValidation
|
10
|
-
include RubyConversations::LlmCredentials
|
11
|
-
|
12
|
-
# Associations
|
13
|
-
belongs_to :conversationable, polymorphic: true, optional: true, touch: true
|
14
|
-
has_many :ai_messages, class_name: RubyConversations.configuration.message_class, dependent: :destroy
|
15
|
-
|
16
|
-
# Validations
|
17
|
-
validates :ai_messages, presence: { message: 'At least one message is required' }, on: :update
|
18
|
-
validate :validate_messages
|
19
|
-
|
20
|
-
# Scopes
|
21
|
-
scope :recent, -> { order(updated_at: :desc) }
|
22
|
-
scope :with_messages, -> { includes(:ai_messages) }
|
23
|
-
|
24
|
-
# Attributes
|
25
|
-
attr_accessor :model_identifier, :provider, :tool
|
26
|
-
|
27
|
-
def initialize(attributes = nil)
|
28
|
-
attributes ||= {}
|
29
|
-
super
|
30
|
-
@model_identifier ||= attributes[:model_identifier] || RubyConversations.configuration.default_llm_model
|
31
|
-
@provider ||= attributes[:provider] || RubyConversations.configuration.default_llm_provider
|
32
|
-
end
|
33
|
-
|
34
|
-
# Instance Methods
|
35
|
-
def ask_multiple(prompt_inputs, description: nil)
|
36
|
-
MessageBuilder.new(self).build_from_multiple_prompts(prompt_inputs, description: description)
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def ask(name, description: nil, inputs: {})
|
41
|
-
MessageBuilder.new(self).build_from_single_prompt(name, description: description, inputs: inputs)
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
def execute(system_message: nil)
|
46
|
-
save!
|
47
|
-
message = ai_messages.last
|
48
|
-
raise ArgumentError, 'Conversation must have at least one message to execute' unless message
|
49
|
-
|
50
|
-
chat = setup_llm_chat(system_message: system_message)
|
51
|
-
response = chat.ask(message.request)
|
52
|
-
update_last_message_response(message, response)
|
53
|
-
response
|
54
|
-
end
|
55
|
-
|
56
|
-
def latest_message
|
57
|
-
ai_messages.order(created_at: :desc).first
|
58
|
-
end
|
59
|
-
|
60
|
-
def message_count
|
61
|
-
ai_messages.count
|
62
|
-
end
|
63
|
-
|
64
|
-
def llm
|
65
|
-
case model_identifier
|
66
|
-
when 'claude-3-7-sonnet'
|
67
|
-
'us.anthropic.claude-3-7-sonnet-20250219-v1:0'
|
68
|
-
else
|
69
|
-
model_identifier
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
private
|
74
|
-
|
75
|
-
def setup_llm_chat(system_message: nil)
|
76
|
-
configure_llm_credentials
|
77
|
-
build_chat(system_message)
|
78
|
-
end
|
79
|
-
|
80
|
-
def update_last_message_response(message, response)
|
81
|
-
message.update!(response: response.to_h.to_json)
|
82
|
-
end
|
83
|
-
|
84
|
-
def build_chat(system_message)
|
85
|
-
chat = RubyLLM.chat(model: llm, provider: provider).with_temperature(0.0)
|
86
|
-
chat.with_tool(tool) if tool.present?
|
87
|
-
chat.add_message(role: :system, content: system_message) if system_message.present?
|
88
|
-
chat
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# An AI message is a message in an AI conversation.
|
5
|
-
class AiMessage < ActiveRecord::Base
|
6
|
-
# Associations
|
7
|
-
belongs_to :ai_conversation, class_name: RubyConversations.configuration.conversation_class
|
8
|
-
has_many :ai_message_prompts, class_name: RubyConversations.configuration.message_prompt_class, dependent: :destroy
|
9
|
-
has_many :prompts, through: :ai_message_prompts, class_name: RubyConversations.configuration.prompt_class
|
10
|
-
|
11
|
-
# Validations
|
12
|
-
validates :llm, presence: true
|
13
|
-
validates :request, presence: true
|
14
|
-
|
15
|
-
# Scopes
|
16
|
-
scope :ordered, -> { order(created_at: :desc) }
|
17
|
-
scope :with_tool, ->(tool) { where(tool: tool) }
|
18
|
-
scope :with_prompts, -> { includes(:ai_message_prompts) }
|
19
|
-
|
20
|
-
def prompt_inputs
|
21
|
-
ai_message_prompts.includes(:ai_message_inputs).flat_map(&:ai_message_inputs)
|
22
|
-
end
|
23
|
-
|
24
|
-
def tool?
|
25
|
-
tool.present?
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# Represents an input provided for a specific prompt placeholder within an AI message.
|
5
|
-
class AiMessageInput < ActiveRecord::Base
|
6
|
-
# Associations
|
7
|
-
belongs_to :ai_message_prompt
|
8
|
-
|
9
|
-
# Validations
|
10
|
-
validates :placeholder_name, presence: true
|
11
|
-
validate :value_not_nil
|
12
|
-
|
13
|
-
# Scopes
|
14
|
-
scope :ordered, -> { order(:placeholder_name) }
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def value_not_nil
|
19
|
-
errors.add(:value, "can't be blank") if value.nil?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# Represents the association between an AI message and a specific version of a Prompt.
|
5
|
-
class AiMessagePrompt < ActiveRecord::Base
|
6
|
-
# Associations
|
7
|
-
belongs_to :ai_message
|
8
|
-
belongs_to :prompt, optional: true
|
9
|
-
belongs_to :prompt_version, optional: true
|
10
|
-
has_many :ai_message_inputs, class_name: RubyConversations.configuration.message_input_class, dependent: :destroy
|
11
|
-
|
12
|
-
# Validations
|
13
|
-
validate :prompt_or_inline_data_present
|
14
|
-
|
15
|
-
# Scopes
|
16
|
-
scope :with_inputs, -> { includes(:ai_message_inputs) }
|
17
|
-
scope :for_prompt, ->(prompt) { where(prompt: prompt) }
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def prompt_or_inline_data_present
|
22
|
-
return if prompt_id.present? || prompt_version_id.present?
|
23
|
-
return if name.present? && role.present? && draft.present?
|
24
|
-
|
25
|
-
errors.add(:base, 'Must have either a prompt/version reference or inline prompt data (name, role, draft)')
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyConversations
|
4
|
-
# Represents a specific version of a Prompt template.
|
5
|
-
class PromptVersion < ActiveRecord::Base
|
6
|
-
# Associations
|
7
|
-
belongs_to :prompt
|
8
|
-
|
9
|
-
# Validations
|
10
|
-
validates :message, presence: true
|
11
|
-
validates :temperature, numericality: { greater_than_or_equal_to: 0.0 }, allow_nil: true
|
12
|
-
|
13
|
-
# Scopes
|
14
|
-
scope :ordered, -> { order(created_at: :desc) }
|
15
|
-
end
|
16
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
require 'rails/generators/migration'
|
5
|
-
|
6
|
-
module RubyConversations
|
7
|
-
module Generators
|
8
|
-
# Generates the necessary files for installing the ruby_conversations engine.
|
9
|
-
class InstallGenerator < Rails::Generators::Base
|
10
|
-
include Rails::Generators::Migration
|
11
|
-
|
12
|
-
source_root File.expand_path('templates', __dir__)
|
13
|
-
|
14
|
-
def self.next_migration_number(path)
|
15
|
-
next_migration_number = current_migration_number(path) + 1
|
16
|
-
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
17
|
-
end
|
18
|
-
|
19
|
-
def copy_migrations
|
20
|
-
migration_template_details.each do |file, description|
|
21
|
-
migration_template(
|
22
|
-
"migrations/#{file}",
|
23
|
-
"db/migrate/#{file.sub('.erb', '')}",
|
24
|
-
migration_version: migration_version,
|
25
|
-
migration_description: description
|
26
|
-
)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_initializer
|
31
|
-
template 'initializer.rb.erb', 'config/initializers/ruby_conversations.rb'
|
32
|
-
end
|
33
|
-
|
34
|
-
def mount_engine
|
35
|
-
route "mount RubyConversations::Engine => '/ai', as: 'ruby_conversations'"
|
36
|
-
end
|
37
|
-
|
38
|
-
def display_post_install_message
|
39
|
-
readme 'README.md'
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def migration_version
|
45
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
46
|
-
end
|
47
|
-
|
48
|
-
def migration_template_details
|
49
|
-
{
|
50
|
-
'create_prompts.rb.erb' => 'Create prompts table',
|
51
|
-
'create_prompt_versions.rb.erb' => 'Create prompt versions table',
|
52
|
-
'create_ai_conversations.rb.erb' => 'Create conversations table',
|
53
|
-
'create_ai_messages.rb.erb' => 'Create messages table',
|
54
|
-
'create_ai_message_prompts.rb.erb' => 'Create message prompts table',
|
55
|
-
'create_ai_message_inputs.rb.erb' => 'Create message inputs table'
|
56
|
-
}
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# RubyConversations Installation
|
2
|
-
|
3
|
-
The gem has been installed! Here are the next steps:
|
4
|
-
|
5
|
-
1. Run the migrations:
|
6
|
-
```bash
|
7
|
-
bin/rails db:migrate
|
8
|
-
```
|
9
|
-
|
10
|
-
2. Configure the gem in `config/initializers/ruby_conversations.rb`
|
11
|
-
- Set your storage mode (:local or :remote)
|
12
|
-
- If using remote mode, set your API URL and JWT secret
|
13
|
-
- Customize model names if needed
|
14
|
-
|
15
|
-
3. For remote mode, ensure your API endpoint is accessible and JWT authentication is configured.
|
16
|
-
|
17
|
-
4. Start using conversations in your models:
|
18
|
-
```ruby
|
19
|
-
class MyModel < ApplicationRecord
|
20
|
-
has_one :conversation, as: :conversationable, class_name: 'AiConversation'
|
21
|
-
end
|
22
|
-
|
23
|
-
# Create a conversation
|
24
|
-
conversation = my_model.create_conversation!
|
25
|
-
|
26
|
-
# Ask a question using a prompt
|
27
|
-
conversation.ask("explain_code", inputs: { code: "def hello; end" })
|
28
|
-
```
|
29
|
-
|
30
|
-
5. The engine is mounted at `/ai`. You can change this in `config/routes.rb` if needed.
|
31
|
-
|
32
|
-
## What's Next?
|
33
|
-
|
34
|
-
- Check out the documentation at https://github.com/yourusername/ruby_conversations
|
35
|
-
- Review the example app at https://github.com/yourusername/ruby_conversations_example
|
36
|
-
- Join our Discord community at https://discord.gg/ruby_conversations
|
37
|
-
|
38
|
-
## Need Help?
|
39
|
-
|
40
|
-
- Open an issue on GitHub
|
41
|
-
- Check our FAQ at https://github.com/yourusername/ruby_conversations/wiki/FAQ
|
42
|
-
- Email support at support@example.com
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RubyConversations.configure do |config|
|
4
|
-
# Storage mode: :local or :remote
|
5
|
-
config.storage_mode = :local
|
6
|
-
|
7
|
-
# Remote API settings (only needed for remote mode)
|
8
|
-
# config.api_url = ENV['RUBY_CONVERSATIONS_API_URL']
|
9
|
-
# config.jwt_secret = ENV['RUBY_CONVERSATIONS_JWT_SECRET']
|
10
|
-
|
11
|
-
# Default LLM settings
|
12
|
-
config.default_llm_model = 'gpt-4'
|
13
|
-
|
14
|
-
# Customize model behaviors
|
15
|
-
config.conversation_class = 'AiConversation'
|
16
|
-
config.message_class = 'AiMessage'
|
17
|
-
config.prompt_class = 'Prompt'
|
18
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_conversations.rb.erb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateAiConversations < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :ai_conversations do |t|
|
4
|
-
t.string :conversationable_type
|
5
|
-
t.bigint :conversationable_id
|
6
|
-
|
7
|
-
t.timestamps
|
8
|
-
end
|
9
|
-
|
10
|
-
add_index :ai_conversations, [:conversationable_type, :conversationable_id],
|
11
|
-
name: 'index_ai_conversations_on_conversationable'
|
12
|
-
end
|
13
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_inputs.rb.erb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateAiMessageInputs < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :ai_message_inputs do |t|
|
4
|
-
t.string :placeholder_name
|
5
|
-
t.text :value
|
6
|
-
t.bigint :ai_message_prompt_id, null: false
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
|
11
|
-
add_index :ai_message_inputs, :ai_message_prompt_id
|
12
|
-
end
|
13
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_message_prompts.rb.erb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateAiMessagePrompts < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :ai_message_prompts do |t|
|
4
|
-
t.bigint :ai_message_id, null: false
|
5
|
-
t.bigint :prompt_id
|
6
|
-
t.text :draft
|
7
|
-
t.bigint :prompt_version_id
|
8
|
-
t.string :name
|
9
|
-
t.string :role
|
10
|
-
|
11
|
-
t.timestamps
|
12
|
-
end
|
13
|
-
|
14
|
-
add_index :ai_message_prompts, :ai_message_id
|
15
|
-
add_index :ai_message_prompts, :prompt_id
|
16
|
-
add_index :ai_message_prompts, :prompt_version_id
|
17
|
-
end
|
18
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_messages.rb.erb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class CreateAiMessages < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :ai_messages do |t|
|
4
|
-
t.bigint :ai_conversation_id, null: false
|
5
|
-
t.jsonb :request
|
6
|
-
t.text :response
|
7
|
-
t.string :model_identifier
|
8
|
-
t.string :tool
|
9
|
-
t.text :change_description
|
10
|
-
t.string :llm, default: 'us.anthropic.claude-3-7-sonnet-20250219-v1:0', null: false
|
11
|
-
|
12
|
-
t.timestamps
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :ai_messages, :ai_conversation_id
|
16
|
-
add_index :ai_messages, :llm
|
17
|
-
end
|
18
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_ai_tool_calls.rb.erb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
class CreateAiToolCalls < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :ai_tool_calls do |t|
|
4
|
-
t.references :ai_message, null: false, foreign_key: true
|
5
|
-
t.string :name, null: false
|
6
|
-
t.jsonb :arguments, null: false, default: {}
|
7
|
-
t.text :result
|
8
|
-
t.text :error
|
9
|
-
|
10
|
-
t.timestamps
|
11
|
-
end
|
12
|
-
|
13
|
-
add_index :ai_tool_calls, :name
|
14
|
-
end
|
15
|
-
end
|
data/lib/generators/ruby_conversations/install/templates/migrations/create_prompt_versions.rb.erb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
class CreatePromptVersions < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :prompt_versions do |t|
|
4
|
-
t.bigint :prompt_id, null: false
|
5
|
-
t.text :message
|
6
|
-
t.float :temperature
|
7
|
-
t.text :change_description
|
8
|
-
|
9
|
-
t.timestamps
|
10
|
-
end
|
11
|
-
|
12
|
-
add_index :prompt_versions, :prompt_id
|
13
|
-
end
|
14
|
-
end
|