crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
18.62k stars 2.57k forks source link

JSONSearchTool giving KeyError: 'OPENAI_API_KEY' #711

Closed lusabo closed 5 days ago

lusabo commented 3 months ago

I'm running it on Google Colab, I created a JSON file and uploaded it.

The code is quite simple:

json_tool = JSONSearchTool(json_path='/content/hotels.json')

When I am running the code I getting the error:

KeyError: 'OPENAI_API_KEY'

Wasn't it supposed to only fetch the information within JSON?

gadgethome commented 3 months ago

Hi you will need to override the default embedding that uses openai. Please see

https://docs.crewai.com/tools/JSONSearchTool/#usage-examples

arnav77 commented 2 months ago

@gadgethome why is there a need to override when I want to use ada from Openai? The key works as intended when only a language model is required but gives a key error when embeddings are used.

theCyberTech commented 2 months ago

@gadgethome why is there a need to override when I want to use ada from Openai? The key works as intended when only a language model is required but gives a key error when embeddings are used.

What does your embedding conf look like? If there is anything wrong with it crew will default to gpt4

lusabo commented 2 months ago

As my crew is using Llama3, I thought the tool would use what is defined in the crew. I tried to override like below without success, maybe because I don't have the Google API configured. I will do it in a moment.

json_tool = JSONSearchTool(
    json_path='/content/hotels.json', #Is it correct?
    config={
        "llm": {
            "provider": "ollama",
            "config": {
                "model": "llama3"
            },
        },
        "embedder": {
            "provider": "google",
            "config": {
                "model": "models/embedding-001", #what add here?
                "task_type": "retrieval_document" #where can I see task_type?
            },
        },
    }
)
lusabo commented 2 months ago

Whether or not I configure the API key created in AIStudio, I have the error below.

os.environ["API_KEY"] = "my_key_comes_here"

ERROR:grpc._plugin_wrapping:AuthMetadataPluginCallback "<google.auth.transport.grpc.AuthMetadataPlugin object at 0x791ecbfd5cc0>" raised exception! Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/google/auth/compute_engine/credentials.py", line 128, in refresh self._retrieve_info(request) File "/usr/local/lib/python3.10/dist-packages/google/auth/compute_engine/credentials.py", line 101, in _retrieve_info info = _metadata.get_service_account_info( File "/usr/local/lib/python3.10/dist-packages/google/auth/compute_engine/_metadata.py", line 323, in get_service_account_info return get(request, path, params={"recursive": "true"}) File "/usr/local/lib/python3.10/dist-packages/google/auth/compute_engine/_metadata.py", line 248, in get raise exceptions.TransportError( google.auth.exceptions.TransportError: ("Failed to retrieve http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/?recursive=true from the Google Compute Engine metadata service. Status: 404 Response:\nb''", <google.auth.transport.requests._Response object at 0x791ecae217e0>)

The above exception was the direct cause of the following exception:

lusabo commented 2 months ago

I solved the connection problem with::

import google.generativeai as genai
...
os.environ["API_KEY"] = "The key"
genai.configure(api_key=os.environ['API_KEY'])
arnav77 commented 2 months ago

I solved the connection problem with::

import google.generativeai as genai
...
os.environ["API_KEY"] = "The key"
genai.configure(api_key=os.environ['API_KEY'])

I have used this to authenticate Gemini models but this still doesn't work with crew. Tbh I don't understand how this could be a key error.

cbruyndoncx commented 2 months ago

I think this is also related to the known issue that RAG out of the box only works with openai, and there is an embedchain chromate version conflict in v0.30.11 Hoping for next version to fix this, there are some workarounds mentioned here and on the Discord server.

YohanReddy commented 2 months ago

I think this is also related to the known issue that RAG out of the box only works with openai, and there is an embedchain chromate version conflict in v0.30.11 Hoping for next version to fix this, there are some workarounds mentioned here and on the Discord server.

Any fix for RAG using Gemini?

lusabo commented 2 months ago

HI all,

Suddenly my example stopped working and now I receive the error:

ModuleNotFoundError: No module named 'ollama'

I put details on Discord: https://discord.com/channels/1192246288507474000/1252690687804051529

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 5 days ago

This issue was closed because it has been stalled for 5 days with no activity.