zizon
zizon

Reputation: 43

langchian LLM getting Serpapi error saying that the api key is invalid

I am trying to create a LLM that can use search function to get the answer of the user's questions from the internet. The current code I have is this. I have imported all the required files, so I am skipping the import codes.

os.environ["SERPAPI_API_KEY"] = "*****"

search = SerpAPIWrapper()
tools = [ Tool(
      name="Search",
      func=search.run,
      description= f"""Useful when you need to answer questions that is not in the csv dataframe.
      If you can't find the answer from the csv file, use the search tool.
      While searching, try to provide the url of the webiste that the user has asked for.
      """,
    ),
]

mrkl = initialize_agent(
    tools, llm, max_iterations=10, verbose=True
)

There is one more tool that I have used, and my model was successfully able to use that first tool, and start using the search tool if it cannot find the answer of the user's question.

However, when it starts to search, it shows the following error message:

ValueError: Got error from SerpAPI: Invalid API key. Your API key should be here: https://serpapi.com/manage-api-key

I have tried to get another SerpAPI, but it is still not working. Any help would be appreciated!

Upvotes: 0

Views: 1294

Answers (1)

ZKS
ZKS

Reputation: 2856

If you are using windows, you need to set environment variable for this key. Key can be found on https://serpapi.com/manage-api-key. You can use free account with limited number of requests

enter image description here

Upvotes: 1

Related Questions