From d1764c5011b6b16947f0e77d72049d7cd0814e84 Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 15 Apr 2024 14:20:29 -0400 Subject: [PATCH 1/3] Update functions.py Syntactic Sugar to make maintenance easier --- functions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/functions.py b/functions.py index 794627a..098fc87 100644 --- a/functions.py +++ b/functions.py @@ -296,7 +296,7 @@ def get_company_profile(symbol: str) -> dict: return {} def get_openai_tools() -> List[dict]: - functions = [ + old_functions = [ code_interpreter, google_search_and_scrape, get_current_stock_price, @@ -309,6 +309,8 @@ def get_openai_tools() -> List[dict]: get_dividend_data, get_technical_indicators ] + ### Should be the same as above + functions = [func for func in dir(__main__) if inspect.isfunction(getattr(__main__, func)) and getattr(__main__, func).__module__ == '__main__'] tools = [convert_to_openai_tool(f) for f in functions] - return tools \ No newline at end of file + return tools From f7589a892424c7cfe665f081aeea341389ea48c7 Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 15 Apr 2024 14:24:01 -0400 Subject: [PATCH 2/3] Update README.md update to match new way to auto-build `functions` list in `functions.py` --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9b51bd..c252c6d 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ def get_new_function(symbol: str) -> dict: return {} ``` -After defining your new function, make sure to add it to the `get_openai_tools()` function in the `functions.py` script: +After defining your new function, make sure it's added to the `functions` array in the `get_openai_tools()` function in the `functions.py` script. ```python def get_openai_tools() -> List[dict]: @@ -77,6 +77,7 @@ def get_openai_tools() -> List[dict]: tools = [convert_to_openai_tool(f) for f in functions] return tools ``` +Note, this should be automatic via some `inspect` syntax but it's worth checking that `old_funtions` and the automatically derived `functions` arrays are the same. This will ensure that your new function is included in the list of available tools for the model to use. From 058af89e370de04f3cff96332fe9fd5ec91a776a Mon Sep 17 00:00:00 2001 From: jay Date: Mon, 15 Apr 2024 14:27:43 -0400 Subject: [PATCH 3/3] Update functions.py Add some error checking --- functions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/functions.py b/functions.py index 098fc87..997b238 100644 --- a/functions.py +++ b/functions.py @@ -311,6 +311,14 @@ def get_openai_tools() -> List[dict]: ] ### Should be the same as above functions = [func for func in dir(__main__) if inspect.isfunction(getattr(__main__, func)) and getattr(__main__, func).__module__ == '__main__'] + + try: + assert ( set(functions) == set(old_functions) ) + except Exception as e: + print(f"Error building automatic `functions` array: {e}") + print(f"It's likely that the function you added is either in a sub-module or has amother issue") + functions = old_functions + pass tools = [convert_to_openai_tool(f) for f in functions] return tools