Skip to content

Commit

Permalink
remove deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 22, 2024
1 parent e8c50b5 commit 2cbf08f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 48 deletions.
7 changes: 5 additions & 2 deletions parser/src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ impl Constraint {
Ok(CommitResult::from_step_result(&self.last_res))
}

/// commit_token() is a top-level method in this file and is called indirectly via
/// the advance_parser() method of the LLIinterpreter trait in py.rs.
/// commit_token() is a top-level method in this file and is called by
/// the LLInterpreter::commit_token().
///
/// commit_token() commits the sampled token (if any), and sees if this forces any more tokens
/// on the output (if ff_tokens are enabled in InferenceCapabilities).
///
/// It only returns 'STOP' if previous compute_mask() already returned 'STOP'
/// (in which case there's little point calling commit_token()).
pub fn commit_token(&mut self, sampled_token: Option<TokenId>) -> Result<CommitResult> {
loginfo!(self.parser.logger, "\ncommit_token({:?})", sampled_token);

Expand Down
2 changes: 1 addition & 1 deletion parser/src/earley/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl ParserState {

// apply_tokens() "pushes" the bytes in 'tokens' into the lexer and parser. It is a top-level
// method in this file. It is well below llguidance's top-level methods, but in the llguidance
// LLInterpreter interface, it is called indirectly via the advance_parser() method.
// LLInterpreter interface, it is called indirectly via the commit_token() method.
pub fn apply_token(&mut self, shared: &mut SharedState, tok_bytes: &[u8]) -> Result<usize> {
self.assert_definitive();

Expand Down
6 changes: 3 additions & 3 deletions parser/src/tokenparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl TokenParser {

// advance_parser() is a top-level method in this file.
// This advance_parser() is called by Constraint::commit_token().
// It is accessible via the advance_parser() method of
// It is accessible via the commit_token() method of
// the LLInterpreter interface.
//
// The result here *never* includes a mask.
Expand All @@ -282,9 +282,9 @@ impl TokenParser {

// mid_process() is a top-level method in this file.
// mid_process() is called by Constraint::commit_token().
// It is also be called by TokenParser::advance_parser()
// It is also be called by TokenParser::commit_token()
// within this file, in which case it is accessible
// via the advance_parser() method of the LLInterpreter interface.
// via the commit_token() method of the LLInterpreter interface.
pub fn mid_process(&mut self, mut arg: StepArg) -> StepResult {
assert!(self.is_fresh == false, "process_prompt() not called");

Expand Down
21 changes: 0 additions & 21 deletions python/llguidance/_lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,6 @@ class LLInterpreter:
If true, next compute_mask() call will return stop
"""

# deprecated:

def post_process(
self, sampled_token: Optional[TokenId]
) -> Tuple[int, List[TokenId]]:
"""
Deprecated: use commit_token() instead.
"""

def advance_parser(
self, sampled_token: Optional[TokenId]
) -> Tuple[int, List[TokenId]]:
"""
Deprecated: use commit_token() instead.
"""

def mid_process(self) -> Tuple[Optional[bytes], str]:
"""
Deprecated: use compute_mask() instead.
"""

class JsonCompiler:
def __new__(
cls,
Expand Down
21 changes: 0 additions & 21 deletions rust/src/py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ impl LLInterpreter {
self.inner.process_prompt(prompt)
}

// deprecated
fn mid_process(&mut self, py: Python<'_>) -> PyResult<(Option<Cow<[u8]>>, String)> {
self.compute_mask(py)
}

fn compute_mask(&mut self, py: Python<'_>) -> PyResult<(Option<Cow<[u8]>>, String)> {
let r = py
.allow_threads(|| self.inner.compute_mask())
Expand Down Expand Up @@ -115,17 +110,6 @@ impl LLInterpreter {
}
}

// deprecated
fn advance_parser(&mut self, sampled_token: Option<TokenId>) -> PyResult<(u32, Vec<TokenId>)> {
let pres = self.inner.commit_token(sampled_token).map_err(val_error)?;
if pres.stop {
// let the next mid_process deal with it
Ok((0, vec![]))
} else {
Ok((pres.backtrack, pres.ff_tokens))
}
}

fn commit_token(
&mut self,
sampled_token: Option<TokenId>,
Expand All @@ -139,11 +123,6 @@ impl LLInterpreter {
}
}

// deprecated
fn post_process(&mut self, sampled_token: Option<TokenId>) -> PyResult<(u32, Vec<TokenId>)> {
self.advance_parser(sampled_token)
}

fn has_pending_stop(&self) -> bool {
self.inner.has_pending_stop()
}
Expand Down

0 comments on commit 2cbf08f

Please sign in to comment.