The documentation suggests passing a list of tool schemas - and then using the tool_choice
parameter to force the LLM to choose one of them. Isn’t that kind of wasteful in terms of tokens? If you want to use just one tool - then maybe pass just one schema?
For my usage I wrote a wrapper around ‘completions.create’:
def openai_query(self, tool_schemas, force_auto_tool_choice=False):
if len(tool_schemas) == 1 and not force_auto_tool_choice:
tool_choice = tool_choice={'type': 'function', 'function': {'name': tool_schemas[0]['function']['name']}}
else:
tool_choice = "auto"
completion = self.client.chat.completions.create(
model=self.model,
messages=self.prompt.to_messages(),
tools=tool_schemas,
tool_choice=tool_choice
)
return completion
I infer tool_choice
from the number of schemas. To cover all the possible cases I added that force_auto_tool_choice optional parameter that would make it possible for the LLM to choose no function call even when passed a schema with just one tool. For now I don’t need that.
Anything against that wrapper?