#๐ Why is it not recognizing my key?
44 messages ยท Page 1 of 1 (latest)
@trail agate
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
What's the full error message?
Try passing in the api key that you get as a named parameter? I'm not sure how nicely pydantic plays with a google colab environment
So just directly paste the key as a parameter?
I think your env var has the wron name
from the error message, it's looking for TAVILY_API_KEY
but your env vars are just TAVILY_KEY and API_KEY
Yeah something like
api_key = userdata.get(...)
...
web_search_tool = TavilySearchResults(k=3, tavily_api_key=api_key)
where did you guys find a tavily_api_key?
import os, getpass
from google.colab import userdata
userdata.get('TAVILY_KEY')
userdata.get('LANGSMITH_KEY')
def _set_env(var: str):
if not os.environ.get(var):
os.environ[var] = getpass.getpass(f"{var}: ")
_set_env("TAVILY_KEY")
_set_env("LANGSMITH_KEY")
os.environ['TOKENIZERS_PARALLELISM'] = 'true'
os.environ["LANGCHAIN_TRACING_V2"] = 'true'
os.environ["LANGCHAIN_PROJECT"] = "local-llama32-rag"
###Search
from langchain_community.tools.tavily_search import TavilySearchResults
web_search_tool = TavilySearchResults(k=3)
###LLM
from langchain_ollama import ChatOllama
local_llm = 'llama3.2:3b-instruct-fp16'
llm = ChatOllama(model=local_llm, temperature=0)
llm_json_mode = ChatOllama(model=local_llm, temperature=0, format='json')```
From the error message
The error message is telling you what it should be
Rename TAVILY_KEY to TAVILY_API_KEY
As indicated by the error message, this is the env var in which it's looking for the api key
It also suggests passing it in as a named param, as jim already mentioned too
For environment variables, programs will look for a specific name to look up
Yeah i just read it properly, but its weird why i have to name it in a certain format in a secrets file
i understand
it works, thanks a lot guys
Why is that weird? The library you're using can't just guess out of all the environment variables which one to use
i mean i can name it xyz and then if i say to detect xyz, for the value of the key, isn't that normal?
But in your code you didn't tell it to look for a different env car name. So it's still looking under the original one
Some programs do allow you to set which env var name it should look under, but it's more common for it to just expect it under one name and nowhere else
i named it TAVILY_KEY in the folder and even here in the code i passed TAVILY_KEY everywhere for the same environment variables. Shouldn't it detect that?
Yeah that's what im saying, so this is like either a colab or a tavily's own formatting way of naming keys this way right?
You never told the authentication library what the name of your environment variable was
All it knows is to look for "TAVILY_API_KEY"
How is TavilySearchResults() supposed to know that though? You also set Langsmith Key, why shouldn't it also look under there?
This is Tavily requiring a specific name for the env var it will search under
cus tavilysearchresults() didn't ask for a key directly and even when it requires one it can look up tavily_key from here? (Now i changed it ofc)
Hmm yeah then its something i need to keep in mind
But it's looking under tavily_api_key. It has no way to know to search for something else
is it like tavily_api_key is the default term its searching for? And if i want to change that i need to add additional commands or something?
Yeah, but most libraries won't let you change the term it'll look for. It just tells you what the name to set and that's just what you have to do
ahh okay okay i understand. Thanks!
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.