1 Star 0 Fork 1

python/ai-agent-imooc925

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
7.1链的基本使用-pipe.py 632 Bytes
一键复制 编辑 原始数据 按行查看 历史
码农的世界 提交于 2025-04-18 15:15 +08:00 . Initial commit: Add project files
# 使用.pipe效果与|等同
# 定义LLM
from langchain_deepseek import ChatDeepSeek
llm = ChatDeepSeek(
model="deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
temperature=0,
api_key=os.environ.get("DEEPSEEK_API_KEY"),
api_base=os.environ.get("DEEPSEEK_API_BASE"),
)
# 使用管道操作符来实现一条链
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template("讲一个关于{topic}的笑话,不要有任何解释")
chain = (prompt.pipe(llm).pipe(StrOutputParser()))
res=chain.invoke({"topic": "狗"})
print(res)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_76/ai-agent-imooc925.git
git@gitee.com:python_76/ai-agent-imooc925.git
python_76
ai-agent-imooc925
ai-agent-imooc925
main

搜索帮助