Closed remmen-io closed 2 months ago
The error you're encountering, pydantic.v1.errors.ConfigError: unable to infer type for attribute "api_key"
, indicates an issue with Pydantic's ability to determine the type of the api_key
attribute. This can often be due to the environment variable for api_key
not being correctly loaded or accessible at the point where an instance of the relevant Pydantic model is being created. Here are steps to troubleshoot and potentially resolve this issue:
Ensure Environment Variables Are Loaded First: Verify that the code loading the .env
file is executed before any Pydantic models are instantiated. This is crucial for making sure that all environment variables are available when needed.
Explicitly Define Type and Source for api_key
: In your Pydantic model, explicitly define the type of api_key
and, if it's coming from an environment variable, use Pydantic's Field
to specify its environment variable name, like so:
from pydantic import BaseModel, Field
class ApiKey(BaseModel):
api_key: str = Field(..., env='API_KEY_ENV_VARIABLE')
This approach clarifies the expected type and source of api_key
.
Check the Environment Variable Directly: Before the Pydantic model instantiation, add a debug statement to print out the environment variable value to ensure it's being correctly set and recognized by your application.
Manually Test Model Initialization: Try manually initializing your Pydantic model with a hardcoded api_key
value to see if the error still occurs. If it doesn't, the issue likely lies in how the environment variable is being passed or loaded.
Review Pydantic and Project Documentation: Double-check the Pydantic documentation for any nuances related to environment variable loading or type inference that might be affecting your setup. Additionally, consult the project's documentation or forums for any known issues or specific guidance related to api_key
handling.
By following these steps, you should be able to identify and correct the issue with the api_key
attribute in your Pydantic model.
To continue the conversation, mention @dosu.
@remmen-io can you git pull ;)
I'm having the same problem, is there a definitive solution so far?
Same, MacBook Pro M1
Can you uncomment the BRAVE_SEARCH api key in the env file ?
Looks as it works now :)
BRAVE_SEARCH_API_KEY=CHANGE_ME
Uncommenting BRAVE_SEARCH_API_KEY also worked here. Thanks!
What happened?
I've reinstalled quivr from scratch, started the db, setup .env, but I'm unable to get the backend-core running. I get a
pydantic.v1.errors.ConfigError: unable to infer type for attribute "api_key"
error.Relevant log output