配置Azure OpenAI与CrewAI:综合指南
一步一步指导如何在CrewAI框架内设置和配置Azure OpenAI以用于您的AI代理。

不用引言来打扰,以下是指南。
1. 设置 Azure OpenAI

- 创建 Azure OpenAI 资源:
- 登录到Azure 门户。
- 导航至"创建资源" > "AI + 机器学习" > "Azure OpenAI"。
- 填写所需详细信息并创建资源。
- 获取 API 密钥和端点:

- 创建资源后,转到其"密钥和端点"部分。
- 复制端点 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 模型。
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
参数或优化输入数据以防止延迟。 - 速率限制错误:如果您遇到一个
RateLimitError
,错误代码为code 429
,这表明您的请求已超出当前 Azure OpenAI 定价层的令牌速率限制。要解决此问题,请考虑申请配额增加。如果您的应用程序要求超出当前限制,您可以通过 Azure 门户申请配额增加。请访问 https://aka.ms/oai/quotaincrease 获取更多信息。

通过遵循这些步骤,您可以有效地将 Azure OpenAI 与 CrewAI 集成,使您的代理能够以更高的智能和效率执行任务。
请参考下面的文档以获取更多详细信息。
大型语言模型 (LLMs) - CrewAI
了解如何为您的 CrewAI 项目配置和优化大型语言模型 (LLMs)。
评论 ()