你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
重要
- 此 REST API 允许开发人员通过 Azure AI Foundry 代理服务使用“使用必应自定义搜索查找事实依据”工具。 它不会直接将调用发送到“使用必应自定义搜索查找事实依据”API。
- 如果通过 REST API 调用将 Azure AI Foundry 项目 资源与 Microsoft Fabric 工具配合使用,则以下示例适用
- 连接 ID 应采用以下格式:
/subscriptions/<sub-id>/resourceGroups/<your-rg-name>/providers/Microsoft.CognitiveServices/accounts/<your-ai-services-name>/projects/<your-project-name>/connections/<your-bing-connection-name>
请按照 REST API 快速入门 为环境变量 AGENT_TOKEN
、AZURE_AI_FOUNDRY_PROJECT_ENDPOINT
和 API_VERSION
设置正确的值。
创建已启用“使用必应自定义搜索提供事实依据”工具的代理
要使“使用必应自定义搜索查找事实依据”工具可供代理使用,请使用连接来初始化该工具并将其附加到代理。 可以在 Azure AI Foundry 门户中项目的“已连接资源”部分找到连接。
curl --request POST \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/assistants?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"instructions": "You are a helpful agent.",
"name": "my-agent",
"model": "gpt-4o",
"tools": [
{
"type": "bing_custom_search",
"bing_custom_search": {
"search_configurations": [
{
"connection_id": /subscriptions/<sub-id>/resourceGroups/<your-rg-name>/providers/Microsoft.CognitiveServices/accounts/<your-ai-services-name>/projects/<your-project-name>/connections/<your-bing-connection-name>,
"instance_name": <your_custom_search_configuration_name>,
"count": 7,
"market": "en-US",
"set_lang": "en",
"freshness": "day",
}
]
}
}
]
}'
创建线程
curl --request POST \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d ''
将用户问题添加到线程
curl --request POST \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/messages?api-version=api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"role": "user",
"content": "<ask a question tailored towards your web domains>"
}'
创建运行并检查输出
创建运行并观察模型是否使用“使用必应自定义搜索查找事实依据”工具来响应用户的问题。
curl --request POST \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"assistant_id": "asst_abc123",
}'
获取运行状态
curl --request GET \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs/run_abc123?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN"
检索代理响应
curl --request GET \
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/messages?api-version=$API_VERSION \
-H "Authorization: Bearer $AGENT_TOKEN"