-
Notifications
You must be signed in to change notification settings - Fork 9
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
Track and format chat history #9
base: master
Are you sure you want to change the base?
Conversation
148c274
to
b65dc33
Compare
We should download the relevant files from HF. I don't think we can avoid implementing the Jinja2 templates for each model family though. Would need to use regular expressions instead of full names (might be slow).
307f662
to
65546fe
Compare
Given the multiplicity of formats, formatting the prompt for chat workflows with open models can be a real hassle and is error-prone. In this PR we introduce a `Chat` class that allows users to track the conversation and easily print the corresponding prompt.
Jan does this over in the Julia world with PromptingTools.jl, and it's extremely ergonomic. PromptingTools has one of the best interfaces I've seen, so big fan of this. |
It's useful to compare this to The biggest issue I probably have with I do see some advantages in this proposed approach, namely:
Additionally I do like the template example you have in chat. However it seems to me that templating and constructing prompts themselves should be independent from managing the chat/instruct interface? Now if the
Of course this diminishes the generality of the Chat as well. Ideally I'm assuming we would like an instance of Basically the tl;dr here is we should make sure that the value add is pretty strong to justify the user switching from a very well known and well supported data structure (list of dicts) to our custom class. |
Just to give some context, the interface was designed so rendering can be done automatically in from prompts import Chat, user
from outlines import models
openai = models.openai("gpt-4o")
chat = Chat()
chat.system = "You are an AI"
chat += user("Hi!")
result = openai(chat) Where chat.render("openai") is called by the |
Given the multiplicity of formats, formatting the prompt for chat workflows with open models can be a real hassle and is error-prone. In this PR we introduce a
Chat
class that allows users to track the conversation and easily print the corresponding prompt.Closes #4
We can initialize a chat session with an optional system prompt:
This system prompt can always be updated later on:
We can add user and assistant messages to the session:
Adding two successive
user
orassistant
messages will raise an exception. To prevent user errors we will create two typesUser
andAssistant
to replaceMessage("user"
andMessage("assistant"
:We can also easily "fork" discussions:
And finally we can render the conversation using
model
's chat template withNote that before rendering, the
render
method calls an internalfilter
method that can trim the discussion (pass through by default). To implement a memory-less agent you would subclassChat
this way:For vision model we can re-use the
Vision
objects we defined in the new version of Outlines:TODO
user
andassistant
aliases