Skip to content

Commit

Permalink
Add Index type
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Nov 16, 2023
1 parent 4457886 commit 35611ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion outlines/generate/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

if TYPE_CHECKING:
from outlines.generate.samplers import Sampler
from outlines.index.index import Index


@dataclass
Expand All @@ -15,7 +16,7 @@ class GenerationState:
kv_cache: Optional[torch.Tensor] = None


def process(generator: Generator, index, state: GenerationState):
def process(generator: Generator, index: "Index", state: GenerationState):
"""This generator drives the text generation process by
walking through the FSM."""
next(generator)
Expand Down
11 changes: 11 additions & 0 deletions outlines/index/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Callable, NamedTuple, NewType

import torch

State = NewType("State", int)


class Index(NamedTuple):
next_instruction: Callable[[State], torch.Tensor]
next_state: Callable[[State, torch.Tensor], State]
is_final: Callable[[State], bool]

0 comments on commit 35611ab

Please sign in to comment.