Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
package_name: agents-course
path_to_docs: agents-course/units/
additional_args: --not_python_module
languages: en zh-CN ru-RU vi es ko fr
languages: en zh-CN zh-TW ru-RU vi es ko fr
secrets:
hf_token: ${{ secrets.HF_DOC_BUILD_PUSH }}
2 changes: 1 addition & 1 deletion .github/workflows/build_pr_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
package_name: agents-course
path_to_docs: agents-course/units/
additional_args: --not_python_module
languages: en zh-CN ru-RU vi es ko fr
languages: en zh-CN zh-TW ru-RU vi es ko fr
172 changes: 172 additions & 0 deletions units/zh-TW/_toctree.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
- title: 第 0 單元:歡迎加入課程
sections:
- local: unit0/introduction
title: 歡迎加入課程 🤗
- local: unit0/onboarding
title: 課前準備
- local: unit0/discord101
title: (選修)Discord 入門
- title: 直播 1:課程進行方式與問答
sections:
- local: communication/live1
title: 直播 1:課程進行方式與問答
- title: 第 1 單元:agent 入門
sections:
- local: unit1/introduction
title: 簡介
- local: unit1/what-are-agents
title: 什麼是 agent?
- local: unit1/quiz1
title: 隨堂測驗 1
- local: unit1/what-are-llms
title: 什麼是 LLM?
- local: unit1/messages-and-special-tokens
title: 訊息與特殊 token
- local: unit1/tools
title: 什麼是工具?
- local: unit1/quiz2
title: 隨堂測驗 2
- local: unit1/agent-steps-and-structure
title: 透過思考、行動與觀察循環理解 AI agent
- local: unit1/thoughts
title: 思考、內部推理與 Re-Act 方法
- local: unit1/actions
title: 行動:讓 agent 與環境互動
- local: unit1/observations
title: 觀察:整合回饋以反思與調整
- local: unit1/dummy-agent-library
title: 簡易 agent 函式庫
- local: unit1/tutorial
title: 使用 smolagents 建立第一個 agent
- local: unit1/final-quiz
title: 第 1 單元總測驗
- local: unit1/conclusion
title: 結語
- title: 第 2 單元:AI agent 框架
sections:
- local: unit2/introduction
title: AI agent 框架
- title: 第 2.1 單元:smolagents 框架
sections:
- local: unit2/smolagents/introduction
title: smolagents 簡介
- local: unit2/smolagents/why_use_smolagents
title: 為什麼使用 smolagents?
- local: unit2/smolagents/quiz1
title: 隨堂測驗 1
- local: unit2/smolagents/code_agents
title: 建立使用程式碼的 agent
- local: unit2/smolagents/tool_calling_agents
title: 以程式碼片段或 JSON 撰寫行動
- local: unit2/smolagents/tools
title: 工具
- local: unit2/smolagents/retrieval_agents
title: 檢索 agent
- local: unit2/smolagents/quiz2
title: 隨堂測驗 2
- local: unit2/smolagents/multi_agent_systems
title: 多 agent 系統
- local: unit2/smolagents/vision_agents
title: 視覺與瀏覽器 agent
- local: unit2/smolagents/final_quiz
title: 總測驗
- local: unit2/smolagents/conclusion
title: 結語
- title: 第 2.2 單元:LlamaIndex 框架
sections:
- local: unit2/llama-index/introduction
title: LlamaIndex 簡介
- local: unit2/llama-index/llama-hub
title: LlamaHub 簡介
- local: unit2/llama-index/components
title: LlamaIndex 中的元件是什麼?
- local: unit2/llama-index/tools
title: 在 LlamaIndex 中使用工具
- local: unit2/llama-index/quiz1
title: 隨堂測驗 1
- local: unit2/llama-index/agents
title: 在 LlamaIndex 中使用 agent
- local: unit2/llama-index/workflows
title: 在 LlamaIndex 中建立 agentic 工作流程
- local: unit2/llama-index/quiz2
title: 隨堂測驗 2
- local: unit2/llama-index/conclusion
title: 結語
- title: 第 2.3 單元:LangGraph 框架
sections:
- local: unit2/langgraph/introduction
title: LangGraph 簡介
- local: unit2/langgraph/when_to_use_langgraph
title: 什麼是 LangGraph?
- local: unit2/langgraph/building_blocks
title: LangGraph 的基本元件
- local: unit2/langgraph/first_graph
title: 建立第一個 LangGraph
- local: unit2/langgraph/document_analysis_agent
title: 文件分析圖
- local: unit2/langgraph/quiz1
title: 隨堂測驗 1
- local: unit2/langgraph/conclusion
title: 結語
- title: 第 3 單元:Agentic RAG 應用案例
sections:
- local: unit3/agentic-rag/introduction
title: Agentic RAG 應用案例簡介
- local: unit3/agentic-rag/agentic-rag
title: Agentic 檢索增強生成(RAG)
- local: unit3/agentic-rag/invitees
title: 為賓客故事建立 RAG 工具
- local: unit3/agentic-rag/tools
title: 為 agent 建立並整合工具
- local: unit3/agentic-rag/agent
title: 建立晚宴 agent
- local: unit3/agentic-rag/conclusion
title: 結語
- title: 第 4 單元:期末專案——建立、測試並認證你的 agent
sections:
- local: unit4/introduction
title: 最後一個單元簡介
- local: unit4/what-is-gaia
title: 什麼是 GAIA?
- local: unit4/hands-on
title: 期末實作
- local: unit4/get-your-certificate
title: 取得卓越證書
- local: unit4/conclusion
title: 課程結語
- local: unit4/additional-readings
title: 接下來該學什麼?
- title: 加碼單元 1:微調 LLM 以支援函式呼叫
sections:
- local: bonus-unit1/introduction
title: 簡介
- local: bonus-unit1/what-is-function-calling
title: 什麼是函式呼叫?
- local: bonus-unit1/fine-tuning
title: 微調模型以支援函式呼叫
- local: bonus-unit1/conclusion
title: 結語
- title: 加碼單元 2:agent 可觀測性與評估
sections:
- local: bonus-unit2/introduction
title: 簡介
- local: bonus-unit2/what-is-agent-observability-and-evaluation
title: 什麼是 agent 可觀測性與評估?
- local: bonus-unit2/monitoring-and-evaluating-agents-notebook
title: 監控與評估 agent
- local: bonus-unit2/quiz
title: 測驗
- title: 加碼單元 3:寶可夢遊戲中的 agent
sections:
- local: bonus-unit3/introduction
title: 簡介
- local: bonus-unit3/state-of-art
title: 在遊戲中運用 LLM 的最新進展
- local: bonus-unit3/from-llm-to-agents
title: 從 LLM 到 AI agent
- local: bonus-unit3/building_your_pokemon_agent
title: 建立自己的寶可夢對戰 agent
- local: bonus-unit3/launching_agent_battle
title: 啟動寶可夢對戰 agent
- local: bonus-unit3/conclusion
title: 結語
13 changes: 13 additions & 0 deletions units/zh-TW/bonus-unit1/conclusion.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 結語 [[conclusion]]

恭喜你完成第一個附加單元 🥳

你已經**了解函式呼叫的原理,也學會如何微調模型,讓它具備函式呼叫能力**!

接下來,我們建議你試著**微調不同的模型**。**親自嘗試,就是最好的學習方式。**

在下一個單元,你將學習使用 **`smolagents`、`LlamaIndex` 和 `LangGraph` 等先進框架**。

最後,我們很想**聽聽你對課程的想法,以及有哪些地方可以改進**。如果你有任何建議,請 👉 [填寫這份表單](https://docs.google.com/forms/d/e/1FAIpQLSe9VaONn0eglax0uTwi29rIn4tM7H2sYmmybmG5jJNlE5v0xA/viewform?usp=dialog)

### 持續學習,繼續發光 🤗
48 changes: 48 additions & 0 deletions units/zh-TW/bonus-unit1/fine-tuning.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 微調模型,讓它學會函式呼叫

現在,我們準備好微調第一個具備函式呼叫能力的模型了 🔥。

## 如何訓練模型進行函式呼叫?

> 答案:我們需要**資料**

模型訓練可以分成 3 個步驟:

1. **先以大量資料預訓練模型**,得到**預訓練模型**,例如 [google/gemma-2-2b](https://huggingface.co/google/gemma-2-2b)。這是基礎模型,只會**預測下一個 token,還不太能遵循指令**。

2. 為了用於對話,模型接著需要經過**微調**,學會遵循指令。這一步可以由模型開發者、開源社群、你,或任何人來訓練。例如,[google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it) 就是 Gemma 專案的 Google 團隊完成指令微調的模型。

3. 接著,可以讓模型**對齊**開發者的偏好。例如,客服聊天模型必須始終禮貌地對待客戶。

通常,Gemini 或 Mistral 這類完整產品**會經過全部 3 個步驟**;你在 Hugging Face 上找到的模型,則可能完成了其中一個或多個步驟。

在本教學中,我們會以 [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it) 為基礎,建立函式呼叫模型。我們選擇經過微調的 [google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it),而非基礎模型 [google/gemma-2-2b](https://huggingface.co/google/gemma-2-2b),因為微調後的模型更適合我們的使用情境。

如果從預訓練模型開始,**就需要更多訓練,才能學會遵循指令、對話,以及函式呼叫**。

從完成指令微調的模型開始,**就能盡量減少模型還需要學習的資訊量**。

## LoRA(大型語言模型的低秩適應)

LoRA 是一種常見的輕量訓練技術,能大幅**減少需要訓練的參數數量**。

它的做法是**在待訓練的模型中插入少量新權重,作為 adapter(適配器)**。這讓 LoRA 訓練更快、更節省記憶體,產生的模型權重也更小(數百 MB),便於儲存與分享。

<img src="https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/unit1/blog_multi-lora-serving_LoRA.gif" alt="LoRA inference" width="50%"/>

LoRA 會在 Transformer 層中加入成對的秩分解矩陣,通常以線性層為主。訓練時,我們會「凍結」模型的其餘部分,只更新新增 adapter 的權重。

因為只需要更新 adapter 的權重,需要訓練的**參數**數量就能大幅減少。

推論時,輸入會送入 adapter 和基礎模型;也可以先將 adapter 的權重合併到基礎模型中,這樣就不會增加額外延遲。

LoRA 特別適合讓**大型**語言模型適應特定任務或領域,同時將資源需求控制在可負擔的範圍內,也能減少訓練模型**所需**的記憶體。

如果想進一步了解 LoRA 的運作原理,可以參考這份[教學](https://huggingface.co/learn/nlp-course/chapter11/4?fw=pt)。

## 微調模型,加入函式呼叫能力

你可以在 👉 [這裡](https://huggingface.co/agents-course/notebooks/blob/main/bonus-unit1/bonus-unit1.ipynb) 開啟教學 notebook。

接著點選 [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/#fileId=https://huggingface.co/agents-course/notebooks/blob/main/bonus-unit1/bonus-unit1.ipynb),就能在 Colab Notebook 中執行。

53 changes: 53 additions & 0 deletions units/zh-TW/bonus-unit1/introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 簡介

![附加單元 1 縮圖](https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/bonus-unit1/thumbnail.jpg)

歡迎來到第一個**附加單元**!你將學習**微調大型語言模型(LLM),讓它具備函式呼叫能力**。

對 LLM 而言,函式呼叫正迅速成為一項*必備*技術。

我們在第 1 單元只依靠 prompt 來引導模型;函式呼叫則讓模型在**訓練階段就學會採取行動、解讀觀察結果**,使 AI 更穩健。

> **什麼時候適合學習這個附加單元?**
>
> 本單元為**選修**,內容比第 1 單元進階。你可以現在開始,也可以等透過課程累積更多知識後再回來學習。
>
> 不用擔心,本單元會提供所需的資訊。即使你還不了解微調的內部原理,我們也會帶你認識微調函式呼叫模型的每個核心概念。

如果具備以下知識,學習本單元會更順利:

1. 知道如何使用 Transformers 微調 LLM。如果還不熟悉,請[參考這份教學](https://huggingface.co/learn/nlp-course/chapter3/1?fw=pt)。

2. 知道如何使用 `SFTTrainer` 微調模型。詳情請[參閱這份文件](https://huggingface.co/learn/nlp-course/en/chapter11/1)。

---

## 你將學到什麼

1. **函式呼叫(Function Calling)**
現代 LLM 如何組織對話,讓模型能夠觸發**工具**。

2. **LoRA(低秩適應)**
一種**輕量、高效率**的微調方法,能減少運算與儲存需求。LoRA 讓大型模型的訓練*更快、成本更低,也更容易*部署。

3. **函式呼叫模型中的思考 → 行動 → 觀察循環**
以簡單而強大的方式,組織模型決定何時及如何呼叫函式、追蹤中間步驟,以及解讀外部工具或 API 結果的流程。

4. **新的特殊 token**
我們會介紹**特殊標記**,幫助模型區分:
- 內部的「思維鏈」推理
- 對外發出的函式呼叫
- 外部工具回傳的回應

---

完成本附加單元後,你將能夠:

- **了解**工具相關 API 的內部運作原理。
- 使用 LoRA 技術**微調**模型。
- **實作**與**修改**思考 → 行動 → 觀察循環,建立穩健、容易維護的函式呼叫工作流程。
- **設計與使用**特殊 token,明確區分模型的內部推理與對外行動。

你也將**親手微調出具備函式呼叫能力的模型。** 🔥

一起來認識**函式呼叫**吧!
77 changes: 77 additions & 0 deletions units/zh-TW/bonus-unit1/what-is-function-calling.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# 什麼是函式呼叫?

函式呼叫是 **LLM 對環境採取行動的一種方式**。這項功能最早[於 GPT-4 推出](https://openai.com/index/function-calling-and-other-api-updates/),後來其他模型也陸續採用。

如同 agent 使用工具,函式呼叫讓模型能夠**對環境採取行動**。不過,函式呼叫能力是**模型透過學習取得的**,**對 prompt 的依賴比其他 agent 技術更少**。

在第 1 單元,agent **並未經過使用工具的訓練**。我們只是提供工具清單,再仰賴模型**將既有能力泛化,規劃如何使用這些工具**。

這裡則會**透過微調(訓練),讓 agent 學會使用工具,進行函式呼叫**。

## 模型如何「學會」採取行動?

在第 1 單元,我們探討過 agent 的一般工作流程。使用者提供工具,再以查詢作為 prompt 後,模型便會重複以下循環:

1. *思考*:為了達成目標,需要採取哪些行動?
2. *行動*:以正確的參數格式輸出行動,然後停止生成。
3. *觀察*:取得執行結果。

透過 API 與模型進行「一般」對話時,使用者與助理的訊息會交替出現,如下所示:

```python
conversation = [
{"role": "user", "content": "I need help with my order"},
{"role": "assistant", "content": "I'd be happy to help. Could you provide your order number?"},
{"role": "user", "content": "It's ORDER-123"},
]
```

函式呼叫為對話帶來了**新的角色**!

1. 一個代表**行動**的新角色
2. 一個代表**觀察**的新角色

以 [Mistral API](https://docs.mistral.ai/capabilities/function_calling/) 為例,對話會像這樣:

```python
conversation = [
{
"role": "user",
"content": "What's the status of my transaction T1001?"
},
{
"role": "assistant",
"content": "",
"function_call": {
"name": "retrieve_payment_status",
"arguments": "{\"transaction_id\": \"T1001\"}"
}
},
{
"role": "tool",
"name": "retrieve_payment_status",
"content": "{\"status\": \"Paid\"}"
},
{
"role": "assistant",
"content": "Your transaction T1001 has been successfully paid."
}
]
```

> ……可是,你不是說函式呼叫會有新的角色嗎?

**是,也不完全是。** 在這個例子和許多其他 API 中,模型會將要採取的行動格式化為「assistant」訊息。聊天範本接著會以函式呼叫的**特殊 token** 表示它。

- `[AVAILABLE_TOOLS]` – 可用工具清單的起點
- `[/AVAILABLE_TOOLS]` – 可用工具清單的終點
- `[TOOL_CALLS]` – 呼叫工具(也就是採取「行動」)
- `[TOOL_RESULTS]` – 「觀察」行動結果
- `[/TOOL_RESULTS]` – 觀察結束(模型可以再次解碼)

課程後續還會談到函式呼叫。如果想深入了解,也可以參閱[這份詳盡的文件](https://docs.mistral.ai/capabilities/function_calling/)。

---
現在,我們已經了解函式呼叫的概念與運作方式。接下來,要在模型中加入新的特殊 token,**讓原本還不具備這項能力的模型學會函式呼叫**:[google/gemma-2-2b-it](https://huggingface.co/google/gemma-2-2b-it)。

在開始之前,**我們得先了解微調與 LoRA**。
Loading