mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-04-23 15:59:14 +00:00
Templates: Fix stop_string parsing
Template modules grab all set vars, including ones that use runtime vars. If a template var is set to a runtime var and a module is created, an UndefinedError fires. Use make_module instead to pass runtime vars when creating a template module. Resolves #92 Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
@@ -141,11 +141,14 @@ def format_prompt_with_template(data: ChatCompletionRequest):
|
||||
unwrap(data.ban_eos_token, False),
|
||||
)
|
||||
|
||||
template_vars = {
|
||||
"messages": data.messages,
|
||||
"add_generation_prompt": data.add_generation_prompt,
|
||||
**special_tokens_dict,
|
||||
}
|
||||
|
||||
prompt, template_stop_strings = get_prompt_from_template(
|
||||
data.messages,
|
||||
model.container.prompt_template,
|
||||
data.add_generation_prompt,
|
||||
special_tokens_dict,
|
||||
model.container.prompt_template, template_vars
|
||||
)
|
||||
|
||||
# Append template stop strings
|
||||
@@ -157,17 +160,17 @@ def format_prompt_with_template(data: ChatCompletionRequest):
|
||||
return prompt
|
||||
|
||||
except KeyError as exc:
|
||||
raise HTTPException(
|
||||
400,
|
||||
error_message = handle_request_error(
|
||||
"Could not find a Conversation from prompt template "
|
||||
f"'{model.container.prompt_template.name}'. "
|
||||
"Check your spelling?",
|
||||
) from exc
|
||||
).error.message
|
||||
|
||||
raise HTTPException(400, error_message) from exc
|
||||
except TemplateError as exc:
|
||||
raise HTTPException(
|
||||
400,
|
||||
f"TemplateError: {str(exc)}",
|
||||
) from exc
|
||||
error_message = handle_request_error(f"TemplateError: {str(exc)}").error.message
|
||||
|
||||
raise HTTPException(400, error_message) from exc
|
||||
|
||||
|
||||
async def stream_generate_chat_completion(
|
||||
|
||||
Reference in New Issue
Block a user