為工具使用定義函式
你目前在一家 SaaS(software as a service)公司工作,目標是推出能幫助組織各層員工做出以資料為本決策的工具。你正在為一個應用程式建立 PoC,讓客戶成功經理可以用自然語言與公司資料互動,擷取關鍵的客戶資訊。
你已獲得一個名為 customers 的 pandas DataFrame,內含少量的客戶資料樣本。這個專案的第一步,是定義一個 Python 函式,能在給定客戶名稱時,從這個資料表擷取資訊。pandas 已經以 pd 匯入。
本練習屬於課程
使用 LangChain 開發 LLM 應用
練習說明
- 定義一個
retrieve_customer_info()函式,接受字串引數name。 - 篩選
customersDataFrame,回傳"name"等於輸入引數name的列。 - 以客戶名稱
"Peak Performance Co."呼叫該函式。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Define a function to retrieve customer info by-name
def retrieve_customer_info(____: ____) -> str:
"""Retrieve customer information based on their name."""
# Filter customers for the customer's name
customer_info = customers[customers['name'] == ____]
return customer_info.to_string()
# Call the function on Peak Performance Co.
print(retrieve_customer_info("____"))