From 6b42931cb5022c46c784ead5f20b2c317dce02a7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 31 May 2024 22:35:17 -0700 Subject: [PATCH] enh: better fc example --- examples/function_calling_filter_pipeline.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/function_calling_filter_pipeline.py b/examples/function_calling_filter_pipeline.py index 7367e65..595cc51 100644 --- a/examples/function_calling_filter_pipeline.py +++ b/examples/function_calling_filter_pipeline.py @@ -77,12 +77,21 @@ And answer according to the language of the user's question.""", print(location, unit) return f"{location}: Sunny" - def get_user_name(self, user_id: str) -> str: + def calculator(self, equation: str) -> str: """ - Get the user's name from the user_id. + Calculate the result of an equation. + + :param equation: The equation to calculate. """ - print(user_id) - return "John Doe" + + # Avoid using eval in production code + # https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html + try: + result = eval(equation) + return f"{equation} = {result}" + except Exception as e: + print(e) + return "Invalid equation" self.functions = Functions()