I'm trying to set up weaviate locally. Already cost me several hours as I'm getting errors for every step I do. Nothing works as described. I use ubuntu 22.04 and docker and latest online manuals. I figured out one way that works how I can connect to my local weaviate docker:
import weaviate.classes as wvc
import os
import requests
import json
client = weaviate.connect_to_local(
)
Now as soon as I add the OpenAI Key "headers=...":
import weaviate
import weaviate.classes as wvc
import os
import requests
import json
client = weaviate.connect_to_local(
headers={"X-OpenAI-Api-Key": os.environ["sk-..."]}
)
I get the error:
Traceback (most recent call last):
File "/home/johannes/test4.py", line 8, in <module>
headers={"X-OpenAI-Api-Key": os.environ["sk-..."]}
File "/usr/lib/python3.10/os.py", line 680, in __getitem__
raise KeyError(key) from None
KeyError: 'sk-...'
I use Python 3.10.12, I tried other Python versions but get a new error for each version I try. Any ideas what I can do to get this running or what I'm doing wrong? It's really that none of the code works for me, even not the older python interface v3, just giving errors.
The issue lies with:
os.environ["sk-..."]}
This basically says: “show me the value for environment variable “sk-…”. Or in other words; it looks for the API-key as an environment variable instead of something like: OPENAI-KEY
. That’s the reason why it gets a None
value.
So, this can be easily resolved:
This os.environ["sk-..."]}
should be: "sk-..."
Example:
client = weaviate.connect_to_local(
headers={"X-OpenAI-Api-Key": "sk-..."}
)
UPDATE:
The confusion seems to be that os.environ["X-OpenAI-API"]
does not mean that you should replace X-OpenAI-API
with your actual key (e.g., sk-...
but that you set an environment variable like $ export X-OpenAI-API=sk-...
this is simply a security measurement.