Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get started #132

Closed
KronosTheLate opened this issue Apr 12, 2024 · 5 comments · Fixed by #135
Closed

Unable to get started #132

KronosTheLate opened this issue Apr 12, 2024 · 5 comments · Fixed by #135

Comments

@KronosTheLate
Copy link
Contributor

Following the getting started page, I have done the following:

  1. Add my Open AI API key to the global ENV dictionary in my startup.jl
  2. Install PromtingTools
  3. Run ai"Hello!"

This results in the following error:

julia> ai"Hello!"
ERROR: ArgumentError: api_key cannot be empty
Stacktrace:
  [1] auth_header(::OpenAI.OpenAIProvider, api_key::String)
    @ OpenAI ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:40
  [2] _request(api::String, provider::OpenAI.OpenAIProvider, api_key::String; method::String, query::Nothing, http_kwargs::@NamedTuple{…}, streamcallback::Nothing, additional_headers::Vector{…}, kwargs::@Kwargs{…})
    @ OpenAI ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:159
  [3] _request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:141 [inlined]
  [4] #openai_request#14
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:205 [inlined]
  [5] openai_request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:198 [inlined]
  [6] #create_chat#19
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:368 [inlined]
  [7] create_chat
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:362 [inlined]
  [8] #create_chat#162
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:86 [inlined]
  [9] create_chat
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:81 [inlined]
 [10] macro expansion
    @ ./timing.jl:395 [inlined]
 [11] aigenerate(prompt_schema::PromptingTools.OpenAISchema, prompt::String; verbose::Bool, api_key::String, model::String, return_all::Bool, dry_run::Bool, conversation::Vector{…}, http_kwargs::@NamedTuple{…}, api_kwargs::@NamedTuple{}, kwargs::@Kwargs{})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:495
 [12] aigenerate(prompt::String; model::String, kwargs::@Kwargs{return_all::Bool})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_interface.jl:297
 [13] macro expansion
    @ ~/.julia/packages/PromptingTools/wSKVR/src/macros.jl:39 [inlined]
 [14] top-level scope
    @ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.

Despite the fact that the environment variable is set:

julia> haskey(ENV, "OPENAI_API_KEY")
true

Have I done something wrong, or should it be working at this point? I could use some help figuring out what I am missing to get things working...

Versions:

Julia Version 1.10.2
 [670122d1] PromptingTools v0.19.0
@svilupp
Copy link
Owner

svilupp commented Apr 12, 2024

Would you mind starting a temp environment and running it again?
Make sure that you can see the ENV["OPENAI_API_KEY"] and that there is no typo, before you import the package.

That's the most common mistake.

An easy check if the package loaded it correctly is if it shows up in PromptingTools.OPENAI_API_KEY.

There was a bug in past versions where people started the package before they set the ENV and Julia was for whatever reason precompiling the get(ENV..) call as well, so the only solution was to get rid of the cache (precompile again, upgrade version, manually delete the cache) - see the FAQ note.

But nowadays I split the get(ENV,..) in two steps to prevent Julia from inlining/precompiling it. No one has reported the issue since that fix.

@KronosTheLate
Copy link
Contributor Author

I am not getting a different error message, which states that I have exceeded my current quota. I assumed that since I can use ChatGPT in the browser, I could also make requests via this interface for free. Is that wrong?

Full stacktrace of new error
julia> ai"Hello!"
ERROR: HTTP.Exceptions.StatusError(429, "POST", "/v1/chat/completions", HTTP.Messages.Response:
"""
HTTP/1.1 429 Too Many Requests
Date: Mon, 15 Apr 2024 06:44:21 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 337
Connection: keep-alive
vary: Origin
x-request-id: req_47fc080729878fd0ef899db83bb08b55
strict-transport-security: max-age=15724800; includeSubDomains
CF-Cache-Status: DYNAMIC
Set-Cookie: ******
Set-Cookie: ******
Server: cloudflare
CF-RAY: 8749f76edc4aabd5-CPH
alt-svc: h3=":443"; ma=86400

{
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.",
        "type": "insufficient_quota",
        "param": null,
        "code": "insufficient_quota"
    }
}
""")
Stacktrace:
  [1] (::HTTP.ConnectionRequest.var"#connections#4"{…})(req::HTTP.Messages.Request; proxy::Nothing, socket_type::Type, socket_type_tls::Type, readtimeout::Int64, connect_timeout::Int64, logerrors::Bool, logtag::Nothing, kw::@Kwargs{…})
    @ HTTP.ConnectionRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/ConnectionRequest.jl:141
  [2] (::Base.var"#96#98"{…})(args::HTTP.Messages.Request; kwargs::@Kwargs{…})
    @ Base ./error.jl:308
  [3] (::HTTP.RetryRequest.var"#manageretries#3"{…})(req::HTTP.Messages.Request; retry::Bool, retries::Int64, retry_delays::ExponentialBackOff, retry_check::Function, retry_non_idempotent::Bool, kw::@Kwargs{…})
    @ HTTP.RetryRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RetryRequest.jl:75
  [4] manageretries
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RetryRequest.jl:30 [inlined]
  [5] (::HTTP.CookieRequest.var"#managecookies#4"{…})(req::HTTP.Messages.Request; cookies::Bool, cookiejar::HTTP.Cookies.CookieJar, kw::@Kwargs{…})
    @ HTTP.CookieRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/CookieRequest.jl:42
  [6] managecookies
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/CookieRequest.jl:19 [inlined]
  [7] (::HTTP.HeadersRequest.var"#defaultheaders#2"{…})(req::HTTP.Messages.Request; iofunction::Nothing, decompress::Nothing, basicauth::Bool, detect_content_type::Bool, canonicalize_headers::Bool, kw::@Kwargs{…})
    @ HTTP.HeadersRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/HeadersRequest.jl:71
  [8] defaultheaders
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/HeadersRequest.jl:14 [inlined]
  [9] (::HTTP.RedirectRequest.var"#redirects#3"{…})(req::HTTP.Messages.Request; redirect::Bool, redirect_limit::Int64, redirect_method::Nothing, forwardheaders::Bool, response_stream::Nothing, kw::@Kwargs{…})
    @ HTTP.RedirectRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RedirectRequest.jl:25
 [10] redirects
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RedirectRequest.jl:14 [inlined]
 [11] (::HTTP.MessageRequest.var"#makerequest#3"{…})(method::String, url::URIs.URI, headers::Vector{…}, body::IOBuffer; copyheaders::Bool, response_stream::Nothing, http_version::HTTP.Strings.HTTPVersion, verbose::Int64, kw::@Kwargs{…})
    @ HTTP.MessageRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/MessageRequest.jl:35
 [12] makerequest
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/MessageRequest.jl:24 [inlined]
 [13] request(stack::HTTP.MessageRequest.var"#makerequest#3"{…}, method::String, url::String, h::Vector{…}, b::IOBuffer, q::Vector{…}; headers::Vector{…}, body::IOBuffer, query::Vector{…}, kw::@Kwargs{…})
    @ HTTP ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:457
 [14] #request#20
    @ ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:315 [inlined]
 [15] request (repeats 2 times)
    @ ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:313 [inlined]
 [16] #request_body#3
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:82 [inlined]
 [17] request_body
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:78 [inlined]
 [18] _request(api::String, provider::OpenAI.OpenAIProvider, api_key::String; method::String, query::Nothing, http_kwargs::@NamedTuple{…}, streamcallback::Nothing, additional_headers::Vector{…}, kwargs::@Kwargs{…})
    @ OpenAI ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:162
 [19] _request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:141 [inlined]
 [20] #openai_request#14
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:205 [inlined]
 [21] openai_request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:198 [inlined]
 [22] #create_chat#19
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:368 [inlined]
 [23] create_chat
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:362 [inlined]
 [24] #create_chat#162
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:86 [inlined]
 [25] create_chat
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:81 [inlined]
 [26] macro expansion
    @ ./timing.jl:395 [inlined]
 [27] aigenerate(prompt_schema::PromptingTools.OpenAISchema, prompt::String; verbose::Bool, api_key::String, model::String, return_all::Bool, dry_run::Bool, conversation::Vector{…}, http_kwargs::@NamedTuple{…}, api_kwargs::@NamedTuple{}, kwargs::@Kwargs{})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:495
 [28] aigenerate(prompt::String; model::String, kwargs::@Kwargs{return_all::Bool})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_interface.jl:297
 [29] macro expansion
    @ ~/.julia/packages/PromptingTools/wSKVR/src/macros.jl:39 [inlined]
 [30] top-level scope
    @ REPL[2]:1

caused by: HTTP.Exceptions.StatusError(429, "POST", "/v1/chat/completions", HTTP.Messages.Response:
"""
HTTP/1.1 429 Too Many Requests
Date: Mon, 15 Apr 2024 06:44:21 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 337
Connection: keep-alive
vary: Origin
x-request-id: req_47fc080729878fd0ef899db83bb08b55
strict-transport-security: max-age=15724800; includeSubDomains
CF-Cache-Status: DYNAMIC
Set-Cookie: ******
Set-Cookie: ******
Server: cloudflare
CF-RAY: 8749f76edc4aabd5-CPH
alt-svc: h3=":443"; ma=86400

{
    "error": {
        "message": "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.",
        "type": "insufficient_quota",
        "param": null,
        "code": "insufficient_quota"
    }
}
""")
Stacktrace:
 [1] (::HTTP.ExceptionRequest.var"#exceptions#2"{…})(stream::HTTP.Streams.Stream{…}; status_exception::Bool, timedout::ConcurrentUtilities.TimedOut{…}, logerrors::Bool, logtag::Nothing, kw::@Kwargs{…})
   @ HTTP.ExceptionRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/ExceptionRequest.jl:19
 [2] exceptions
   @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/ExceptionRequest.jl:13 [inlined]
 [3] #2
   @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/TimeoutRequest.jl:22 [inlined]
 [4] macro expansion
   @ ~/.julia/packages/ConcurrentUtilities/J6iMP/src/try_with_timeout.jl:82 [inlined]
 [5] (::ConcurrentUtilities.var"#2#4"{HTTP.Messages.Response, Timer, ConcurrentUtilities.TimedOut{…}, Channel{…}, HTTP.TimeoutRequest.var"#2#5"{…}})()
   @ ConcurrentUtilities ~/.julia/packages/ConcurrentUtilities/J6iMP/src/ConcurrentUtilities.jl:9
Stacktrace:
  [1] try_yieldto(undo::typeof(Base.ensure_rescheduled))
    @ Base ./task.jl:931
  [2] wait()
    @ Base ./task.jl:995
  [3] wait(c::Base.GenericCondition{ReentrantLock}; first::Bool)
    @ Base ./condition.jl:130
  [4] wait
    @ ./condition.jl:125 [inlined]
  [5] take_unbuffered(c::Channel{HTTP.Messages.Response})
    @ Base ./channels.jl:494
  [6] take!
    @ ./channels.jl:471 [inlined]
  [7] try_with_timeout(f::Function, timeout::Int64, ::Type{HTTP.Messages.Response})
    @ ConcurrentUtilities ~/.julia/packages/ConcurrentUtilities/J6iMP/src/try_with_timeout.jl:89
  [8] (::HTTP.TimeoutRequest.var"#timeouts#3"{…})(stream::HTTP.Streams.Stream{…}; readtimeout::Int64, logerrors::Bool, logtag::Nothing, kw::@Kwargs{…})
    @ HTTP.TimeoutRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/TimeoutRequest.jl:21
  [9] (::HTTP.ConnectionRequest.var"#connections#4"{…})(req::HTTP.Messages.Request; proxy::Nothing, socket_type::Type, socket_type_tls::Type, readtimeout::Int64, connect_timeout::Int64, logerrors::Bool, logtag::Nothing, kw::@Kwargs{…})
    @ HTTP.ConnectionRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/ConnectionRequest.jl:119
 [10] (::Base.var"#96#98"{…})(args::HTTP.Messages.Request; kwargs::@Kwargs{…})
    @ Base ./error.jl:308
 [11] (::HTTP.RetryRequest.var"#manageretries#3"{…})(req::HTTP.Messages.Request; retry::Bool, retries::Int64, retry_delays::ExponentialBackOff, retry_check::Function, retry_non_idempotent::Bool, kw::@Kwargs{…})
    @ HTTP.RetryRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RetryRequest.jl:75
 [12] manageretries
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RetryRequest.jl:30 [inlined]
 [13] (::HTTP.CookieRequest.var"#managecookies#4"{…})(req::HTTP.Messages.Request; cookies::Bool, cookiejar::HTTP.Cookies.CookieJar, kw::@Kwargs{…})
    @ HTTP.CookieRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/CookieRequest.jl:42
 [14] managecookies
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/CookieRequest.jl:19 [inlined]
 [15] (::HTTP.HeadersRequest.var"#defaultheaders#2"{…})(req::HTTP.Messages.Request; iofunction::Nothing, decompress::Nothing, basicauth::Bool, detect_content_type::Bool, canonicalize_headers::Bool, kw::@Kwargs{…})
    @ HTTP.HeadersRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/HeadersRequest.jl:71
 [16] defaultheaders
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/HeadersRequest.jl:14 [inlined]
 [17] (::HTTP.RedirectRequest.var"#redirects#3"{…})(req::HTTP.Messages.Request; redirect::Bool, redirect_limit::Int64, redirect_method::Nothing, forwardheaders::Bool, response_stream::Nothing, kw::@Kwargs{…})
    @ HTTP.RedirectRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RedirectRequest.jl:25
 [18] redirects
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/RedirectRequest.jl:14 [inlined]
 [19] (::HTTP.MessageRequest.var"#makerequest#3"{…})(method::String, url::URIs.URI, headers::Vector{…}, body::IOBuffer; copyheaders::Bool, response_stream::Nothing, http_version::HTTP.Strings.HTTPVersion, verbose::Int64, kw::@Kwargs{…})
    @ HTTP.MessageRequest ~/.julia/packages/HTTP/vnQzp/src/clientlayers/MessageRequest.jl:35
 [20] makerequest
    @ ~/.julia/packages/HTTP/vnQzp/src/clientlayers/MessageRequest.jl:24 [inlined]
 [21] request(stack::HTTP.MessageRequest.var"#makerequest#3"{…}, method::String, url::String, h::Vector{…}, b::IOBuffer, q::Vector{…}; headers::Vector{…}, body::IOBuffer, query::Vector{…}, kw::@Kwargs{…})
    @ HTTP ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:457
 [22] #request#20
    @ ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:315 [inlined]
 [23] request (repeats 2 times)
    @ ~/.julia/packages/HTTP/vnQzp/src/HTTP.jl:313 [inlined]
 [24] #request_body#3
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:82 [inlined]
 [25] request_body
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:78 [inlined]
 [26] _request(api::String, provider::OpenAI.OpenAIProvider, api_key::String; method::String, query::Nothing, http_kwargs::@NamedTuple{…}, streamcallback::Nothing, additional_headers::Vector{…}, kwargs::@Kwargs{…})
    @ OpenAI ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:162
 [27] _request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:141 [inlined]
 [28] #openai_request#14
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:205 [inlined]
 [29] openai_request
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:198 [inlined]
 [30] #create_chat#19
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:368 [inlined]
 [31] create_chat
    @ ~/.julia/packages/OpenAI/d65zV/src/OpenAI.jl:362 [inlined]
 [32] #create_chat#162
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:86 [inlined]
 [33] create_chat
    @ ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:81 [inlined]
 [34] macro expansion
    @ ./timing.jl:395 [inlined]
 [35] aigenerate(prompt_schema::PromptingTools.OpenAISchema, prompt::String; verbose::Bool, api_key::String, model::String, return_all::Bool, dry_run::Bool, conversation::Vector{…}, http_kwargs::@NamedTuple{…}, api_kwargs::@NamedTuple{}, kwargs::@Kwargs{})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_openai.jl:495
 [36] aigenerate(prompt::String; model::String, kwargs::@Kwargs{return_all::Bool})
    @ PromptingTools ~/.julia/packages/PromptingTools/wSKVR/src/llm_interface.jl:297
 [37] macro expansion
    @ ~/.julia/packages/PromptingTools/wSKVR/src/macros.jl:39 [inlined]
 [38] top-level scope
    @ REPL[2]:1

@svilupp
Copy link
Owner

svilupp commented Apr 15, 2024

Ah, good! That means that the api key issue is gone. Which of the steps above resolved it for you?

On your current error, it's common for new / non-paying users. It's very similar to this error: https://siml.earth/PromptingTools.jl/dev/frequently_asked_questions#Getting-an-error-%22Rate-limit-exceeded%22-from-OpenAI?

But it's likely because you don't have any prepaid credit in your OpenAI account.

I'd suggest prepaying $5 credit: https://help.openai.com/en/articles/8264644-what-is-prepaid-billing

@KronosTheLate
Copy link
Contributor Author

I can use chat.openai.com/ freely. Are the rules different when accessed through this package? I just assumed that as long as I kept to normal usage and only the free models, I did not have to whip out a credit card...

@KronosTheLate
Copy link
Contributor Author

Looking at the billing information with OpenAI, I can see the following:
image

Which makes it clear that my chatGPT account is not reflected by that information, indicating that the two accounts have separate statuses. That helps explain why I can freely make requests online, but not via the OpenAI API. I do not plan on paying for this when I can freely use the online service.

To keep this confusion from happening again, perhaps the getting started section could mention that you have to pay to get started?

KronosTheLate added a commit to KronosTheLate/ReplGPT.jl that referenced this issue Apr 17, 2024
See svilupp/PromptingTools.jl#132 for a related discussion.

This would hopefully make it clear to people who, like me, expect that because one can use chat.openai.com/ freely, then interacting via the OpenAI API must surely also be free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants