GithubHelp home page GithubHelp logo

Comments (16)

Torantulino avatar Torantulino commented on July 1, 2024 2

You have to rename the file to just .env 😊

from auto-gpt.

iskandarzhilmi avatar iskandarzhilmi commented on July 1, 2024 2

I've found the solution: open the folder in Visual Studio Code and rename the .env.template file from there. It remains as .env.template when I first opened it in VS Code. It seems that Finder on Mac doesn't actually change the file name.

image

from auto-gpt.

Cosmingld avatar Cosmingld commented on July 1, 2024 1

from auto-gpt.

Torantulino avatar Torantulino commented on July 1, 2024 1

image

Make sure you copy the entre key in, sometimes they have a "-" in them that can make you miss a section of it when highlighting.

from auto-gpt.

Veylkh avatar Veylkh commented on July 1, 2024 1

I have a .env file in the root directory, with python-dotenv library installed, with the full key "sk-XYZ..." without quotes, but I'm still getting this:

Traceback (most recent call last):
  File "C:\Users\PC\Auto-GPT\scripts\main.py", line 286, in <module>
    assistant_reply = chat.chat_with_ai(
  File "C:\Users\PC\Auto-GPT\scripts\chat.py", line 110, in chat_with_ai
    assistant_reply = create_chat_completion(
  File "C:\Users\PC\Auto-GPT\scripts\llm_utils.py", line 9, in create_chat_completion
    response = openai.ChatCompletion.create(
  File "C:\Python310\lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create
    return super().create(*args, **kwargs)
  File "C:\Python310\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create
    response, _, api_key = requestor.request(
  File "C:\Python310\lib\site-packages\openai\api_requestor.py", line 226, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "C:\Python310\lib\site-packages\openai\api_requestor.py", line 619, in _interpret_response
    self._interpret_response_line(
  File "C:\Python310\lib\site-packages\openai\api_requestor.py", line 682, in _interpret_response_line
    raise self.handle_error_response(
openai.error.AuthenticationError: Incorrect API key provided: null. You can find your API key at https://platform.openai.com/account/api-keys.

from auto-gpt.

Veylkh avatar Veylkh commented on July 1, 2024

You have to rename the file to just .env 😊

Might still not work properly

I added some print() to debug and I'm getting this:

PS C:\Users\PC\Auto-GPT> python scripts/main.py continuous-mode
env_path: .env
.env file exists: True
OPENAI_API_KEY: null
Config openai_api_key: null

from auto-gpt.

Torantulino avatar Torantulino commented on July 1, 2024

So you have a file called .env that contains the keys? πŸ€”

from auto-gpt.

Veylkh avatar Veylkh commented on July 1, 2024

So you have a file called .env that contains the keys? πŸ€”

Yes, tried having it in both root and /scripts directory, with or without quotations marks around the key, to no avail

Does it works on your end?

from auto-gpt.

Torantulino avatar Torantulino commented on July 1, 2024

Yep, must be in the root directory and no quotes.

from auto-gpt.

Torantulino avatar Torantulino commented on July 1, 2024

I'm unable to reproduce this.. Sorry!
Is anyone else experiencing this?

Try cloning a fresh copy and setup the .env file again.

Are you using a virtual environment?

from auto-gpt.

Veylkh avatar Veylkh commented on July 1, 2024

key
(trying unmodified config.py made no change to output)

from auto-gpt.

Veylkh avatar Veylkh commented on July 1, 2024

I'm unable to reproduce this.. Sorry! Is anyone else experiencing this?

Try cloning a fresh copy and setup the .env file again.

Are you using a virtual environment?

No venv and on windows 11 22H2
Python 3.10.5 (tags/v3.10.5:f377153, Jun 6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32

What about you?

from auto-gpt.

jmanhype avatar jmanhype commented on July 1, 2024

Name: NextJS-13-Developer
Role: You are a skilled and experienced developer with a strong background in web development and experience in building e-commerce sites using Next.js 13. You have an eye for design and are able to change the style and layout of the site as needed to meet the client's needs. You have excellent communication skills and are able to ask questions when needed to ensure that the project is completed to the highest standard.
Goals: ['Increase net worth', 'Grow Twitter Account', 'Develop and manage multiple businesses autonomously']
Continue (y/n): y
Traceback (most recent call last):
File "C:\Users\strau\Downloads\Auto-GPT\scripts\main.py", line 279, in
assistant_reply = chat.chat_with_ai(
^^^^^^^^^^^^^^^^^^
File "C:\Users\strau\Downloads\Auto-GPT\scripts\chat.py", line 110, in chat_with_ai
assistant_reply = create_chat_completion(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\strau\Downloads\Auto-GPT\scripts\llm_utils.py", line 9, in create_chat_completion
response = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create
return super().create(*args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\openai\api_requestor.py", line 226, in request
resp, got_stream = self._interpret_response(result, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\openai\api_requestor.py", line 619, in _interpret_response
self._interpret_response_line(
File "C:\Python311\Lib\site-packages\openai\api_requestor.py", line 682, in _interpret_response_line
raise self.handle_error_response(
openai.error.AuthenticationError: Incorrect API key provided: <sk-JW3R
***************************************Caq>. You can find your API key at https://platform.openai.com/account/api-keys.
PS C:\Users\strau\Downloads\Auto-GPT>

still broke Ive done everything you all spoke about to no avail HELP

from auto-gpt.

uuta avatar uuta commented on July 1, 2024

Hey, I just found a solution.

https://github.com/Torantulino/Auto-GPT/blob/3f106963a8b461a52ec1d9acb3a3273cac3ad6d7/scripts/config.py#L32-L37

As you can see, python scripts use os.getenv that allows you to retrieve the value of an environment variable. So even if you set OPENAI_API_KEY to .env, it's impossible to retrieve it when the same key is registered as an environment variable.

First, check your value in a console.

$ python
>>> import os
>>> api_key = os.getenv("OPENAI_API_KEY")
>>> print("OPENAI_API_KEY:", api_key)
OPENAI_API_KEY: <your API key>

If the value is different from the value in the .env file, there might be a high possibility that an environment variable has already been set.

$ printenv
...
OPENAI_API_KEY=<your API key>

So by unsetting the value in OPENAI_API_KEY, the value of the .env file becomes available temporarily.

$ unset OPENAI_API_KEY

However, it is probably due to the fact that the environment variable values are fixed in the shell settings, so the best way is to update the value to the correct one. In my case, I used the wrong value that had been set up in ~/.zshrc.

// .zshrc
source "$HOME/.openai_key.zsh"

// .openai_key.zsh
export OPENAI_API_KEY=<wrong key>

from auto-gpt.

toto83fr avatar toto83fr commented on July 1, 2024

Hey, I just found a solution.

https://github.com/Torantulino/Auto-GPT/blob/3f106963a8b461a52ec1d9acb3a3273cac3ad6d7/scripts/config.py#L32-L37

As you can see, python scripts use os.getenv that allows you to retrieve the value of an environment variable. So even if you set OPENAI_API_KEY to .env, it's impossible to retrieve it when the same key is registered as an environment variable.

First, check your value in a console.

$ python
>>> import os
>>> api_key = os.getenv("OPENAI_API_KEY")
>>> print("OPENAI_API_KEY:", api_key)
OPENAI_API_KEY: <your API key>

If the value is different from the value in the .env file, there might be a high possibility that an environment variable has already been set.

$ printenv
...
OPENAI_API_KEY=<your API key>

So by unsetting the value in OPENAI_API_KEY, the value of the .env file becomes available temporarily.

$ unset OPENAI_API_KEY

However, it is probably due to the fact that the environment variable values are fixed in the shell settings, so the best way is to update the value to the correct one. In my case, I used the wrong value that had been set up in ~/.zshrc.

// .zshrc
source "$HOME/.openai_key.zsh"

// .openai_key.zsh
export OPENAI_API_KEY=<wrong key>

Which code should I type to fix the issue?

from auto-gpt.

uuta avatar uuta commented on July 1, 2024

@toto83fr

Make sure that there's the value of OPENAI_API_KEY between .env file under the Auto-GPT directory and environment variables. Run the following command in your shell.

$ printenv
...
OPENAI_API_KEY=<your API key>

Remember the above key. If the different variable in OPENAI_API_KEY is set as an environment variable, you have to consider unsetting or changing it.

// temporary solution
$ unset OPENAI_API_KEY

The way of changing an environment variable depends on your environment, so I can't propose you a proper answer.

from auto-gpt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.