prompt-poet 参考使用

主要是一个简单的功能体验,包含了include 以及简单的jinja2 逻辑判断

模版定义

  • app.yaml.j2
{% include 'system_instruction.yml.j2' %}
- name: system demo
  role: system
  content: |
    you are a system user
 
{% if username =="dalong" %}
- name: system audio 
  role: system
  content: |
    you are a system audio user
{% endif %}
  • system_instruction.yml.j2
- name: system demo
  role: system
  content: |
    demo contents
  • 应用使用
from prompt_poet import Prompt
 
template_data = {
  "character_name": "Character Assistant",
  "username": "dalong",
}
 
prompt = Prompt(
    template_path="app.yaml.j2",
    template_data=template_data
)
 
print(prompt.messages)
  • 效果

说明

基于prompt-poet的提示词模版管理机制上还是比较灵活的,值得尝试下,同时还提供了一个模版registry 的功能,后边可以详细研究下源码

参考资料

https://github.com/character-ai/prompt-poet/issues/18
https://github.com/character-ai/prompt-poet

posted on 2024-09-29 17:03  荣锋亮  阅读(2)  评论(0编辑  收藏  举报

导航