How To Integrate Chatgpt With Rails 7: Step-by-step Tutorial


In this video I will go through making a Ruby on Rails frontend/middle-tier that will talk to OpenAI’s API. All of this will let you mimic what the ChatGPT website does.

This code will:

– Let you create/manage users by hooking in Devise
– Let you create conversations with ChatGPT that are assigned to a user
– Let you save and retrieve these conversations so that they can be continued at any time.

As I have tried to keep this on target I am not doing any error checking, nor am I doing the stuff we don’t specifically need for this (logging out, creating users via UI, etc etc). I leave that as an exercise to the reader!

Timestamps

00:00 Intro
00:50 Create app
02:02 Install devise
03:30 Add seed data
04:00 Add docker
05:00 Add dotenv-rails, .env file
06:40 Update database.yml
09:00 Start the database
10:35 Create chat object, controller, views (scaffolded)
13:20 devise: force account and make better looking
16:20 add ruby-openai
17:15 OpenAI access token
18:50 create views
21:30 work on controllers to create the chat
23:30 turbo_streams
29:20 chat index
31:00 chat view (finally!)
36:20 Talking to OpenAI
43:40 How to continue the conversation
46:30 save the raw response
47:05 fix the sidebar list
48:20 Conclusion – tips for a product

### Source code and notes 🗳
You can download the source code and notes from my Gumroad account: https://philsmy.gumroad.com/l/ovsgkr
This is a ‘pay what you want’ item, meaning you can get it for free. But any payment is really appreciated as it helps me transition to creating great content like this full-time!

### Talk to me!

You can find me on Twitter (https://twitter.com/psmy) where I share insights on Ruby on Rails, discuss my journey with Zonmaster (https://public.zonmaster.com/), and explore various aspects of life.

And guess what? I’ve recently released my first guide, “Getting Started with Ruby on Rails: A Step-by-Step Guide for Beginners” on Gumroad (https://philsmy.gumroad.com/l/yfhoq)! 📚🚀 It’s a ‘Fair Price’ ebook, so you can get it for free, but any payment is greatly appreciated as it helps support my work and future guides. Don’t miss out on this opportunity to level up your web development skills with Rails!

Drop me a note on Twitter or LinkedIn (https://linkedin.com/in/philsmy) if you have any questions or need help with your Rails project. Happy coding! 😊🎉

Some people online just talk – I just do. One of my major SaaS products out there is Zonmaster.com (https://public.zonmaster.com) THE AutoResponder and Customer Management tool for Amazon Sellers. Join over 17,000 other Amazon Sellers and sign up today!

Looking for great hosting? I’ve been using DigitalOcean for 7 years and they have never let me down. Amazing.
Check them out here https://m.do.co/c/f1c6edf8597f and get $100(!!!) free credits towards the cost of servers.

#techEntrepreneur #entrepreneurship #softwareDevelopment


Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.