#๐Ÿ”’ Why is it not recognizing my key?

44 messages ยท Page 1 of 1 (latest)

trail agate
harsh escarpBOT
#

@trail agate

Python help channel opened

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.

vocal plover
trail agate
vocal plover
# trail agate

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

trail agate
loud mauve
#

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

vocal plover
#

Yeah something like

api_key = userdata.get(...)

...

web_search_tool = TavilySearchResults(k=3, tavily_api_key=api_key)
trail agate
#

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')```
vocal plover
#

From the error message

trail agate
#

i know, but shouldnt it then be in my code?

#

if i've written a variable wrong

vocal plover
#

The error message is telling you what it should be

loud mauve
#

Rename TAVILY_KEY to TAVILY_API_KEY

trail agate
#

huh. why does that matter?

#

is it not just a variable

loud mauve
#

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

vocal plover
#

For environment variables, programs will look for a specific name to look up

trail agate
#

Yeah i just read it properly, but its weird why i have to name it in a certain format in a secrets file

trail agate
#

it works, thanks a lot guys

loud mauve
#

Why is that weird? The library you're using can't just guess out of all the environment variables which one to use

trail agate
#

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?

vocal plover
#

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

trail agate
trail agate
loud mauve
#

All it knows is to look for "TAVILY_API_KEY"

vocal plover
vocal plover
trail agate
trail agate
vocal plover
trail agate
#

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?

vocal plover
#

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

trail agate
#

ahh okay okay i understand. Thanks!

harsh escarpBOT
#
Python help channel closed

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.