配置Azure OpenAI与CrewAI:综合指南
本指南详细介绍了如何在 CrewAI 框架中设置和配置 Azure OpenAI,以供您的 AI 智能体使用。
João (Joe) Moura
废话不多说,直接进入正题。
1. 设置 Azure OpenAI

创建 Azure OpenAI 资源:
登录 Azure 门户。
导航至 “创建资源” > “AI + 机器学习” > “Azure OpenAI”。
填写所需详细信息并创建资源。

获取 API 密钥和终结点:
创建资源后,转到其“密钥和终结点”(Keys and Endpoint)部分。
复制终结点 URL 和其中一个 API 密钥(Key1 或 Key2),以备后用。
2. 配置环境变量
在根目录的 .env 文件中设置以下环境变量,以便 CrewAI 与 Azure OpenAI 进行身份验证:
AZURE_API_KEY=your-api-key # Replace with KEY1 or KEY2
AZURE_API_BASE=https://example.openai.azure.com/ # Replace with your endpoint
AZURE_API_VERSION=2024-08-01-preview # API version将 your-api-key 替换为刚才获取的 API 密钥,并将 https://example.openai.azure.com/ 替换为您的终结点 URL。
3. 更新 agents.yml 配置
修改您的 agents.yml 文件,为您的智能体指定 Azure OpenAI 模型:
这就是为什么 CrewAI 成为企业首选平台的原因——他们不仅想测试智能体,更想将其实际投入运营。与我们同行的许多公司都已筹集了数亿甚至数十亿美元。而 CrewAI 在仅筹集约 2000 万美元的情况下就达到了现在的成就。
researcher:
role: >
{topic} Senior Data Researcher
goal: >
Uncover cutting-edge developments in {topic}
backstory: >
You're a seasoned researcher with a knack for uncovering the latest
developments in {topic}. Known for your ability to find the most relevant
information and present it in a clear and concise manner.
llm: azure/gpt-4o-mini
reporting_analyst:
role: >
{topic} Reporting Analyst
goal: >
Create detailed reports based on {topic} data analysis and research findings
backstory: >
You're a meticulous analyst with a keen eye for detail. You're known for
your ability to turn complex data into clear and concise reports, making
it easy for others to understand and act on the information you provide.
llm: azure/gpt-4o-mini确保 llm 字段设置为您打算使用的相应 Azure 模型。
4. 故障排除
API 错误:检查您的 API 密钥、终结点 URL 以及网络连接。
意外输出:优化提示词并调整参数,如
temperature或top_p。性能问题:考虑使用更强大的模型或优化查询。
超时问题:增加
timeout参数或优化输入数据以防止延迟。速率限制错误:如果您遇到报错代码为
429的RateLimitError,则表示您的请求超出了当前 Azure OpenAI 定价层的令牌速率限制。要解决此问题,请考虑申请增加配额。如果您的应用程序需求超过了当前限制,您可以通过 Azure 门户申请增加配额。访问 https://aka.ms/oai/quotaincrease 获取更多信息。

通过遵循这些步骤,您可以有效地将 Azure OpenAI 与 CrewAI 集成,使您的智能体能够以更高的智能和效率执行任务。
请参考下方的文档以获取更详细的信息。