Spaces:
Sleeping
Sleeping
Add a tool, get_system_info.
Browse files
app.py
CHANGED
|
@@ -18,6 +18,33 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -55,7 +82,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
|
| 22 |
+
import os
|
| 23 |
+
from datetime import datetime
|
| 24 |
+
# from langchain_core.tools import tool
|
| 25 |
+
|
| 26 |
+
@tool
|
| 27 |
+
def get_system_info() -> str:
|
| 28 |
+
"""获取当前系统的实时信息,包括时间、磁盘使用、进程数等。
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
_: 无参数,直接调用
|
| 32 |
+
"""
|
| 33 |
+
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 34 |
+
disk = os.statvfs("/")
|
| 35 |
+
total_gb = (disk.f_blocks * disk.f_frsize) / 1024**3
|
| 36 |
+
free_gb = (disk.f_bavail * disk.f_frsize) / 1024**3
|
| 37 |
+
cpu_count = os.cpu_count()
|
| 38 |
+
pid_count = len(os.listdir("/proc")) if os.path.exists("/proc") else "N/A"
|
| 39 |
+
|
| 40 |
+
return (
|
| 41 |
+
f"当前时间: {now}\n"
|
| 42 |
+
f"磁盘总量: {total_gb:.1f} GB, 可用: {free_gb:.1f} GB\n"
|
| 43 |
+
f"CPU 核心数: {cpu_count}\n"
|
| 44 |
+
f"当前进程数: {pid_count}"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
@tool
|
| 49 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 50 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 82 |
|
| 83 |
agent = CodeAgent(
|
| 84 |
model=model,
|
| 85 |
+
tools=[final_answer, get_system_info], ## add your tools here (don't remove final answer)
|
| 86 |
max_steps=6,
|
| 87 |
verbosity_level=1,
|
| 88 |
grammar=None,
|