Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearXNG: Exception: Tavily API key not found. Please set the TAVILY_API_KEY environment variable. #909

Closed
PieBru opened this issue Oct 14, 2024 · 5 comments

Comments

@PieBru
Copy link

PieBru commented Oct 14, 2024

Describe the bug
This is the log:

INFO:     [11:03:05] 
🔍 Running research for ...
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/home/admin/Github/gpt-researcher/gpt_researcher/retrievers/tavily/tavily_search.py", line 39, in get_api_key
    api_key = os.environ["TAVILY_API_KEY"]
              ~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 679, in __getitem__
KeyError: 'TAVILY_API_KEY'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 242, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/applications.py", line 113, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 152, in __call__
    await self.app(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/routing.py", line 715, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/routing.py", line 735, in app
    await route.handle(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/routing.py", line 362, in handle
    await self.app(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/routing.py", line 95, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app
    raise exc
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app
    await app(scope, receive, sender)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/starlette/routing.py", line 93, in app
    await func(session)
  File "/home/admin/Github/gpt-researcher/venv/lib/python3.11/site-packages/fastapi/routing.py", line 383, in app
    await dependant.call(**solved_result.values)
  File "/home/admin/Github/gpt-researcher/backend/server/server.py", line 142, in websocket_endpoint
    await handle_websocket_communication(websocket, manager)
  File "/home/admin/Github/gpt-researcher/backend/server/server_utils.py", line 117, in handle_websocket_communication
    await handle_start_command(websocket, data, manager)
  File "/home/admin/Github/gpt-researcher/backend/server/server_utils.py", line 28, in handle_start_command
    report = await manager.start_streaming(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/backend/server/websocket_manager.py", line 61, in start_streaming
    report = await run_agent(task, report_type, report_source, source_urls, tone, websocket, headers)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/backend/server/websocket_manager.py", line 95, in run_agent
    report = await researcher.run()
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/backend/report_type/basic_report/basic_report.py", line 41, in run
    await researcher.conduct_research()
  File "/home/admin/Github/gpt-researcher/gpt_researcher/master/agent/master.py", line 82, in conduct_research
    self.context = await self.research_conductor.conduct_research()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/master/agent/researcher.py", line 73, in conduct_research
    self.researcher.context = await self.__get_context_by_search(self.researcher.query)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/master/agent/researcher.py", line 161, in __get_context_by_search
    context = await asyncio.gather(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/master/agent/researcher.py", line 220, in __process_sub_query
    scraped_data = await self.__scrape_data_by_query(sub_query)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/master/agent/researcher.py", line 275, in __scrape_data_by_query
    retriever = retriever_class(sub_query)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/retrievers/tavily/tavily_search.py", line 25, in __init__
    self.api_key = self.get_api_key()
                   ^^^^^^^^^^^^^^^^^^
  File "/home/admin/Github/gpt-researcher/gpt_researcher/retrievers/tavily/tavily_search.py", line 41, in get_api_key
    raise Exception(
Exception: Tavily API key not found. Please set the TAVILY_API_KEY environment variable.
INFO:     connection closed

To Reproduce
This is the .env:

#export TAVILY_API_KEY=tvly-**********
#export RETRIEVER=tavily
export RETRIEVER=searx
export SEARX_URL="http://10.4.0.101:32768"
export DOC_PATH=./my-docs
export LLM_PROVIDER=ollama
export OLLAMA_BASE_URL="http://10.4.0.100:11434"
export FAST_LLM=ollama:llama3.2
export SMART_LLM=ollama:llama3.2
export TEMPERATURE="0.1"
export EMBEDDING_PROVIDER=ollama
export OLLAMA_EMBEDDING_MODEL=nomic-embed-text

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Debian 12 LXC on Proxmox VE 8.2
  • Browser LibreWolf (Firefox)
  • Version -

Smartphone (please complete the following information):

  • Device: -
  • OS: -
  • Browser -
  • Version -

Additional context
Add any other context about the problem here.

@assafelovic
Copy link
Owner

Looking into it!

@igochkov
Copy link
Contributor

I got this working yesterday. The searx retriever had to be rewritten. I will submit a pull request soon.

@assafelovic
Copy link
Owner

Thanks @igochkov would love a pr fix for this

@igochkov
Copy link
Contributor

Pull-request: #960 is ready for review @assafelovic

@ab94amz
Copy link

ab94amz commented Oct 29, 2024

I solved with

from dotenv import load_dotenv
load_dotenv(dotenv_path=".env")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants