add /apply-template endpoint to server
This commit is contained in:
parent
794fe23f29
commit
a864590aef
2 changed files with 25 additions and 0 deletions
|
@ -4124,6 +4124,14 @@ int main(int argc, char ** argv) {
|
||||||
res_ok(res, root);
|
res_ok(res, root);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto handle_apply_template = [&ctx_server, ¶ms, &res_ok](const httplib::Request & req, httplib::Response & res) {
|
||||||
|
auto body = json::parse(req.body);
|
||||||
|
const auto & chat_template = body.contains("tools") && ctx_server.chat_templates.template_tool_use ? *ctx_server.chat_templates.template_tool_use : *ctx_server.chat_templates.template_default;
|
||||||
|
json data = oaicompat_completion_params_parse(body, chat_template, params.use_jinja);
|
||||||
|
|
||||||
|
res_ok(res, data);
|
||||||
|
};
|
||||||
|
|
||||||
const auto handle_embeddings = [&handle_embeddings_impl](const httplib::Request & req, httplib::Response & res) {
|
const auto handle_embeddings = [&handle_embeddings_impl](const httplib::Request & req, httplib::Response & res) {
|
||||||
handle_embeddings_impl(req, res, OAICOMPAT_TYPE_NONE);
|
handle_embeddings_impl(req, res, OAICOMPAT_TYPE_NONE);
|
||||||
};
|
};
|
||||||
|
@ -4300,6 +4308,7 @@ int main(int argc, char ** argv) {
|
||||||
svr->Post("/v1/reranking", handle_rerank);
|
svr->Post("/v1/reranking", handle_rerank);
|
||||||
svr->Post("/tokenize", handle_tokenize);
|
svr->Post("/tokenize", handle_tokenize);
|
||||||
svr->Post("/detokenize", handle_detokenize);
|
svr->Post("/detokenize", handle_detokenize);
|
||||||
|
svr->Post("/apply-template", handle_apply_template);
|
||||||
// LoRA adapters hotswap
|
// LoRA adapters hotswap
|
||||||
svr->Get ("/lora-adapters", handle_lora_adapters_list);
|
svr->Get ("/lora-adapters", handle_lora_adapters_list);
|
||||||
svr->Post("/lora-adapters", handle_lora_adapters_apply);
|
svr->Post("/lora-adapters", handle_lora_adapters_apply);
|
||||||
|
|
|
@ -121,6 +121,22 @@ def test_chat_template():
|
||||||
assert res.body["__verbose"]["prompt"] == "<s> <|start_header_id|>system<|end_header_id|>\n\nBook<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nWhat is the best book<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
|
assert res.body["__verbose"]["prompt"] == "<s> <|start_header_id|>system<|end_header_id|>\n\nBook<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nWhat is the best book<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_apply_chat_template():
|
||||||
|
global server
|
||||||
|
server.chat_template = "command-r"
|
||||||
|
server.start()
|
||||||
|
res = server.make_request("POST", "/apply-template", data={
|
||||||
|
"max_tokens": 8,
|
||||||
|
"messages": [
|
||||||
|
{"role": "system", "content": "You are a test."},
|
||||||
|
{"role": "user", "content":"Hi there"},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
assert res.status_code == 200
|
||||||
|
assert "prompt" in res.body
|
||||||
|
assert res.body["prompt"] == "<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>You are a test.<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|USER_TOKEN|>Hi there<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("response_format,n_predicted,re_content", [
|
@pytest.mark.parametrize("response_format,n_predicted,re_content", [
|
||||||
({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\""),
|
({"type": "json_object", "schema": {"const": "42"}}, 6, "\"42\""),
|
||||||
({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]"),
|
({"type": "json_object", "schema": {"items": [{"type": "integer"}]}}, 10, "[ -3000 ]"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue