-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prompt role blocks debug output + new prompt implementation example #578
Prompt role blocks debug output + new prompt implementation example #578
Conversation
Thanks @cpcdoy ! This is great idea. I'll review more closely when I am not on mobile, but one quick thought: could we somehow show the white space? Further thought: I wonder if we should have a "debug()" context that allows everything to act differently in debug mode if it wants, so we could show all the white spaces, perhaps not show the fancy role rows etc. |
Thanks @slundberg! It actually already shows white space (as can be seen in the first screenshot on the For your second point, I actually already thought of the possibility of putting a Lmk what you think and I can make adjustments if needed when I have time this week! |
Alright I dug into a bit today and decided that roles make more sense long term I think. This is because you may want to be able to print out the raw format of guidance functions you didn't write without having to go inside them and find all their role tags. I implemented this with a new with indent_roles(False), system():
lm = orca + "You are a cat expert."
with user():
lm += "What are the smallest cats?"
with assistant():
lm += gen("answer", stop=".", max_tokens=20) It also allows for easy control of more complex functions: with indent_roles(False):
lm += my_complex_function() In the process I flushed out a few ordering bugs about nested contexts. Let me know if this looks good to you. Thanks! |
@cpcdoy I am going to merge this for now so I can use the fixes to context block ordering, but if you want to tweak something later just let me know. thanks again! |
@slundberg Sorry for the late reply, I had quite a busy week and I'm also traveling. I think your approach of using blocks sounds good to me! I'll try it next time I'm debugging a model and will see if I have any feedback! Thanks for the help on this PR :) |
else: | ||
return lm.remove(name) | ||
|
||
def set_var(name, value=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you implemented this approach to set the same values as in the set_attribute
method you did for blocks, but I don't see it used anywhere for now. Is this something you're planning to use later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I just checked your commit history and you were using variables instead of attributes for the blocks before, so maybe a forgotten file, unless you think it's still useful for other purposes?
Description
This PR comes after I wanted to implement a new model prompt and found it could be simpler (discussed in #571)
Implementation
The implementation remains as simple as possible and uses the
kwargs
from each role blocks to pass adebug
variable that then will either wrap each blocks with aNODISP
block to hide the prompt in the HTML output or with aspan
block to display the prompt debug in an orange color.Usage
Let's say we implement a new chat model with its own prompt:
Then we can try the new prompt this way:
It is also possible to only show some parts of the prompt (only
user
or bothsystem
andassistant
blocks for example) to help understand how Guidance is generating the prompt. For example only showing thesystem
block:In practice, this works for all the other blocks too.
Compatibility
There are no compatibility issues since the default usage remains the same as before.
Full Example Usage
I also provide a notebook in the PR that shows how to easily use this to debug a new prompt Chat model implementation. The example implements
Orca mini 3b
from HF Hub.