refined tool use
This commit is contained in:
@@ -7,42 +7,37 @@ import math_interpreter
|
||||
import utils
|
||||
|
||||
|
||||
@tool
|
||||
def current_time():
|
||||
"""Get the current local date and time as a string."""
|
||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||
# @tool
|
||||
# def current_time():
|
||||
# """Get the current local date and time as a string."""
|
||||
# # return datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
|
||||
# return f"The current local date and time is {datetime.datetime.now().strftime('%Y-%m-%d %H:%M %p')}."
|
||||
|
||||
@tool
|
||||
def random_float():
|
||||
"""Generate a random float from 0..1."""
|
||||
return str(random.random())
|
||||
|
||||
# @tool
|
||||
# def random_float(a: float=0.0, b: float=1.0):
|
||||
# """Generate a random float in range [a, b], including both end points. Optional pass no parameter and range 0..1 will be used.
|
||||
# Args:
|
||||
# a: minimum possible value
|
||||
# b: maximum possible value"""
|
||||
# return str(random.randint(a, b))
|
||||
# def random_float():
|
||||
# """Generate a random float in range 0 to 1."""
|
||||
# # return str(random.random())
|
||||
# return f"The freshly generated a random number from 0..1 is: {random.random():.5f}."
|
||||
|
||||
|
||||
@tool
|
||||
def random_int(a: int, b: int):
|
||||
"""Generate a random integer in range [a, b], including both end points.
|
||||
Args:
|
||||
a: minimum possible value
|
||||
b: maximum possible value"""
|
||||
return str(random.randint(a, b))
|
||||
# @tool
|
||||
# def random_int(a: int, b: int):
|
||||
# """Generate a random integer in the range [a, b], including both end points.
|
||||
# Args:
|
||||
# a: minimum possible value (must be <= b)
|
||||
# b: maximum possible value (must be >= a)"""
|
||||
# # return str(random.randint(a, b))
|
||||
# return f"A fresh generated random integer between {a} and {b} is {random.randint(a, b)}."
|
||||
|
||||
|
||||
|
||||
|
||||
@tool
|
||||
def math_evaluate(expression: str):
|
||||
"""evaluate and reduce a mathematical expression.
|
||||
"""Evaluate and simplify a mathematical expression. Returns the evaluated result or a simplified version of the expression as a string.
|
||||
Args:
|
||||
expression: Reduce mathematic expression (without '=') algebraically.
|
||||
"""
|
||||
expression: A valid arithmetic expression (e.g., '2 + 3 * 4'). The expression must not contain '='."""
|
||||
try:
|
||||
tokens = math_lexer.tokenize(expression)
|
||||
parser = math_ast.Parser()
|
||||
@@ -55,11 +50,10 @@ Args:
|
||||
|
||||
@tool
|
||||
def math_solve(equations: list[str], variables: list[str]):
|
||||
"""evaluate a mathematical equation system and solve equation systems.
|
||||
"""Solve a system of linear or non-linear equation system. Returns the solutions as a string, or an error message if the input is invalid or unsolvable.
|
||||
Args:
|
||||
equations: list of mathematical equations containing a '='.
|
||||
variables: list of variables to solve for. Must be lower or equal the number of given equations.
|
||||
"""
|
||||
equations: A list of mathematical equations in the format 'x + y = 2'.
|
||||
variables: A list of variables to solve for. The number of variables must not exceed the number of equations."""
|
||||
try:
|
||||
expression = "solve " + " and ".join(equations) + " for " + " and ".join(variables)
|
||||
print(expression)
|
||||
|
Reference in New Issue
Block a user