Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Including the Prompt in the Pattern in SequenceGenerator #1122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

JulesGM
Copy link
Contributor

@JulesGM JulesGM commented Aug 28, 2024

Let's say you have a Json schema and you want to generate just a subset of keys from other keys. With the current SequenceGenerator, it's not possible to do that in an easy way.

We add the "include_prompt" argument, where the prompt is included in the pattern.

We just unroll the FSMs with the prompt tokens. We also keep the prompt tokens inside of the output, as they are needed for the output format_sequence call in things like json.

@brandonwillard brandonwillard changed the title >> Add Support for Including the Prompt in the Pattern in SequenceGenerator Add Support for Including the Prompt in the Pattern in SequenceGenerator Aug 28, 2024
state = fsm.get_next_state(state=state, token_id=token_id.item())
if state < 0:
raise ValueError(f"Invalid state {state}")
final_fsm_states.append(state)
Copy link
Contributor

@lapp0 lapp0 Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to implement this as a Guide? I've started work on #531 and I'd like to see Guides become more composable.

Also interegular has functionality built in to make this easy.

>>> import interegular
>>> fsm = interegular.parse_pattern("abcd").to_fsm()
>>> fsm.accepts("abcd")
True
>>> partial_fsm = fsm.derive("ab")
>>> partial_fsm.accepts("abcd")
False
>>> partial_fsm.accepts("cd")
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants