ai-python 是做什麼的?
AI SDK for Python(ai 套件)。用於 Python 模型呼叫(LLM、影像、影片、語音、嵌入、轉錄、重新排序或評估)、代理、模型互動測試、工具呼叫、子代理、審批、持久化執行、遙測、AI SDK UI 後端及自訂提供者。
支援的功能
- 模型呼叫:支援 LLM、影像、影片、語音、嵌入、轉錄、重新排序與評估。
- 代理系統:建立 AI 代理,支援工具呼叫與子代理協作。
- 互動測試:測試模型互動與代理行為。
- 審批流程:支援人工審批節點,確保關鍵操作安全。
- 持久化執行:處理長時間任務或狀態維護。
- 遙測:收集使用數據與監控效能。
- UI 後端:整合 AI SDK UI 元件,建立互動式前端。
- 自訂提供者:可擴充至非標準模型或私有部署。
快速開始
安裝套件:
pip install ai
基本使用範例:
from ai import Agent
agent = Agent(
model="gpt-4",
tools=[my_custom_tool],
system_prompt="你是個有用的助手。"
)
response = agent.run("請解釋量子計算。")
print(response.text)
進階使用
如需使用子代理或審批:
from ai import Agent, ApprovalStep
agent = Agent(
model="gpt-4",
sub_agents=[specialist_agent],
steps=[ApprovalStep("需要管理員審批")]
)
平台支援
- Vercel Edge / Serverless:自動整合。
- 本機執行:適用於開發測試。
- 自訂環境:透過提供者介面擴充。
遙測與監控
SDK 內建遙測支援,可與 OpenTelemetry 等工具整合:
from ai import Telemetry
telemetry = Telemetry(enabled=True)
agent = Agent(model="gpt-4", telemetry=telemetry)
更多資源
- 官方文件:前往 Vercel AI SDK 文件
- 範例:檢視
examples/目錄 - 問題回報:GitHub Issues