Migrate call_func from claudette to toolslm #14
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR migrates the call_func logic from claudette to toolslm in order to help with reusability of tool calling across our various LLM API wrappers like cosette. Some changes were made to properly abstract away the specifics of each API provider.
Specifically, call_func now takes in the function name, the function parameters, and a namespace which is required.
Previously, the namespace (if given as 'none') would be created based on globals. However, since imported modules have their own separate namespace from the importer of the module, you would end up missing keys. Therefore, I think it's better to require the caller to actually define the namespace that is going to be searched.
I also moved the helper function for making a namespace given a list of items to here, along with a new function called obj2ns which handles converting objects (like classes) into a proper namespace object.
Previously this was handled differently with class objects where we would only attempt to get the attribute of the object's functions if it existed.
However, I felt that we could abstract this away just into the general concept of having namespaces where we convert objects to namespaces. This simplifies the code greatly, especially when modifying, for example, Claudette to now use this API.