GPT Researcher 如何配置 Azure OpenAI 部署名、text-embedding-3-large 嵌入模型与配额要求
【免费下载链接】gpt-researcherAn autonomous agent that conducts deep research on any data using any LLM providers项目地址: https://gitcode.com/GitHub_Trending/gp/gpt-researcher
如果你的 GPT Researcher 目前直连 OpenAI,现在需要把 LLM 和嵌入模型迁移到 Azure OpenAI,这篇文章给出文档支撑的完整配置路径:在 Azure 侧创建部署(含强制要求的text-embedding-3-large嵌入模型部署)、在项目的.env中按azure_openai:部署名格式填写各角色模型、处理嵌入模型的配额申请,最后启动服务验证配置生效。前置要求:本地已安装 Python 3.11 或更高版本(requirements.txt 中的注释为 LangChain v1 要求 Python 3.10+),并已克隆 gpt-researcher 仓库。
GPT Researcher 通过更新SMART_LLM、FAST_LLM、STRATEGIC_LLM和EMBEDDING四个环境变量在提供商之间切换(见 LLM 配置文档),azure_openai是受支持的 LLM 与 embedding 提供商。
Azure 侧:创建部署并申请配额
在 Azure OpenAI Portal 上,你需要为每个要用的模型各创建一个 deployment,然后在项目的.env文件中登记这些部署。文档给出的推荐模型(2025 年 1 月版本)是:
gpt-4o-minigpt-4oo1-preview或o1-mini(这两者可能需要先申请访问权限才能部署)
文档列出了三条必备前置条件(Required Precondition):
- Endpoint 可以是任意合法名称;
- 模型的部署名(deployment name)必须与模型名相同——这决定了后面环境变量里冒号后面该填什么;
- 必须部署一个 Embedding 模型:GPT Researcher 要求使用
text-embedding-3-large,需要把这个具体模型部署到你的 Azure Endpoint。
同时有一条推荐项(Recommended):应该申请配额提升(quota increase),尤其是嵌入模型的配额,因为默认配额不足。也就是说部署完成不等于能跑——嵌入模型配额不够时,这是文档明确给出的应对方式,而不是自行调参能解决的。
在 .env 中配置 Azure OpenAI
按 LLM 配置文档 的 Azure OpenAI 一节,在项目根目录的.env文件中写入([Your Key]替换为你的 Azure API key,{your-endpoint}替换为你的 endpoint 名称,OPENAI_API_VERSION可用你实际使用的版本):
AZURE_OPENAI_API_KEY=[Your Key] AZURE_OPENAI_ENDPOINT=https://{your-endpoint}.openai.azure.com/ OPENAI_API_VERSION=2024-05-01-preview # each string is "azure_openai:deployment_name". ensure that your deployment have the same name as the model you use! FAST_LLM=azure_openai:gpt-4o-mini SMART_LLM=azure_openai:gpt-4o STRATEGIC_LLM=azure_openai:o1-preview # specify embedding EMBEDDING=azure_openai:text-embedding-3-large几个关键点:
FAST_LLM/SMART_LLM/STRATEGIC_LLM的格式是azure_openai:deployment_name,冒号后面填的是部署名而不是模型名(另一份 Azure 配置示例 的注释明确写着 "change to the name of your deployment (not model-name)")。配合上一条前置条件"部署名必须与模型名相同",实操中直接填模型名即可。EMBEDDING=azure_openai:text-embedding-3-large就是上面必备前置条件第 3 条的落点:嵌入模型也按同一格式指向 Azure 侧的部署。- 解析逻辑在 gpt_researcher/config/config.py:
parse_llm和parse_embedding按第一个冒号拆出提供商和模型名,提供商不在支持列表时会报错(例如Unsupported ...并列出支持的提供商);字符串不含冒号时抛出Set SMART_LLM or FAST_LLM = '<llm_provider>:<llm_model>'提示。 - 环境变量如何被消费:嵌入客户端在 gpt_researcher/memory/embeddings.py 中构造,
azure_openai分支使用langchain_openai.AzureOpenAIEmbeddings,azure_endpoint和openai_api_key直接取自AZURE_OPENAI_ENDPOINT与AZURE_OPENAI_API_KEY(缺任一变量会在构造时直接抛错);API 版本优先读AZURE_OPENAI_API_VERSION,未设置时回退到OPENAI_API_VERSION——这就是文档示例只写OPENAI_API_VERSION也能生效的原因。
另一个官方示例:搜索引擎与 token 限制
running-with-azure.md 给出了一份更早的示例,额外覆盖了搜索引擎和输出 token 限制:
OPENAI_API_VERSION="2024-05-01-preview" # or whatever you are using AZURE_OPENAI_ENDPOINT="https://CHANGEMEN.openai.azure.com/" # change to the name of your deployment AZURE_OPENAI_API_KEY="[Your Key]" # change to your API key EMBEDDING="azure_openai:text-embedding-ada-002" # change to the deployment of your embedding model FAST_LLM="azure_openai:gpt-4o-mini" # change to the name of your deployment (not model-name) FAST_TOKEN_LIMIT=4000 SMART_LLM="azure_openai:gpt-4o" # change to the name of your deployment (not model-name) SMART_TOKEN_LIMIT=4000 RETRIEVER="bing" # if you are using Bing as your search engine (which is likely if you use Azure) BING_API_KEY="[Your Key]"注意其中EMBEDDING="azure_openai:text-embedding-ada-002"与 llms.md 中"必须部署text-embedding-3-large"的硬性要求不一致,两份文档在这里冲突;本文按标题目标采用 llms.md 的text-embedding-3-large,ada-002仅作为该旧示例的原样呈现。如果你使用 Bing 作为搜索引擎(文档认为使用 Azure 时很可能如此),把RETRIEVER与BING_API_KEY一并加入.env。token 限制类参数(FAST_TOKEN_LIMIT、SMART_TOKEN_LIMIT等)的默认值与长输出模型的调高建议见 配置参考。
安装依赖
pip install -r requirements.txtrequirements.txt已包含langchain-openai(即AzureOpenAIEmbeddings所在包)。此外 llms.md 要求为 Azure OpenAI 增加langchain-azure-dynamic-sessions:Docker 部署时把它加入你自己的 requirements.txt,否则直接pip install langchain-azure-dynamic-sessions。该依赖不在仓库默认的 requirements.txt 中,漏装会影响 Azure 会话支持。
启动并验证
按 Getting Started 的路径启动:
uvicorn main:app --reload然后打开浏览器访问 http://localhost:8000,发起一次研究任务,确认报告能正常生成——这是文档给出的端到端验证方式。配置不当时,文档建议遵循控制台日志排错(config.md 原话:"Please follow your console logs for further assistance")。可以对照的预期错误形态:
FAST_LLM/SMART_LLM格式错误(缺少provider:model冒号格式)会看到Set SMART_LLM or FAST_LLM = '<llm_provider>:<llm_model>';- 提供商名拼错会看到
Unsupported <provider>加支持列表; .env缺少AZURE_OPENAI_ENDPOINT或AZURE_OPENAI_API_KEY时,嵌入客户端构造阶段直接抛错。
限制
o1-preview/o1-mini在部署前可能需要先在 Azure 申请模型访问权限;- 嵌入模型默认配额不足是文档明确承认的常见问题,配额申请属于 Azure 侧操作,完成部署后应主动发起;
- GPT Researcher 在 GPT 系列模型上优化和测试得最充分,切换到其他模型可能遇到上下文长度错误和意外响应(llms.md 的通用提示)。
验证以浏览器端研究任务成功运行、且控制台日志不再出现上述配置错误为准;配额不足导致嵌入调用失败时,回到 Azure 侧申请配额提升而不是修改项目配置。
【免费下载链接】gpt-researcherAn autonomous agent that conducts deep research on any data using any LLM providers项目地址: https://gitcode.com/GitHub_Trending/gp/gpt-researcher
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考