Table of Contents

  1. Customizing Controllers
  2. Customizing Models
  3. Customizing Views
  4. Customizing System Prompts
  5. Adding LLM Models

Customizing Controllers

You can override Raif’s controllers by creating your own that inherit from Raif’s base controllers:

class ConversationsController < Raif::ConversationsController
  # Your customizations here
end

class ConversationEntriesController < Raif::ConversationEntriesController
  # Your customizations here
end

Then update the configuration:

Raif.configure do |config|
  config.conversations_controller = "ConversationsController"
  config.conversation_entries_controller = "ConversationEntriesController"
end

Customizing Models

By default, Raif models inherit from ApplicationRecord. You can change this:

Raif.configure do |config|
  config.model_superclass = "CustomRecord"
end

Customizing Views

You can customize Raif’s views by copying them to your application and modifying them. To copy the conversation-related views, run:

rails generate raif:views

This will copy all conversation and conversation entry views to your application in:

  • app/views/raif/conversations/
  • app/views/raif/conversation_entries/

These views will automatically override Raif’s default views. You can customize them to match your application’s look and feel while maintaining the same functionality.

Customizing System Prompts

If you don’t want to override the system prompt entirely in your task/conversation subclasses, you can customize the intro portion of the system prompts for conversations and tasks:

Raif.configure do |config|
  config.conversation_system_prompt_intro = "You are a helpful assistant who specializes in customer support."
  config.task_system_prompt_intro = "You are a helpful assistant who specializes in data analysis."

  # or with a lambda
  config.task_system_prompt_intro = ->(task) { "You are a helpful assistant who specializes in #{task.name}." }
  config.conversation_system_prompt_intro = ->(conversation) { "You are a helpful assistant talking to #{conversation.creator.email}. Today's date is #{Date.today.strftime('%B %d, %Y')}." }
end

Adding LLM Models

You can easily add new LLM models to Raif. The first argument is the provider adapter class to use and the second argument is a hash defining the specifics of the model:

# Register the model in Raif's LLM registry
Raif.register_llm(Raif::Llms::OpenRouter, {
  key: :open_router_gemini_flash_1_5_8b, # a unique key for the model
  api_name: "google/gemini-flash-1.5-8b", # name of the model to be used in API calls - needs to match the provider's API name
  input_token_cost: 0.038 / 1_000_000, # the cost per input token
  output_token_cost: 0.15 / 1_000_000, # the cost per output token
})

# Then use the model
llm = Raif.llm(:open_router_gemini_flash_1_5_8b)
llm.chat(message: "Hello, world!")

# Or set it as the default LLM model in your initializer
Raif.configure do |config|
  config.default_llm_model_key = "open_router_gemini_flash_1_5_8b"
end

Read next: Testing