python -m venv .venv source .venv/bin/activate # Windows 使用 .venv\Scripts\activate pip install -U pip pip install langchain langchain-openai langchain-community python-dotenv
from langchain_core.tools import tool
@tool def multiply(a: int, b: int) -> int:
"""计算两个整数的乘积。当用户需要做乘法运算时使用。"""
return a * b
@tool def search_flights(city: str, date: str) -> str:
"""查询指定城市和日期的航班信息。日期格式为 YYYY-MM-DD。"""
return f"{city} 在 {date} 有 3 个航班可选。"