Extra context for chat templates
This commit is contained in:
parent
6e42723899
commit
a17950fb63
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
|
||||
|
|
@ -1199,6 +1200,16 @@ static void func_args_not_string(json & messages) {
|
|||
|
||||
}
|
||||
|
||||
static json common_chat_extra_context() {
|
||||
json ctx = json::object();
|
||||
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
|
||||
std::string datetime_str = format_time(now, "%b %d %Y");
|
||||
std::string date_str = format_time(now, "%d %b %Y");
|
||||
ctx["datetime"] = datetime_str;
|
||||
ctx["date_string"] = date_str;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
static common_chat_params common_chat_templates_apply_jinja(const struct common_chat_templates * tmpls,
|
||||
const struct common_chat_templates_inputs & inputs) {
|
||||
autoparser::templates_params params;
|
||||
|
|
@ -1229,7 +1240,7 @@ static common_chat_params common_chat_templates_apply_jinja(const struct common_
|
|||
workaround::requires_non_null_content(params.messages);
|
||||
}
|
||||
|
||||
params.extra_context = json::object();
|
||||
params.extra_context = common_chat_extra_context();
|
||||
for (auto el : inputs.chat_template_kwargs) {
|
||||
params.extra_context[el.first] = json::parse(el.second);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue