mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 12:05:19 +02:00
Add streaming chat
This commit is contained in:
parent
d1b83541c1
commit
3f9858a67f
9 changed files with 127 additions and 13 deletions
|
@ -3,8 +3,31 @@ class Message < ApplicationRecord
|
|||
|
||||
enum :role, { user: "user", assistant: "assistant", system: "system" }
|
||||
|
||||
validates :content, presence: true
|
||||
validates :content, presence: true, allow_blank: true
|
||||
validates :role, presence: true
|
||||
|
||||
scope :conversation, -> { where(debug_mode: false, role: [ :user, :assistant ]) }
|
||||
scope :ordered, -> { order(created_at: :asc) }
|
||||
|
||||
after_create_commit :broadcast_to_chat
|
||||
after_update_commit :broadcast_update_to_chat
|
||||
|
||||
private
|
||||
def broadcast_to_chat
|
||||
broadcast_append_to(
|
||||
chat,
|
||||
partial: "messages/message",
|
||||
locals: { message: self },
|
||||
target: "chat_#{chat.id}_messages"
|
||||
)
|
||||
end
|
||||
|
||||
def broadcast_update_to_chat
|
||||
broadcast_update_to(
|
||||
chat,
|
||||
partial: "messages/message",
|
||||
locals: { message: self },
|
||||
target: "message_#{self.id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue