英文:
Why do I get an openai.error.AuthenticationError when using llama-index despite my key is valid?
问题
以下是翻译好的部分:
我正在使用带有以下代码的llama-index:
import os
from llama_index import VectorStoreIndex, SimpleDirectoryReader
os.environ["OPENAI_API_KEY"] = 'MY_KEY'
documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
这只是一个非常简单的示例。
在执行时,我遇到了以下错误:
[...]
openai.error.AuthenticationError: <empty message>
直接原因是以下异常:
[...]
tenacity.RetryError: RetryError[<Future at 0xffff944b5d50 state=finished raised AuthenticationError>]
似乎是由于无效的API密钥,但实际上并非如此。当直接使用OPEN API时,我可以正常使用它。
您知道发生了什么变化或我做错了什么吗?
谢谢!
英文:
I'm using llama-index with the following code:
import os
from llama_index import VectorStoreIndex, SimpleDirectoryReader
os.environ["OPENAI_API_KEY"] = 'MY_KEY'
documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
Which is a very simple example.
I got the following error when executing it:
[...]
openai.error.AuthenticationError: <empty message>
The above exception was the direct cause of the following exception:
[...]
tenacity.RetryError: RetryError[<Future at 0xffff944b5d50 state=finished raised AuthenticationError>]
Seems to be the API key which is invalid, but it is not. I can use it properly, when using the OPEN API directly.
Do you have any idea on what has changed or what I do wrong?
Thanks!
答案1
得分: 1
只是遇到了相同的错误,我以某种方式解决了它,只需确保在定义 API 密钥之后从库导入,如下所示:
os.environ["OPENAI_API_KEY"] = 'YOUR_API_KEY'
from llama_index import VectorStoreIndex, SimpleDirectoryReader
英文:
Just facing the same error, I resolved it somehow, just make sure you are importing from the lib after you define you api keys like following
os.environ["OPENAI_API_KEY"] = 'YOU_API_KEY'
from llama_index import VectorStoreIndex, SimpleDirectoryReader
答案2
得分: 1
"Define this first:
import openai
openai.api_key = 'your_api_key'
Source: https://github.com/jerryjliu/llama_index/issues/617#issuecomment-1601547159"
英文:
Define this first:
import openai
openai.api_key = "your_api_key"
Source: https://github.com/jerryjliu/llama_index/issues/617#issuecomment-1601547159
答案3
得分: 0
我解决它的方式如下:
import openai
openai.api_key = '我的密钥'
os.environ['OPENAI_API_KEY'] = '我的密钥'
英文:
I solved it like this
import openai
openai.api_key = <'MY_KEY'>
os.environ['OPENAI_API_KEY'] = <'MY_KEY'>
答案4
得分: 0
我遇到了完全相同的问题。设置OpenAI密钥也无法解决问题。错误是在调用source_index=VectorStoreIndex.from_documents(source_documents)位于llama_index.embeddings.openai.py文件中触发的。
我怀疑是某个未安装的Python模块导致了这个错误,因为这个错误只在3个安装中的2个中出现。其中一个没有错误,但与其他两个相比,它也安装了非常多的Python模块。其中一个不正常的模块是huggingface,使用了通常的requirements.txt。
英文:
I have exactly the same problem. Setting the openai key does not solve the problem either. The error is triggered by calling source_index=VectorStoreIndex.from_documents(source_documents) in llama_index.embeddings.openai.py .
I suspect that an uninstalled python module is causal, because the error only occurs on 2 out of 3 installations. One works without errors, however, compared to the other two, it also has extremely many Python modules. one of the non-functioning is huggingface with usual requirements.txt
答案5
得分: 0
我遇到了与python的openai==0.27.9包相同的错误。对于完成模型(gpt-3.5-turbo)和图像创建,它运行正常,但对于Whisper,会出现以下错误:openai.error.AuthenticationError: 提供了错误的API密钥。
问题在我将openai包降级到0.27.0之后解决了。
对某些人可能有用。
英文:
I was encountering same error with python’s openai==0.27.9 package. It was working fine for completion models (gpt-3.5-turbo) and image creating, but for Whisper raises: openai.error.AuthenticationError: Incorrect API key provided.
Issue has gone after i downgraded openai package to 0.27.0
Might be useful for somebody
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论