You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Python调用Microsoft 365 Copilot/Graph API实现Bing联网搜索?

关于Microsoft 365 Copilot API实现公开网页搜索Grounding的问题解答

1. 是否存在支持通过Microsoft 365 Copilot实现Web/Bing搜索grounding的API端点

目前没有公开的API端点支持通过Microsoft 365 Copilot或Graph API直接调用Bing网页搜索进行grounding。Microsoft 365 Copilot UI中的网页搜索能力是微软内部整合的专属功能,并未对外暴露API接口。

2. 功能状态确认

该网页搜索grounding功能仅在Microsoft 365 Copilot原生UI中可用,未通过任何公开API向第三方开发者开放。当前处于预览阶段的Copilot Chat API仅支持基于租户内部内容(如SharePoint、OneDrive)的grounding,依赖Retrieval APIs完成内部内容检索,不支持拉取公开网页数据。

3. 替代方案

若需在Python应用中实现带公开网页搜索的AI响应,必须单独使用Bing Search API,自行完成搜索结果的获取、上下文整理,再将其传入Copilot Chat API(或其他大语言模型API)生成最终响应。

简单实现思路(Python伪代码)

# 1. 调用Bing Search API获取公开网页结果
import requests

def get_bing_search_results(query, bing_api_key):
    url = "https://api.bing.microsoft.com/v7.0/search"
    headers = {"Ocp-Apim-Subscription-Key": bing_api_key}
    params = {"q": query, "count": 3}  # 获取3条搜索结果
    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    results = response.json()
    # 整理搜索结果为上下文文本
    context = "\n".join([f"来源: {item['name']}\n内容摘要: {item['snippet']}" for item in results["webPages"]["value"]])
    return context

# 2. 将搜索结果作为上下文传入Copilot Chat API
def call_copilot_chat(prompt, context, copilot_api_token):
    url = "https://graph.microsoft.com/v1.0/me/copilot/chat"
    headers = {"Authorization": f"Bearer {copilot_api_token}", "Content-Type": "application/json"}
    payload = {
        "messages": [
            {"role": "system", "content": f"基于以下公开网页搜索结果回答问题:\n{context}"},
            {"role": "user", "content": prompt}
        ]
    }
    response = requests.post(url, headers=headers, json=payload)
    response.raise_for_status()
    return response.json()["choices"][0]["message"]["content"]

注意:使用Bing Search API需要单独申请API密钥,Copilot Chat API的调用需遵循微软预览版的权限要求和调用限制。

内容的提问来源于stack exchange,提问作者Banng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 19:07:27