> For the complete documentation index, see [llms.txt](https://doc.thordata.com/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.thordata.com/doc/zh-hk/pa-qu/serp-api/ji-cheng/sdk-ji-cheng/ru-he-jiang-thordata-yu-llamaindex-ji-cheng.md).

# 如何將ThorData与LlamaIndex集成

安裝 Thordata LlamaIndex 套件，配置 API Token，並在 AI Agent 中使用 SERP 工具進行即時網頁、圖片和新聞搜尋。

將 ThorData SERP API 連接到 LlamaIndex，讓您的代理能夠執行即時網頁搜尋、圖片搜尋、新聞搜尋，並取得結構化搜尋結果。ThorData 支援覆蓋全球 190 個國家/地區，適用於 AI Agent、SEO 工具、市場研究和搜尋驅動型應用。

#### 取得您的 ThorData API 密鑰

* 登入您的 [ThorData 控制台](https://dashboard.thordata.com/serp-api/get-started)。
* 前往 [SERP API - API Token](https://dashboard.thordata.com/serp-api/get-started)。如果您尚未生成 API Token，請生成一個新的API 密鑰。

#### 安裝

安裝所需的套件：

```
python -m pip install llama-index-tools-thordata-serp
```

#### 使用範例

以下範例示範如何將 ThorData 工具與 LlamaIndex 搭配使用。

```
llm = OpenAI(model="gpt-4o", api_key="your-api-key")

thordata_tool = thordataToolSpec(api_key="your-api-key", zone="unlocker")

tool_list = thordata_tool.to_tool_list()

for tool in tool_list:
    tool.original_description = tool.metadata.description
    tool.metadata.description = "thordata web scraping tool"

agent = OpenAIAgent.from_tools(tools=tool_list, llm=llm)

query = (
    "Find and summarize the latest news about AI from major tech news sites"
)
tool_descriptions = "\n\n".join(
    [
        f"Tool Name: {tool.metadata.name}\nTool Description: {tool.original_description}"
        for tool in tool_list
    ]
)

query_with_descriptions = f"{tool_descriptions}\n\nQuery: {query}"

response = agent.chat(query_with_descriptions)
print(response)
```
