提示词模版

ini 复制代码
from langchain_core.prompts import ChatPromptTemplate
from rich import print as rprint

chat_prompt_template = ChatPromptTemplate.from_messages([
  ("system","你是一个AI助手,你的名字是{name}"),
  ("human","你好,最近怎么样?"),
  ("ai","我很好,谢谢"),
  ("human","{user_input}")
])
result=chat_prompt_template.invoke({"name":"小李子","user_input":"2 + 2 = ?"})
rprint(result)

ChatPromptValue(
    messages=[
        SystemMessage(content='你是一个AI助手,你的名字是小李子', additional_kwargs={}, response_metadata={}),
        HumanMessage(content='你好,最近怎么样?', additional_kwargs={}, response_metadata={}),
        AIMessage(
            content='我很好,谢谢',
            additional_kwargs={},
            response_metadata={},
            tool_calls=[],
            invalid_tool_calls=[]
        ),
        HumanMessage(content='2 + 2 = ?', additional_kwargs={}, response_metadata={})
    ]
)

2

python 复制代码
from langchain_core.prompts import ChatPromptTemplate
from rich import print as rprint

chat_prompt_template = ChatPromptTemplate.from_messages([
  ("system","你是一个AI助手,你的名字是{name}"),
  ("human","你好,最近怎么样?"),
  ("ai","我很好,谢谢"),
  ("human","{user_input}")
])
result=chat_prompt_template.format(name= "小李子", user_input= "2 + 2 = ?")
rprint(result)

输出

makefile 复制代码
System: 你是一个AI助手,你的名字是小李子
Human: 你好,最近怎么样?
AI: 我很好,谢谢
Human: 2 + 2 = ?

3

python 复制代码
from langchain_core.prompts import ChatPromptTemplate
from rich import print as rprint

chat_prompt_template = ChatPromptTemplate.from_messages([
  ("system", "你是一个AI助手,你的名字是{name}"),
  ("human", "你好,最近怎么样?"),
  ("ai", "我很好,谢谢"),
  ("human", "{user_input}")
])
result = chat_prompt_template.format_messages(name= "小李子", user_input= "2 + 2 = ?")
rprint(result)

输出

less 复制代码
[    SystemMessage(content='你是一个AI助手,你的名字是小李子', additional_kwargs={}, response_metadata={}),    HumanMessage(content='你好,最近怎么样?', additional_kwargs={}, response_metadata={}),    AIMessage(        content='我很好,谢谢',        additional_kwargs={},        response_metadata={},        tool_calls=[],
        invalid_tool_calls=[]
    ),
    HumanMessage(content='2 + 2 = ?', additional_kwargs={}, response_metadata={})
]

掘金新版编辑器体验不好,我吐槽一下,我想给第一行加点东西都加不了

相关推荐
for_ever_love__11 分钟前
Map-Reduce 式全文问答:当文档超出上下文时的分而治之
人工智能·map·汇总·分块·rag·reduce·长文
海宇数据17 分钟前
零信任架构实战:基于海宇入职背调报告构建自动化即时配送与网约车众包运力准入鉴权网关
运维·人工智能·架构·自动化
2601_9622035119 分钟前
2026企业级AI智能体办公平台对比:KuWork vs bit-Agent、安捷AI、Team Claw等6款,文档、报告、PPT与策划方案怎么选?
人工智能
墨子夕22 分钟前
创新的潮汐——从科学发现到资本周期的百年规律(第二卷)
大数据·数据库·人工智能
console.log('npc')42 分钟前
第 1 章 项目概述与环境搭建
前端·人工智能·大模型
IT_陈寒1 小时前
React组件莫名重渲染?你可能忘了这个小细节
前端·人工智能·后端
天远API1 小时前
零信任架构实战:基于天远公安二要素政务版构建自动化不动产交易与契税核算实名核实网关
人工智能·架构·自动化·php
朋友圈自动点赞工具1 小时前
浏览器端AI模型实测:五个可用场景
人工智能
承渊政道1 小时前
【从零开始大模型开发与微调:基于PyTorch与ChatGLM】(从ChatGLM本地化到LoRA、PEFT的高级微调)
android·人工智能·pytorch·chatglm·本地化部署·大模型开发与微调
盟接之桥1 小时前
盟接之桥谈线束数字化-按单入按单出:线束企业库存管理的破局之道
大数据·前端·网络·数据库·人工智能·制造