</promplate/>

提示工程框架

weekly downloads monthly downloads
免安装 交互式教程
import time

from promplate import Node
from promplate.llm.openai import ChatComplete

# 用日语撰写一段祝福
reply_template = """
<| system |>
current time: {{ time.ctime() }}
<| user |>
Say happy new year to me in native Japanese.
Note that you must include the year in the message.
"""

# 翻译成中文
translate_template = """
Translate the following dialog to `zh_CN`:
{{ name.title() }}: {{ __result__ }}
"""

reply = Node(reply_template, temperature=0.8)
translate = Node(translate_template, temperature=0.2)

# 获得一段日系祝福
chain = reply + translate

output = chain.invoke(
    {"time": time, "name": "muspi merol"},
    ChatComplete().bind(model="gpt-3.5-turbo"),
)  # 大约等待 3 秒,这期间会请求两次 OpenAI
>>> output.result
'穆斯皮·梅罗:新年快乐!2024年也请多多关照。'