AbanteAI / rawdog

Generate and auto-execute Python scripts in the cli
Apache License 2.0
1.78k stars 137 forks source link

CLI: No Way to Change OpenAI API KEY Once Set #47

Open jerrytmcl opened 7 months ago

jerrytmcl commented 7 months ago

Bottom Line Upfront

I accidentally set a bad OpenAI API key when running rawdog. The only way to fix this is comment out a line of code in llm_client.py or change the OpenAI API key in the hidden config.yaml file in the home directory. Please add the ability to check the API Key and to change it from the CLI while rawdog is running.

How the error appears in the command line

(base) jerrymclaughlin@MacBook ~ % rawdog
   / \__
  (    @\___   ┳┓┏┓┏ ┓┳┓┏┓┏┓
  /         O  ┣┫┣┫┃┃┃┃┃┃┃┃┓
 /   (_____/   ┛┗┛┗┗┻┛┻┛┗┛┗┛
/_____/   U    Rawdog v0.1.1

What can I do for you? (Ctrl-C to exit)
> test

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

Error:
 {'model': 'gpt-4', 'prompt': 'PROMPT: test', 'response': None, 'cost': None, 'error': "OpenAIException - Error code: 401 - {'error': {'message': 'Incorrect API key provided: export O*************************************************************FZ5v. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}"}
Error: Execution error: OpenAIException - Error code: 401 - {'error': {'message': 'Incorrect API key provided: export O*************************************************************FZ5v. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

What can I do for you? (Ctrl-C to exit)

Steps to reproduce

Install rawdog start rawdog set the API Key to any value that is not a real API key

Checking the API Key

I set a new PATH variable for the OpenAI API key I ran conda deactivate I ran echo $OPEN_AI_KEY The correct API Key was there I ran conda activate base I ran echo $OPEN_AI_KEY The correct API Key was there Still rawdog returned the same error

Fix

I opened llm_client.py I commented out #self.api_key = get_llm_api_key() or os.environ.get("OPENAI_API_KEY") I added a new line self.api_key = os.environ.get("OPENAI_API_KEY") I saved the file

I ran conda activate base I ran rawdog Rawdog prompted me to add an API key I provided a valid API key Rawdog worked

I found .rawdog/config.yaml in my home directory config.yaml had the old, wrong API Key I changed the API key I saved the file

I opened llm_client.py I removed this line self.api_key = os.environ.get("OPENAI_API_KEY") I replaced it with this line self.api_key = get_llm_api_key() or os.environ.get("OPENAI_API_KEY") I saved the file

I ran rawdog rawdog worked right away.

(base) jerrymclaughlin@Macbook ~ % rawdog
   / \__
  (    @\___   ┳┓┏┓┏ ┓┳┓┏┓┏┓
  /         O  ┣┫┣┫┃┃┃┃┃┃┃┃┓
 /   (_____/   ┛┗┛┗┗┻┛┻┛┗┛┗┛
/_____/   U    Rawdog v0.1.1

What can I do for you? (Ctrl-C to exit)
> hello world

Hello, world!

What can I do for you? (Ctrl-C to exit)

Requested change

Please add the ability to check the API Key and to change it from the CLI while rawdog is running.

Thank you @ApophisUSA for helping me to troubleshoot this problem!