Spaces:
Sleeping
Sleeping
Add tools for computing age of the univers
Browse files
app.py
CHANGED
|
@@ -4,19 +4,95 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
arg1: the
|
| 17 |
-
arg2: the
|
| 18 |
"""
|
| 19 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +131,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,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import numpy as np
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def get_age_univers(arg1:datetime, arg2:float)-> str: #it's import to specify the return type
|
| 14 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 15 |
+
"""A tool that computes the age of a universe in a given date based on the vacuum energy
|
| 16 |
Args:
|
| 17 |
+
arg1: the date on which we want to compute the age of the univers
|
| 18 |
+
arg2: the vacuum energy in GeV
|
| 19 |
"""
|
| 20 |
+
return "The age of the universe is 14 point 5 billion years"
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def compute_vacuum_energy(L: float, N_max: int, hbar: float=1.0545718e-34, c: float=3e8)->float:
|
| 24 |
+
"""
|
| 25 |
+
Compute the vacuum (zero-point) energy of a scalar field in a 3D box.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
L: Length of the cubic box in meters.
|
| 29 |
+
N_max: Maximum mode number in each direction (for cutoff/regularization).
|
| 30 |
+
hbar: Reduced Planck constant (default is SI units).
|
| 31 |
+
c: Speed of light (default is SI units).
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
float: Total vacuum energy in joules.
|
| 35 |
+
"""
|
| 36 |
+
energy = 0.0
|
| 37 |
+
|
| 38 |
+
for nx in range(1, N_max + 1):
|
| 39 |
+
for ny in range(1, N_max + 1):
|
| 40 |
+
for nz in range(1, N_max + 1):
|
| 41 |
+
# Compute magnitude of k-vector
|
| 42 |
+
k = np.pi * np.sqrt(nx**2 + ny**2 + nz**2) / L
|
| 43 |
+
omega = c * k
|
| 44 |
+
energy += 0.5 * hbar * omega
|
| 45 |
+
|
| 46 |
+
return energy
|
| 47 |
+
|
| 48 |
+
def convert_energy(value: float, current_unit: str, target_unit: str) -> float:
|
| 49 |
+
"""
|
| 50 |
+
Convert an energy value from one unit to another.
|
| 51 |
+
|
| 52 |
+
Parameters:
|
| 53 |
+
value: The energy value to convert.
|
| 54 |
+
current_unit: The unit of the input energy (e.g., 'J', 'eV', 'GeV', 'kcal', 'kWh').
|
| 55 |
+
target_unit: The desired output unit.
|
| 56 |
+
|
| 57 |
+
Returns:
|
| 58 |
+
float: The converted energy value in the target unit.
|
| 59 |
+
|
| 60 |
+
Supported units:
|
| 61 |
+
- 'J' : Joules
|
| 62 |
+
- 'eV' : Electronvolts
|
| 63 |
+
- 'GeV' : Giga-electronvolts
|
| 64 |
+
- 'kcal' : Kilocalories
|
| 65 |
+
- 'kWh' : Kilowatt-hours
|
| 66 |
+
"""
|
| 67 |
+
UNIT_EQUIVALENT_IN_JOULES: dict[str, float] = {
|
| 68 |
+
'j': 1.0,
|
| 69 |
+
'ev': 1.602176634e-19,
|
| 70 |
+
'gev': 1.602176634e-10,
|
| 71 |
+
'kcal': 4184.0,
|
| 72 |
+
'kwh': 3.6e6,
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
current_unit = current_unit.strip().lower()
|
| 76 |
+
target_unit = target_unit.strip().lower()
|
| 77 |
+
|
| 78 |
+
supported_units = list(UNIT_EQUIVALENT_IN_JOULES.keys())
|
| 79 |
+
|
| 80 |
+
if current_unit not in UNIT_EQUIVALENT_IN_JOULES:
|
| 81 |
+
raise ValueError(
|
| 82 |
+
f"Unsupported current unit: '{current_unit}'.\n"
|
| 83 |
+
f"Supported units are: {', '.join(supported_units)}"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
if target_unit not in UNIT_EQUIVALENT_IN_JOULES:
|
| 87 |
+
raise ValueError(
|
| 88 |
+
f"Unsupported target unit: '{target_unit}'.\n"
|
| 89 |
+
f"Supported units are: {', '.join(supported_units)}"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
value_in_joules = value * UNIT_EQUIVALENT_IN_JOULES[current_unit]
|
| 93 |
+
converted_value = value_in_joules / UNIT_EQUIVALENT_IN_JOULES[target_unit]
|
| 94 |
+
return converted_value
|
| 95 |
+
|
| 96 |
|
| 97 |
@tool
|
| 98 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 131 |
|
| 132 |
agent = CodeAgent(
|
| 133 |
model=model,
|
| 134 |
+
tools=[final_answer, get_age_univers, get_current_time_in_timezone, convert_energy, compute_vacuum_energy], ## add your tools here (don't remove final answer)
|
| 135 |
max_steps=6,
|
| 136 |
verbosity_level=1,
|
| 137 |
grammar=None,
|