ieixx commited on
Commit
13bfaaf
·
verified ·
1 Parent(s): 8c5c24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py CHANGED
@@ -33,6 +33,34 @@ def get_current_time_in_timezone(timezone: str) -> str:
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
38
 
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def unit_converter(value: float, from_unit: str, to_unit: str) -> str:
38
+ """通用单位转换工具(支持长度、重量、温度)
39
+ Args:
40
+ value: 要转换的数值
41
+ from_unit: 原单位(支持:m, km, kg, g, °C, °F等)
42
+ to_unit: 目标单位
43
+ """
44
+ try:
45
+ # 长度转换
46
+ if {from_unit, to_unit} <= {"m", "km"}:
47
+ factor = 0.001 if from_unit == "m" else 1000
48
+ return f"{value}{from_unit} = {value*factor}{to_unit}"
49
+
50
+ # 重量转换
51
+ if {from_unit, to_unit} <= {"kg", "g"}:
52
+ factor = 1000 if from_unit == "kg" else 0.001
53
+ return f"{value}{from_unit} = {value*factor}{to_unit}"
54
+
55
+ # 温度转换
56
+ if from_unit == "°C" and to_unit == "°F":
57
+ return f"{value}°C = {value*9/5+32}°F"
58
+ if from_unit == "°F" and to_unit == "°C":
59
+ return f"{value}°F = {(value-32)*5/9}°C"
60
+
61
+ return "暂不支持该单位转换"
62
+ except Exception as e:
63
+ return f"单位转换失败:{str(e)}"
64
 
65
  final_answer = FinalAnswerTool()
66