01。
概述
02。
安装使用
安装
pipinstallprompt-poet
基础使用
importos
importgetpass
fromprompt_poetimportPrompt
fromlangchainimportChatOpenAI
#UncommentifyouneedtosetOPENAI_API_KEY.
#os.environ["OPENAI_API_KEY"]=getpass.getpass()
raw_template="""
-name:systeminstructions
role:system
content:|
Yournameis{{character_name}}andyouaremeanttobehelpfulandneverharmfultohumans.
-name:userquery
role:user
content:|
{{username}}:{{user_query}}
-name:response
role:user
content:|
{{character_name}}:
"""
template_data={
"character_name":"CharacterAssistant",
"username":"Jeff",
"user_query":"Canyouhelpmewithmyhomework?"
}
prompt=Prompt(
raw_template=raw_template,
template_data=template_data
)
model=ChatOpenAI(model="gpt-4o-mini")
response=model.invoke(prompt.messages)
03。
Prompt 模板
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |