Skip to content

Correctly escaping stopping strings? #130

Answered by slundberg
andysalerno asked this question in Q&A
Discussion options

You must be logged in to vote

Good questions.

First, you escape stopping strings the same way you escape strings in Python (double escaping when you are writing the guidance code inside another string). The literals in Guidance code are parsed with Python's ast.literal_eval function, so anything that function can handle you can use:
https://github.com/microsoft/guidance/blob/d2d37949c2a552995e2be5f8c3cdd0fe7f05ea79/guidance/_program_executor.py#L184-L188

As for token healing, no. Stop strings are tested against the growing string as decoded by the decoder. For OpenAI the endpoint handles this or Guidance depending on if you are using a regex or not. For Transformers you can see the regex stopping code here:

https://gi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@andysalerno
Comment options

@andysalerno
Comment options

Answer selected by andysalerno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants