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

Prepare outlines to use outlines-core v0.2 #1380

Open
torymur opened this issue Jan 17, 2025 · 0 comments · May be fixed by #1386
Open

Prepare outlines to use outlines-core v0.2 #1380

torymur opened this issue Jan 17, 2025 · 0 comments · May be fixed by #1386
Assignees

Comments

@torymur
Copy link
Contributor

torymur commented Jan 17, 2025

outlines-core v0.2 introduces major interface changes, which require additional work on the outlines side.

Currently in outlines we're importing these from outlines_core:

from outlines_core.fsm.guide import Generate
from outlines_core.fsm.guide import Guide as CoreGuide
from outlines_core.fsm.guide import RegexGuide as CoreRegexGuide
from outlines_core.fsm.guide import Write
from outlines_core.fsm.guide import (
    create_states_mapping as uncached_create_states_mapping,
)

Now we're providing interfaces and usage like:

import json

from outlines_core.json_schema import build_regex_from_schema
from outlines_core.fsm.guide import Guide, Index, Vocabulary

schema =  {
  "title": "Foo",
  "type": "object",
  "properties": {"date": {"type": "string", "format": "date"}}
}
regex = build_regex_from_schema(json.dumps(schema))

vocabulary = Vocabulary.from_pretrained("openai-community/gpt2")
index = Index(regex, vocabulary)
guide = Guide(index)

# Get current state of the Guide:
current_state = guide.get_state()

# Get allowed tokens for the current state of the Guide:
allowed_tokens = guide.get_tokens()

# Advance Guide to the next state via some token_id and return allowed tokens for that new state:
next_allowed_tokens = guide.advance(allowed_tokens[-1])

# To check if Guide is finished:
guide.is_finished()

# If it's finished then this assertion holds:
assert guide.get_tokens() == [vocabulary.get_eos_token_id()]

More interface details for Vocabulary, Index and Guide will be available at: https://github.com/dottxt-ai/outlines-core/blob/main/python/outlines_core/outlines_core_rs.pyi

Some previously imported structures like Write and Generate might make sense to move back to outlines and adapt them, if they'll be used in other Guides. How best to proceed there is open for discussion.

@yvan-sraka yvan-sraka linked a pull request Jan 22, 2025 that will close this issue
@yvan-sraka yvan-sraka linked a pull request Jan 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants