Module: PlaypathRails::RAG

Defined in:
lib/playpath_rails/rag.rb

Overview

Helper module for RAG (Retrieval-Augmented Generation) functionality

Class Method Summary collapse

Class Method Details

.ask(message) ⇒ String

Send a simple message without conversation history

Parameters:

  • message (String)

    The user’s question or message

Returns:

  • (String)

    The AI-generated response



18
19
20
21
# File 'lib/playpath_rails/rag.rb', line 18

def ask(message)
  response = chat(message: message)
  response['reply']
end

.build_history(*messages) ⇒ Array

Build a conversation history array from alternating user/assistant messages

Parameters:

  • messages (Array)

    Array of message strings, alternating user/assistant

Returns:

  • (Array)

    Properly formatted history array



26
27
28
29
30
31
32
33
# File 'lib/playpath_rails/rag.rb', line 26

def build_history(*messages)
  history = []
  messages.each_with_index do |message, index|
    role = index.even? ? 'user' : 'assistant'
    history << { 'role' => role, 'text' => message }
  end
  history
end

.chat(message:, history: []) ⇒ Hash

Send a message to the RAG assistant

Parameters:

  • message (String)

    The user’s question or message

  • history (Array) (defaults to: [])

    Optional array of previous conversation messages

Returns:

  • (Hash)

    Response containing reply, usage, and limit information



11
12
13
# File 'lib/playpath_rails/rag.rb', line 11

def chat(message:, history: [])
  PlaypathRails.client.chat(message: message, history: history)
end