CrewAI PDFSearchTool 使用 AZURE OPENAI API 时抛出错误

问题描述 投票:0回答:1

为什么在尝试使用 PDFSearchTool 使用 CrewAI 进行 PDF RAG 搜索时出现以下错误?

我正在使用 Azure OpenAPI AI,使用 gpt-4o 和 text-embedding-ada-002 模型传递到 CrewAI 代码中。我参考了 https://docs.crewai.com/tools/pdfsearchtool#pdfsearchtool,其中说如果我们使用其他模型(例如 azure_openai),则使用自定义配置。

from multiprocessing import process
from crewai import Agent, Crew, Process, Task,LLM
from crewai_tools import PDFSearchTool
from dotenv import load_dotenv

import litellm
litellm.set_verbose = True

import os

load_dotenv()


os.environ["OPENAI_API_KEY"] = "random key"
os.environ["OPENAI_API_VERSION"] = "2022-01-01"

llm = LLM(
    model="azure/gpt-4o",
    base_url="https://<azurereopen ai resource name>.openai.azure.com",
    api_key="key copied from endpoint section on azure openai"
)

config = dict(
    llm=dict(
        provider="azure_openai",
        config=dict(
            model="gpt-4o",
            api_key="key copied from endpoint section on azure openai",
            deployment_name="https://<azurereopen ai resource name>.openai.azure.com"
        ),
    ),
    embedder=dict(
        provider="azure_openai",
        config=dict(
            model="text-embedding-ada-002",
            deployment_name="https://<azurereopen ai resource name>.openai.azure.com",
            api_key="key copied from endpoint section on azure openai"
        ),
    )
)

# --- Tools ---
pdf_search_tool = PDFSearchTool(
   config=config,
    pdf='./example_home_inspection.pdf'
)

# --- Agents ---
research_agent = Agent(
    role="Research Agent",
    goal="Search through the PDF to find relevant answers",
    allow_delegation=False,
    verbose=True,
    backstory=(
        """
        The research agent is adept at searching and 
        extracting data from documents, ensuring accurate and prompt responses.
        """
    ),
    tools=[pdf_search_tool],
    llm=llm

)

professional_writer_agent = Agent(
    role="Professional Writer",
    goal="Write professional emails based on the research agent's findings",
    allow_delegation=False,
    verbose=True,
    backstory=(
        """
        The professional writer agent has excellent writing skills and is able to craft 
        clear and concise emails based on the provided information.
        """
    ),
    tools=[]
)


# --- Tasks ---
answer_customer_question_task = Task(
    description=(
        """
        Answer the customer's questions based on the home inspection PDF.
        The research agent will search through the PDF to find the relevant answers.
        Your final answer MUST be clear and accurate, based on the content of the home
        inspection PDF.

        Here is the customer's question:
        {customer_question}
        """
    ),
    expected_output="""
        Provide clear and accurate answers to the customer's questions based on 
        the content of the home inspection PDF.
        """,
    tools=[pdf_search_tool],
    agent=research_agent,
    llm=llm
)

write_email_task = Task(
    description=(
        """
        - Write a professional email to a contractor based 
            on the research agent's findings.
        - The email should clearly state the issues found in the specified section 
            of the report and request a quote or action plan for fixing these issues.
        - Ensure the email is signed with the following details:
        
            Best regards,

            AuthorName
        """
    ),
    expected_output="""
        Write a clear and concise email that can be sent to a contractor to address the 
        issues found in the home inspection report.
        """,
    tools=[],
    agent=professional_writer_agent,
)

# --- Crew ---
crew = Crew(
    agents=[research_agent],
    tasks=[answer_customer_question_task],
    process=Process.sequential
)
customer_question = input(
    "Which section of the report would you like to generate a work order for?\n"
)

result = crew.kickoff(inputs={"customer_question": customer_question})
print(result)

我使用诗歌进行包和依赖项管理,以下是包详细信息:

python = ">=3.10.0,<3.12"
python-dotenv = "1.0.0"
crewai-tools = ">=0.4.26"
crewai = ">=0.41.1"
langchain-anthropic = ">=0.1.20"
langchain-openai=">=0.1.7"

当我尝试运行

python <path to py file>.py
时,它会抛出:

    Agent: Research Agent
Task: Answer the customer's questions based on the home inspection PDF.
The research agent will search through the PDF to find the relevant answers. Your final answer MUST be clear and accurate, based on the content of the home inspection PDF.

Here is the customer's question:Exterior

LiteLLM.Info: If you need to debug this error, use litellm.set_verbose=True'.



    raise AuthenticationError(
litellm.exceptions.AuthenticationError: litellm.AuthenticationError: AuthenticationError: OpenAIException - The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable
azure-openai crewai
1个回答
0
投票

我在本地尝试了你的代码。你的deployment_name变量有错误,剩下的就可以了。

而不是:

deployment_name =“https://.openai.azure.com”

它应该类似于下面的内容,它是你的模型在azure中的部署名称:

deployment_name=gpt-4o

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.