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
19.09k stars 2.64k forks source link

Azure Openai support in tool config #541

Open deb007 opened 4 months ago

deb007 commented 4 months ago

Hello, I am trying out the PDFSearchTool with Azure OpenAI. I see provider = azure_openai is a valid option but I am unable to get it working. This is my current code:

mytool = PDFSearchTool(
    pdf="abcd.pdf",
    config=dict(
        llm=dict(
            provider="azure_openai",  # or google, openai, anthropic, llama2, ...
            config=dict(
                model="gpt4",
                azure_deployment=os.getenv("AZURE_OPENAI_DEPLOYMENT"),
                api_key=os.getenv("AZURE_OPENAI_KEY"),
                azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
                # top_p=1,
                # stream=true,
            ),
        ),
        embedder=dict(
            provider="azure_openai",
            config=dict(
                model="text-embedding-ada-002",
                deployment_name="text-embedding-ada-002",
                # title="Embeddings",
            ),
        ),
    ),
)

Getting error:

schema.SchemaError: Key 'llm' error:
Key 'config' error:
Wrong keys 'azure_deployment', 'azure_endpoint' in {... ... }

Any kind of help will be much appreciated.

DavidGayda commented 3 months ago

I am also having this issue, and have not yet found a resolution.

DavidGayda commented 3 months ago

I believe it is now working correctly for me. I had to do 2 things.

  1. Find the correct key names to use. I have model, deployment_name, and api_key set here from my environment variables.

tool = PDFSearchTool( pdf='file.pdf', config=dict( llm=dict( provider="azure_openai", # or google, openai, anthropic, llama2, ... config=dict( model=os.environ.get("MODEL"), deployment_name=os.environ.get("DEPLOYMENT_NAME"), api_key=os.environ.get("AZURE_OPENAI_KEY"), ), ), embedder=dict( provider="azure_openai", # or openai, ollama, ... config=dict( model="text-embedding-ada-002", deployment_name="text-embedding-ada-002", api_key=os.environ.get("AZURE_OPENAI_KEY"), ), ), ) )

  1. I believe there may be an issue in the embed chain package that CrewAI uses. In the embedchain/embedder/openai.py file in that package Line 23 I updated to pass in the api_key and api_base

embeddings = AzureOpenAIEmbeddings(deployment=self.config.deployment_name, api_key=api_key, base_url=api_base)

theholymath commented 2 months ago

This solution executes (the parameters are accepted) but it's not constructing a RAG DB for me. Weirdly, when I use the code with openAI (not AzureopenAI) it creates the Chroma DB as normal. Then, if I use my code as @DavidGayda outlines above with AzureOpenAI it adds the new text to that existing DB.

github-actions[bot] commented 3 weeks 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.

ecocarlisle commented 3 weeks ago

Hello, following up on this issue. Is there a fix available for using PDFSearchTool and Azure OpenAI?

PiXOT97 commented 2 weeks ago

Same question, anyone figure out this?

theCyberTech commented 1 week ago

Same question, anyone figure out this?

https://github.com/crewAIInc/crewAI/issues/541#issuecomment-2118393378