dynamo_llm/preprocessor/prompt/template/
context.rs1use super::{ContextMixins, PromptContextMixin};
5
6use chrono::{DateTime, Utc};
7use minijinja::value::{Object, Value};
8use std::sync::Arc;
9
10impl Object for ContextMixins {
11 fn get_value(self: &Arc<Self>, field: &Value) -> Option<Value> {
12 match field.as_str()? {
13 "datetime" => self.datetime(),
14 _ => None,
15 }
16 }
17}
18
19impl ContextMixins {
20 pub fn new(allowed_mixins: &[PromptContextMixin]) -> Self {
21 ContextMixins {
22 context_mixins: allowed_mixins.iter().cloned().collect(),
23 }
24 }
25
26 fn datetime(&self) -> Option<Value> {
30 if self
31 .context_mixins
32 .contains(&PromptContextMixin::Llama3DateTime)
33 {
34 let now = chrono::Utc::now();
35 Some(Value::from(llama3_datetime(now)))
36 } else {
37 None
38 }
39 }
40}
41
42fn llama3_datetime(datetime: DateTime<Utc>) -> String {
43 datetime.format("%d, %B, %Y").to_string()
44}