riokorb commited on
Commit
3ca5eac
·
verified ·
1 Parent(s): d954df7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -33,6 +33,31 @@ 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
 
@@ -55,7 +80,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,
 
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
36
+ @tool
37
+ def convert_units(value: float, from_unit: str, to_unit: str) -> str:
38
+ """Converts common units (length, weight, temperature).
39
+ Args:
40
+ value: The numerical value to convert
41
+ from_unit: The original unit (e.g., 'km', 'kg', 'C')
42
+ to_unit: The target unit (e.g., 'miles', 'lb', 'F')
43
+ """
44
+ conversions - {
45
+ ('km', 'miles'): lambda x: x * 0.621371,
46
+ ('miles', 'km'): lambda x: x / 0.621371,
47
+ ('kg', 'lb'): lambda x: x * 2.20462,
48
+ ('lb', 'kg'): lambda x: x / 2.20462,
49
+ ('C', 'F'): lambda x: (x * 9/5) + 32,
50
+ ('F', 'C'): lambda x: (x - 32) * 5/9
51
+ }
52
+ # dictionary which maps (from_unit, to_unit) tuples to simple math functions (lambda) that perform the actual conversion
53
+ try:
54
+ func = conversions[(from_unit.lower(), to_unit.lower())]
55
+ result = func(value)
56
+ return f"(value) {from_unit} = {result:.2f} {to_unit}"
57
+ except KeyError:
58
+ return f"Unsupported conversion from {from_unit} to {to_unit}."
59
+ except Exception as e:
60
+ return f"An unexpected error occurred: {str(e)}"
61
 
62
  final_answer = FinalAnswerTool()
63
 
 
80
 
81
  agent = CodeAgent(
82
  model=model,
83
+ tools=[final_answer, convert_units], ## add your tools here (don't remove final answer)
84
  max_steps=6,
85
  verbosity_level=1,
86
  grammar=None,