使用 CrewAI 配置 Azure OpenAI:综合指南
在 CrewAI 框架中为你的 AI 智能体设置和配置 Azure OpenAI 的分步指南。
我就不冗长地介绍啦,直接上指南。
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参数或优化输入数据以防止延迟。 - 速率限制错误:如果您遇到错误代码为
429的RateLimitError,表示您的请求已超出当前 Azure OpenAI 定价层的令牌速率限制。要解决此问题,请考虑请求增加配额。如果您的应用程序需求超出当前限制,您可以通过 Azure 门户请求增加配额。访问 https://aka.ms/oai/quotaincrease 获取更多信息。

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

评论 ()