Skip to content
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

[Feature Request] Add user_message solver #864

Open
kaifronsdal opened this issue Nov 19, 2024 · 1 comment
Open

[Feature Request] Add user_message solver #864

kaifronsdal opened this issue Nov 19, 2024 · 1 comment

Comments

@kaifronsdal
Copy link
Contributor

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

@solver
def user_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 template
    content = resource(template)

    async def solve(state: TaskState, generate: Generate) -> TaskState:
        kwargs = state.metadata | params
        state.messages.append(
            ChatMessageUser(content=content.format(**kwargs))
        )
        return state

    return solve

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.

@kaifronsdal
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant