Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify functions array #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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.

Expand Down
14 changes: 12 additions & 2 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -309,6 +309,16 @@ 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__']

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
return tools