API: add /props route (#1222)

* API: add an /extra/chat_template route

A lot of manual tweaking is done when swapping between models. We can automate or make better assumptions about some of them by having more information, such as chat template. This PR adds an endpoint /extra/chat_template which returns the model chat template string as is in a 'chat_template' key. The front end can then use this to derive the proper templates or use it as is, or at least warn the user when they are trying to use e.g. a Mistral preset with a Llama 3.1 model.

* switch to pre-established /props endpoint for chat template

* bug-fix (upstream): one-off in string juggling
This commit is contained in:
kallewoof
2024-11-21 11:58:32 +09:00
committed by GitHub
parent 8ab3eb89a8
commit 547ab2aebb
4 changed files with 35 additions and 0 deletions
+8
View File
@@ -459,6 +459,7 @@ def init_library():
handle.abort_generate.restype = ctypes.c_bool
handle.token_count.restype = token_count_outputs
handle.get_pending_output.restype = ctypes.c_char_p
handle.get_chat_template.restype = ctypes.c_char_p
handle.sd_load_model.argtypes = [sd_load_model_inputs]
handle.sd_load_model.restype = ctypes.c_bool
handle.sd_generate.argtypes = [sd_generation_inputs]
@@ -1956,6 +1957,13 @@ Enter Prompt:<br>
self.send_header("location", self.path)
self.end_headers(content_type='text/html')
return None
elif self.path.endswith('/props'):
ctbytes = handle.get_chat_template()
chat_template = ctypes.string_at(ctbytes).decode("UTF-8")
# TODO: decide whether to add or skip below settings from llama.cpp /props endpoint.
# { "default_generation_settings", ctx_server.default_generation_settings_for_props },
# { "total_slots", ctx_server.params.n_parallel },
response_body = (json.dumps({"chat_template":chat_template}).encode())
if response_body is None:
self.send_response(404)