You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I often find I want to add scafolding to an agent/prompt it in multiple stages. Currently this requires writing custom solvers to add the subsequent user messages (prompt_template only works for the first message). This is the usecase I'm thinking of is something like this
chain(
system_message("You are a math expert."),
user_message("How would you go about solving 3x^2+2x+1=10?"),
generate(),
user_message("Now solve for x."),
generate(),
user_message("What is your final answer for x?"),
generate()
)
The implementation would be pretty simlar to system_message. Perhaps something like this
@solverdefuser_message(template: str, **params: Any) ->Solver:
"""Solver which appends a user message to the conversation. User message template containing any number of optional `params`. for substitution. All values contained in sample `metadata` are also automatically included in the `params`. Args: template (str): Template for user message. **params (dict[str,Any]): Parameters to fill into the template. Returns: A solver that appends the parameterised user message. """# read templatecontent=resource(template)
asyncdefsolve(state: TaskState, generate: Generate) ->TaskState:
kwargs=state.metadata|paramsstate.messages.append(
ChatMessageUser(content=content.format(**kwargs))
)
returnstatereturnsolve
I could also see a usecase for wanting assistant_message and tool_message solvers as well that simply append the relevent message type. This is somwhat similar to sglang's model interface.
The text was updated successfully, but these errors were encountered:
A minor update to the sugestion. Instead of using state.metadata to fill in the template, it would be more useful to be able to use store() to fill in the template.
I often find I want to add scafolding to an agent/prompt it in multiple stages. Currently this requires writing custom solvers to add the subsequent user messages (prompt_template only works for the first message). This is the usecase I'm thinking of is something like this
The implementation would be pretty simlar to
system_message
. Perhaps something like thisI could also see a usecase for wanting
assistant_message
andtool_message
solvers as well that simply append the relevent message type. This is somwhat similar to sglang's model interface.The text was updated successfully, but these errors were encountered: