railsjazz / ask_chatgpt

AI-Powered Assistant Gem right in your Rails console. Full power of ChatGPT in Rails
https://www.railsjazz.com/
MIT License
253 stars 13 forks source link

irb_show_source Error when running Model specific commands #3

Closed cal1801 closed 1 year ago

cal1801 commented 1 year ago

After adding to my application and launching the rails console I can run commands like:

gpt.ask "how to parse JSON with ruby"

But when trying to get model specific: gpt.rspec_test(Post) I get an error like this:

undefined method `irb_show_source' for main:Object
Did you mean?  irb_source
../.rbenv/versions/2.7.2/gemsets/showingteam/gems/ask_chatgpt-0.2.0/lib/ask_chatgpt/helpers.rb:10:in `block in extract_source'
../.rbenv/versions/2.7.2/gemsets/showingteam/gems/ask_chatgpt-0.2.0/lib/ask_chatgpt/helpers.rb:34:in `block in capture_io'
../.rbenv/versions/2.7.2/gemsets/showingteam/gems/ask_chatgpt-0.2.0/lib/ask_chatgpt/helpers.rb:45:in `_synchronize'
../.rbenv/versions/2.7.2/gemsets/showingteam/gems/ask_chatgpt-0.2.0/lib/ask_chatgpt/helpers.rb:27:in `capture_io'
../.rbenv/versions/2.7.2/gemsets/showingteam/gems/ask_chatgpt-0.2.0/lib/ask_chatgpt/helpers.rb:9:in `extract_source'

Does it need to be a Rails 7/Ruby 3 application?

Integrated into a Rails 6 application: Rails 6.1.3.1 Ruby 2.7.2 ask_chatgpt: 0.2.0

cal1801 commented 1 year ago

I added this also to a Ruby 3/Rails 7 application and it worked successfully.

I would suggest adding Ruby/Rails dependencies to cut down confusion.

Thanks for a great tool though! Great to have it integrated into a console and be able to directly call it on Models instead of having to copy/paste code into chat windows.

igorkasyanchuk commented 1 year ago

Looks like this Ruby version doesn't have this method in IRB.

https://github.com/ruby/ruby/blob/ruby_2_7/lib/irb/cmd/show_source.rb vs https://github.com/ruby/ruby/blob/master/lib/irb/cmd/show_source.rb

If you can find a way how to get a source this issue can be solved. Maybe it can be ported?

igorkasyanchuk commented 1 year ago

btw, Ruby 2.7 End of Life = 31 Mar 2023

cal1801 commented 1 year ago

btw, Ruby 2.7 End of Life = 31 Mar 2023

Yeah, I know...it's working on updating to Ruby 3. :D

Thanks for the reply. Again, great tool for having it all in one place!

igorkasyanchuk commented 1 year ago

I hope that someone will create a PR to solve this issue. For now, I don't have the capacity to do it ((

st0012 commented 1 year ago

@cal1801 I think it's because the version of IRB you're running on doesn't have the command yet. You can try upgrading IRB by adding gem "irb" to your Gemfile.

@igorkasyanchuk Since this project depends on IRB directly, I think it's worth adding irb as a dependency so users can install newer version of it as a gem, instead of using the one that comes with their Ruby.

Also, great job building this project 👍 I'm happy to chat about what IRB can do for chatbot related projects like this.

igorkasyanchuk commented 1 year ago

@st0012 sure, if you want to chat here is my Skype: igorkasyanchuk or https://www.linkedin.com/in/igorkasyanchuk/

igorkasyanchuk commented 1 year ago

@cal1801 released a new version, try, now should work