Files
happy-llm/docs/chapter7/Agent/demo.py
KMnO4-zx 28636a0f9b feat(Agent): 新增维基百科搜索和温度查询工具并实现web界面
- 添加search_wikipedia和get_current_temperature工具函数
- 实现基于Streamlit的web交互界面
- 更新requirements.txt添加相关依赖
- 修复PROMPT_TEMPLATE变量名拼写错误
- 移除不再使用的工具函数
- 添加web界面截图到文档
2025-06-20 12:14:19 +08:00

26 lines
837 B
Python

from src.core import Agent
from src.tools import add, count_letter_in_string, compare, get_current_datetime, search_wikipedia, get_current_temperature
from openai import OpenAI
if __name__ == "__main__":
client = OpenAI(
api_key="your siliconflow api key",
base_url="https://api.siliconflow.cn/v1",
)
agent = Agent(
client=client,
model="Qwen/Qwen2.5-32B-Instruct",
tools=[get_current_datetime, search_wikipedia, get_current_temperature],
)
while True:
# 使用彩色输出区分用户输入和AI回答
prompt = input("\033[94mUser: \033[0m") # 蓝色显示用户输入提示
if prompt == "exit":
break
response = agent.get_completion(prompt)
print("\033[92mAssistant: \033[0m", response) # 绿色显示AI助手回答