RailsGPT

I've been playing around with using ChatGPT to answer my Rails-related questions. But I find that it often runs into problems. I decided to write a custom GPT to avoid them.

RailsGPT
Photo by László Glatz / Unsplash

I've been playing around with using ChatGPT to answer my Rails-related questions. But I find that it often runs into problems. I decided to create a custom GPT to avoid them.

The problems are:

  • ChatGPT often responds in a long tutorial-style format when really all I want is a short response.
  • ChatGPT relies on using tutorials, guides, blog posts. These are second-hand information so they are sometimes outdated, misguided or just incorrect.
  • ChatGPT doesn't have a great grasp of Rails internals. Especially bits that nobody else has written about. This makes it harder to build on lesser-known Rails functionality.

To combat these problems, I've taken the following steps:

  • Prompted GPT to answer questions in the style I like.
  • Upload all the Rails codebase into its "Knowledge", so it can always base its answers off the latest Rails code.

I've pasted the full prompt below if you'd like to have a read.

OpenAI put a limit on the number of files that users can upload to custom GPTs, so I wrote a script that compresses the Rails codebase into a few files. I've pasted the script below. Although, I'm not entirely sure whether I managed to get the GPT to actually reference these files or whether it's just using its existing knowledge of Rails.

Please email me if you have ideas for improving the GPT. And I hope you find this useful!

Here's a link to RailsGPT, the custom GPT for your Rails questions.

# Copy every file from ../rails, recursively, to the current directory.
# Rename the file to just the library it's in.
#
#   /actionpack/lib/action_controller.rb
#
#   to
#
#   actionpack.rb

require 'fileutils'

Dir.glob('../rails/**/*').each do |file|
  next if File.directory?(file)

  # Skip test files
  next if file =~ /_test\.rb$/

  # Skip files that are not ruby
  next unless file =~ /\.rb$/

  # Skip files that are not in the lib directory
  next unless file =~ /\/lib\//

  # Skip fi the file is less than N lines
  next if File.readlines(file).size < 200

  # Append the file to the library name
  # e.g.
  # /rails/actionpack/lib/action_controller.rb
  # goes to
  # actionpack.rb
  library_name = file.split('/')[2]

  File.open(library_name + '.rb', 'a') do |f|
    f.puts "\n\n"
    f.puts "# #{file}"

    f.puts File.read(file)
  end
end

Full Prompt

"RailsGPT" is an expert GPT in Ruby on Rails internals, designed for professionals. Your role extends beyond just answering questions. You should also identify and address potential underlying problems in the user's approach. In complex situations, rather than providing a direct fix, suggest alternative ways to structure programs to prevent the problem from occurring in the first place. Provide relevant Rails internal source code where relevant. Assume high user expertise. When faced with ambiguous queries, seek clarification to offer precise, context-relevant advice. Your expertise should guide users towards solutions that embody the principles and best practices of Ruby on Rails.

Subscribe to Ori Marash

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe