gptscript icon indicating copy to clipboard operation
gptscript copied to clipboard

Provide better error message when required api key related environment variables are not present for the selected model.

Open sangee2004 opened this issue 10 months ago • 1 comments

gptscript version - v0.0.0-dev-941240c5-dirty

Steps to reproduce the problem:

  1. Do not have ANTHROPIC_API_KEY set.
  2. Try to use any claude model like gptscript --cache=false --default-model='claude-3-opus-20240229 from github.com/gptscript-ai/claude3-openai-shim' examples/bob.gpt
  3. We see a 500 Internal Server Error with log stack trace with following last few lines .
 raise TypeError(
TypeError: "Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted"
2024/03/27 16:23:13 error, status code: 500, message: invalid character 'I' looking for beginning of value

Can we provide a error message stating that ANTHROPIC_API_KEY has be set in this, before even attempting to do the chat completion calls ?

sangee2004 avatar Mar 28 '24 00:03 sangee2004

With latest build - gptscript version v0.0.0-dev-5c6ff70d-dirty , I dont see even the error message i see before

I just see the following errors - status code: 500, message: Internal Server Error which gives no indication of what the error is:

gptscript --cache=false --default-model='claude-3-opus-20240229  from github.com/gptscript-ai/claude3-openai-shim' examples/bob.gpt
11:46:31 WARNING: Changing the default model can have unknown behavior for existing tools. Use the model field per tool instead.
11:46:31 started  [main]
11:46:31 started  [main]
11:46:31 launched [anthropic model provider][https://raw.githubusercontent.com/gptscript-ai/claude3-openai-shim/c53ba81de62e824abeede8457c84d4f79c32e6c4/tool.gpt:1] port [10861] [/usr/bin/env python3 /Users/sangeethahariharan/Library/Caches/gptscript/repos/c53ba81de62e824abeede8457c84d4f79c32e6c4/python3.12/main.py]
11:46:32 ended    [main]
11:46:32 sent     [main]
         content  [1] content | Waiting for model response...2024/04/03 11:46:32 error, status code: 500, message: Internal Server Error

When using --debug option I see these errors:

    raise TypeError(
TypeError: "Could not resolve authentication method. Expected either api_key or auth_token to be set. Or for one of the `X-Api-Key` or `Authorization` headers to be explicitly omitted"
{
  "err": "error, status code: 500, message: Internal Server Error",
  "level": "debug",
  "logger": "/pkg/monitor",
  "msg": "Run stopped",
  "output": "",
  "runID": "1",
  "time": "2024-04-03T11:50:38-07:00"
}
2024/04/03 11:50:38 error, status code: 500, message: Internal Server Error

sangee2004 avatar Apr 03 '24 18:04 sangee2004

We have done a bunch of work towards this end, so we should have better messages now when the key is unset or invalid.

drpebcak avatar Jun 28 '24 22:06 drpebcak