railsjazz / ask_chatgpt

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

IRB.CurrentContext is nil #6

Closed timscott closed 1 year ago

timscott commented 1 year ago

Getting this error: undefined method 'main' for nil:NilClass here.

igorkasyanchuk commented 1 year ago

@timscott please provide steps to reproduce, in which context, maybe screenshot what you were doing.

timscott commented 1 year ago

This is why: gem 'pry-rails'. I removed it, and that error went away. I assume that would be a new feature to support pry based console.

Now it works, but no matter what command I get the same output:

irb(main):010:0> gpt.unit_test(User)

-
=> nil
igorkasyanchuk commented 1 year ago

strange, can you try to clone this repo and open test/dummy app

then try to add some gems from your Gemfile to it and see when it will break. I assume the "inspect" is not executed? Or it's something else.

also do you have API key in the initializer/env?

igorkasyanchuk commented 1 year ago

@timscott try now, ask_chatgpt-0.3.1.gem

igorkasyanchuk commented 1 year ago

PS: #7 fixed here

timscott commented 1 year ago

It works with pry now, but I'm still getting no results.

[5] pry(main)> gpt.improve('User.full_name')
|

=>
[6] pry(main)> gpt.explain Events::Item
/

=>
[7] pry(main)> gpt.ask('how to read a text file')
|

=>
igorkasyanchuk commented 1 year ago

Please share your gemfile

timscott commented 1 year ago

https://gist.github.com/timscott/29216399ba3f1f299460d41693c5d9bf

igorkasyanchuk commented 1 year ago

looks like with your gemfile it works (I commented some CSS/JS related gems because dummy app doesn't support them), and it works. I first thought problem might be because of "hirb" or "awesome_print" but looks like it works

can you do the following

  1. clone this repo
  2. connect it in your app using gem "ask_chatgpt", path: '../ask_chatgpt'
  3. open lib/ask_chatgpt/executor.rb and add binding.pry in either call_async or call_sync and check the response
timscott commented 1 year ago

When it's in call_async, I get an error:

[1] pry(main)> gpt.ask('how to read a text file')
|ERROR: Pry started inside Pry.
This can happen if you have a binding.pry inside a #to_s or #inspect function.
|

=>

When it's in call_sync, it's the same empty result.

[1] pry(main)> gpt.ask('how to read a text file')
/

=>

I don't think the empty result is related to pry. When I remove gem 'pry-rails' I get this:

irb(main):001:0> gpt.ask('how to read a text file')
/

=> nil
igorkasyanchuk commented 1 year ago

try to use "puts" and just output what you receive. a very basic way to debug things, but probably the only one possible here.

Also maybe you can enable debug mode. With gpt.debug! Also try to switch to sync mode gpt.sync! (and call call_sync)

finally I'm ready to jump on the call and if you can share screen we can try to fix it together, just find me in the skype: igorkasyanchuk

timscott commented 1 year ago

Okay, now we're getting somewhere. After I ran both gpt.debug! and gpt.sync! I got this:

irb(main):005:0> gpt.ask('how to read a text file')
{:model=>"gpt-3.5-turbo",
 :temperature=>0.1,
 :messages=>
  [{:role=>"user",
    :content=>
     "I have a Ruby on Rails Application, Rails Version 6.1.7, Ruby Version: 3.1.2, Database: postgresql"},
   {:role=>"user", :content=>"how to read a text file"}]}
\{"error"=>
  {"message"=>"You exceeded your current quota, please check your plan and billing details.",
   "type"=>"insufficient_quota",
   "param"=>nil,
   "code"=>nil}}
\
You exceeded your current quota, please check your plan and billing details.
=> nil

Now, when I use ChatGPT in desktop or web (https://chat.openai.com/), it works. However, when I try from https://platform.openai.com/playground, it says I'm over my rate limit. Same account. Not sure how to square that.

Obviously, it's not your problem, except you should probably show me the error without debug or sync on.

igorkasyanchuk commented 1 year ago

since you have this error can you debug and show error message, basically code is present for sync

      if response["error"]
        puts(response["error"]["message"])
      else

and for async maybe something similar should be added.

Also, as for the limits - chat.openai.com works differently, API has its own rate limits: https://platform.openai.com/docs/guides/rate-limits/overview

But I think 3 calls per minute you should have anyway. So it looks strange. Maybe from your IP you have many other developers who are calling service?