dottxt-ai / outlines

Structured Text Generation
https://dottxt-ai.github.io/outlines/
Apache License 2.0
9.57k stars 492 forks source link

Multi-functions function calling #1217

Open rlouf opened 1 month ago

rlouf commented 1 month ago

Presentation of the new feature

Outlines can already do simple function calling either by passing a Pydantic model that models the function's signature, or by passing a function. We would like a simple interface to do function calling with multiple functions.

We could for instance pass an Enum to the generating function:

from enum import Enum

def sum(a:int, b:int):
    return a + b

def mul(a: int, b: int):
    return a * b

class Functions(Enum):
    addition = sum
    multiplication = mul 

Where does it fit in Outlines?

Outlines' main appeal is the definition of output types. I think this is a very important use case. We've had to implement it manually several times internally.

Are you willing to open a PR?

Sure.

g-prz commented 4 days ago

Hey @rlouf I'm pretty new on the repo, would like to start contributing and found this issue interesting Based on the open functions section of the readme and to my current understanding, changes would be made in:

Regarding the first item, it seems correlated to this issue as the handling of Enums would be similar (and call to_regex if we encounter an Enum in the choice function)

rlouf commented 4 days ago

You understood well!

g-prz commented 2 days ago

Thanks 🙏 Gonna work on it!