outlines
outlines copied to clipboard
Add function calling and MCP support
A v0 would be allowing users to instantiate the logits processor with the tool call tokens and pass it to the generator. Note that this would only work with models that use simple tokens for tool calling (Llama has a more complex pattern that we can handle later).
model = ...
logits_processor = FunctionCallingLogitsProcessor("<tool_call>", "</tool_call>", Union[User, Customer])
generator = Generator(model, processor=logits_processor)
The implementation is simple:
- While
<tool_call>has not been observed,__call__is a pass-through. - After
<tool_call>has been observed, mask the logits to follow a given JSON Schema. - Once the JSON generation has completed, force the generation of
</tool_call> - Then let the model generate freely,
__call__is a pass-through.
If there are several possible function calls, the type for (2) would be a Union of the different JSON Schemas.
This will be a relief. The lack of function calling support is having me:
- write prompts that work around it using phrasing like
"If you cannot fill this JSON, and only then, answer 'blah' to parameter_1 and 'blah' to parameter_2."- I currently have to do this because the LLM tries its best to provide some values to
parameter_1andparameter_2, even going into its few-shot examples (whereas I need it to pay attention to only the context) if the context doesn't offer something meaningful. If there's a better way of handling this let me know - actually I am opening a new discussion for it: https://github.com/dottxt-ai/outlines/discussions/1651
- I currently have to do this because the LLM tries its best to provide some values to
- have complex control logic when tools were called and when not