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

server : add /apply-template endpoint for additional use cases of Minja functionality #11489

Merged
merged 5 commits into from
Jan 29, 2025

Conversation

pnb
Copy link
Contributor

@pnb pnb commented Jan 29, 2025

This PR adds an endpoint to examples/server, /apply-template, which will apply the model's chat template to the given messages, like for chat completion, but then will simply return the formatted prompt rather than running inference.

Sometimes I modify prompts after formatting them for chat interactions, especially for cases where the goal is to insert something into the beginning of the model's response. For example, the classic "Sure!" insertion to reduce refusals, or more often some partially-constructed solutions that I would like the model to finish.

Previously I have implemented chat templates for each model myself, but with the addition of some Jinja support via Minja it is very tempting to let the server do this for users instead, as it is more likely to be correct and offer good coverage of prompt templates.

This PR also adds a CI test, which I did using the Command-R template to provide some variety versus the closely related test_chat_template unit test (side note: I did not find __verbose very useful for prompt formatting use cases because it includes BOS, hence the new endpoint).

@pnb pnb requested a review from ngxson as a code owner January 29, 2025 14:33
@github-actions github-actions bot added examples python python script changes server labels Jan 29, 2025
examples/server/server.cpp Outdated Show resolved Hide resolved
@ngxson ngxson merged commit eb7cf15 into ggerganov:master Jan 29, 2025
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples python python script changes server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants