{# import time #}<|system|>current time: {{time.localtime()}}<|user|>Say happy new year to me in no more than 5 words.Note that you must include the year in the message.
Note
This shows some special markup syntax in promplate:
Inside {# ... #} are python codes to run in the context. In this case, we want to use time.localtime() to get the current time. So we import it in the template.
<|user|> and <|assistant|> are chat markups. It will be formatted into a list[Message] object before being passed to the LLM.
Inside {{...}} can be any python expressions.
Translate the following message into `{{lang}}`:"""{{__result__}}"""
You may ask, what is {{__result__}}?
In fact, promplate will automatically inject some variables into the context. Among them, __result__ is the LLM response of the previous node.
Then call chain.invoke({"lang":"chinese"},complete).result to get a Chinese greeting relating with the time now.
Often we need several LLM calls in a process. LCEL is langchain's solution.
Ours is like that, but everything unit is a promplate.Node instance. Router are implemented with 2-3 lines in callback functions through raiseJump(...) statements.
Usually you need to manually construct the message list if you are using a chat model. In promplate, you can write chat templates in separate files, and use a render it as a list.
In langchain, you can bind callback to a variety of event types. Promplate has a flexible callback system similarly, but you can bind simple callbacks through decorators like the callback registration decorators on Node.