Skip to content

OpenAI API Key not being passed in to config in openai_tools.py #568

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

Closed
3 tasks done
tylerprogramming opened this issue Dec 4, 2023 · 4 comments · Fixed by #555
Closed
3 tasks done

OpenAI API Key not being passed in to config in openai_tools.py #568

tylerprogramming opened this issue Dec 4, 2023 · 4 comments · Fixed by #555

Comments

@tylerprogramming
Copy link

tylerprogramming commented Dec 4, 2023

The bug:
Hello, I am trying the memgpt/autogen/examples/agent_groupchat.py as I know MemGPT has been updated and I accomodated my code to use create_memgpt_autogen_agent_from_config(...) method now. That is okay, but no matter how I try to set the openai_key value to the api_key I get from platform.openai, it is always set to 'None', which in turn gives me this error:

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.openai.com/v1/chat/completions

I'm not completely sure, but I did try a new API Key, and just in case I made sure I had enough money in billing.

What I tried:

  1. going to my .memgpt/config file on my local computer and adding in there:

openai_key = sk-......

It doesn't seem to take it.

  1. Setting the os.environ["OPENAI_API_KEY"]=sk-.... and didn't work either. I also tried os.environ["openai_key"]=sk-.... and also a no-go.

It seems that through some debugging, when I get to openai_tools.py on the create() method in this code:

return openai_chat_completions_request(
      url=agent_config.model_endpoint,  # https://api.openai.com/v1 -> https://api.openai.com/v1/chat/completions
      api_key=config.openai_key,  # 'sk....'

the api_key is None when it loads the config from the MemGPTConfig.load() method. I hope you can help, maybe it's my memgpt version (I have shown below).

Please describe your setup

  • MemGPT version
    • What is the output of memgpt version? (eg "0.2.4") 0.2.5
  • How did you install memgpt?
    • pip install pymemgpt
  • Describe your setup
    • What's your OS (Windows/MacOS/Linux)? MacOS
    • How are you running memgpt? (cmd.exe/Powershell/Anaconda Shell/Terminal) inside PyCharm with Anaconda3 Interpreter

I didn't try a Local LLM yet as I wanted to make sure the updates on my end worked for GPT-4 first, then I would know I can get Local LLM working.

@cpacker
Copy link
Collaborator

cpacker commented Dec 4, 2023

Hi @tylerprogramming, thank you for the detailed bug report!

You analysis of the code is correct - the way normal MemGPT (no autogen) works is that when you run memgpt configure for the first time (assuming you follow the openai workflow) your openai API key will get written to ~/.memgpt/config. This is then later read in the openai_tools.py directory as you've noticed.

However, with autogen, there's a chance that you won't use ever run memgpt configure, which breaks this assumption and you might get a runtime error like you're seeing.

Good news is that PR #555 should fix this issue.

@cpacker
Copy link
Collaborator

cpacker commented Dec 4, 2023

The fix is in and will be part of the 0.2.6 release we roll out later today. If you'd like to test it immediately you can install from source.

The relevant part of the fix for your issue is here: https://github.com/cpacker/MemGPT/blob/main/memgpt/autogen/memgpt_agent.py#L51-L69

Please let me know if this doesn't work for you.

@tylerprogramming
Copy link
Author

Hey @cpacker thank you for the response! And yes you are correct, I didn't run memgpt configure, I can definitely try that. I see that in another file to do, I missed that. I will test this out later, appreciate it!

@kendu123
Copy link

i got an issue where i already pip install memgpt but~ it kept show
ModuleNotFoundError: No module named 'memgpt'

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.

3 participants