Skip to content

Add function calling and MCP support #1626

Open
@rlouf

Description

@rlouf

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:

  1. While <tool_call> has not been observed, __call__ is a pass-through.
  2. After <tool_call> has been observed, mask the logits to follow a given JSON Schema.
  3. Once the JSON generation has completed, force the generation of </tool_call>
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions