Skip to content

Commit

Permalink
starting to do tests with guidance
Browse files Browse the repository at this point in the history
  • Loading branch information
parkervg committed Jul 18, 2024
1 parent f547446 commit 97843ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 13 additions & 3 deletions blendsql/generate/regex.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import singledispatch
from typing import Optional, List, Union
import outlines
from guidance import capture, gen

from ..models import Model, OllamaLLM

Expand All @@ -13,8 +13,18 @@ def regex(
max_tokens: Optional[int] = None,
stop_at: Optional[Union[List[str], str]] = None,
) -> str:
generator = outlines.generate.regex(model.model_obj, regex_str=regex)
return generator(prompt, max_tokens=max_tokens, stop_at=stop_at)
print(regex)
regex = "((t|f|-);)((t|f|-);)((t|f|-);)((t|f|-);)"
res = (
model.model_obj
+ prompt
+ capture(
gen(regex=regex, max_tokens=max_tokens or 1e10, stop=stop_at), name="res"
)
)
return res["res"]
# generator = outlines.generate.regex(model.model_obj, regex_str=regex)
# return generator(prompt, max_tokens=max_tokens, stop_at=stop_at)


@regex.register(OllamaLLM)
Expand Down
7 changes: 4 additions & 3 deletions blendsql/models/local/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ def __init__(self, model_name_or_path: str, caching: bool = True, **kwargs):

def _load_model(self) -> ModelObj:
# https://huggingface.co/blog/how-to-generate
from outlines.models import transformers
from guidance.models import Transformers

return transformers(
return Transformers(
self.model_name_or_path,
model_kwargs=self.load_model_kwargs,
echo=False,
**self.load_model_kwargs,
)


Expand Down

0 comments on commit 97843ee

Please sign in to comment.