Skip to content
Discussion options

You must be logged in to vote

The trick is to create the user message yourself, so you can add attachments, etc. You will also want to replace chat.ask with chat.complete which manually triggers the assistant response.

In your MessagesController:

def create
  # Create and persist the user message immediately
  user_message = @chat.create_user_message(message_content)

  # Attach files if present
  if attachments.present?
    user_message.attachments.attach(attachments)
  end

  ChatStreamJob.perform_later(@chat.id)
end

And in ChatStreamJob:

class ChatStreamJob < ApplicationJob
  def perform(chat_id)
    chat = Chat.find(chat_id)

    # Process the latest user message
    chat.complete do |chunk|
      # Get the assist…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by the-s-anton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants