AI教程 2025年01月15日
0 收藏 0 点赞 471 浏览 3549 个字
摘要 :

面向开发者的LLM入门课程-对话摘要缓存储存: 对话摘要缓存储存 对话摘要缓存储存,使用 LLM 对到目前为止历史对话自动总结摘要,并将其保存下来。 1.使用对话摘要缓存……

哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门课程-对话摘要缓存储存”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。

面向开发者的LLM入门课程-对话摘要缓存储存

面向开发者的LLM入门课程-对话摘要缓存储存:

对话摘要缓存储存

对话摘要缓存储存,使用 LLM 对到目前为止历史对话自动总结摘要,并将其保存下来。

1.使用对话摘要缓存储存

我们创建了一个长字符串,其中包含某人的日程安排

from langchain.chains import ConversationChain
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationSummaryBufferMemory
# 创建一个长字符串
schedule = “在八点你和你的产品团队有一个会议。
你需要做一个PPT。
上午9点到12点你需要忙于LangChain。
Langchain是一个有用的工具,因此你的项目进展的非常快。
中午,在意大利餐厅与一位开车来的顾客共进午餐
走了一个多小时的路程与你见面,只为了解最新的 AI。
确保你带了笔记本电脑可以展示最新的 LLM 样例.”
llm = ChatOpenAI(temperature=0.0)
memory = ConversationSummaryBufferMemory(llm=llm, max_token_limit=100)
memory.save_context({“input”: “你好,我叫皮皮鲁”}, {“output”: “你好啊,我叫鲁西西”})
memory.save_context({“input”: “很高兴和你成为朋友!”}, {“output”: “是的,让我们一起去冒
险吧!”})
memory.save_context({“input”: “今天的日程安排是什么?”}, {“output”: f”{schedule}”})
print(memory.load_memory_variables({})[‘history’])
System: The human introduces themselves as Pipilu and the AI introduces
themselves as Luxixi. They express happiness at becoming friends and decide to go
on an adventure together. The human asks about the schedule for the day. The AI
informs them that they have a meeting with their product team at 8 o’clock and
need to prepare a PowerPoint presentation. From 9 am to 12 pm, they will be busy
with LangChain, a useful tool that helps their project progress quickly. At noon,
they will have lunch with a customer who has driven for over an hour just to
learn about the latest AI. The AI advises the human to bring their laptop to
showcase the latest LLM samples.

2.基于对话摘要缓存储存的对话链

基于上面的对话摘要缓存储存,我们新建一个对话链。

conversation = ConversationChain(llm=llm, memory=memory, verbose=True)
conversation.predict(input=”展示什么样的样例最好呢?”)

> Entering new ConversationChain chain…
Prompt after formatting:
The following is a friendly conversation between a human and an AI. The AI is
talkative and provides lots of specific details from its context. If the AI does
not know the answer to a question, it truthfully says it does not know.
Current conversation:
System: The human introduces themselves as Pipilu and the AI introduces
themselves as Luxixi. They express happiness at becoming friends and decide to go
on an adventure together. The human asks about the schedule for the day. The AI
informs them that they have a meeting with their product team at 8 o’clock and
need to prepare a PowerPoint presentation. From 9 am to 12 pm, they will be busy
with LangChain, a useful tool that helps their project progress quickly. At noon,
they will have lunch with a customer who has driven for over an hour just to
learn about the latest AI. The AI advises the human to bring their laptop to
showcase the latest LLM samples.
Human: 展示什么样的样例最好呢?
AI:
> Finished chain.

‘展示一些具有多样性和创新性的样例可能是最好的选择。你可以展示一些不同领域的应用,比如自然语言处理、图像识别、语音合成等。另外,你也可以展示一些具有实际应用价值的样例,比如智能客服、智能推荐等。
总之,选择那些能够展示出我们AI技术的强大和多样性的样例会给客户留下深刻的印象。’

print(memory.load_memory_variables({})) # 摘要记录更新了

{‘history’: “System: The human introduces themselves as Pipilu and the AI
introduces themselves as Luxixi. They express happiness at becoming friends and
decide to go on an adventure together. The human asks about the schedule for the
day. The AI informs them that they have a meeting with their product team at 8
o’clock and need to prepare a PowerPoint presentation. From 9 am to 12 pm, they
will be busy with LangChain, a useful tool that helps their project progress
quickly. At noon, they will have lunch with a customer who has driven for over an
hour just to learn about the latest AI. The AI advises the human to bring their
laptop to showcase the latest LLM samples. The human asks what kind of samples
would be best to showcase. The AI suggests that showcasing diverse and innovative
samples would be the best choice. They recommend demonstrating applications in
different fields such as natural language processing, image recognition, and
speech synthesis. Additionally, they suggest showcasing practical examples like
intelligent customer service and personalized recommendations to impress the
customer with the power and versatility of their AI technology.”}

通过对比上一次输出,发现摘要记录更新了,添加了最新一次对话的内容总结。

面向开发者的LLM入门课程-对话储存英文版提示
面向开发者的LLM入门课程-对话储存英文版提示:英文版提示 1.对话缓存储存 from langchain.chains import ConversationChain fro...

嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门课程-对话摘要缓存储存”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.ai-blog.cn/2670.html

相关推荐
01-15

面向开发者的LLM入门课程-路由链: 路由链 到目前为止,我们已经学习了大语言模型链和顺序链。但是…

214
01-15

面向开发者的LLM入门课程-顺序链: 顺序链 当只有一个输入和一个输出时,简单顺序链(SimpleSequen…

471
01-15

面向开发者的LLM入门课程-简单顺序链: 简单顺序链 顺序链(SequentialChains)是按预定义顺序执行…

471
01-15

面向开发者的LLM入门课程-大语言模型链: 模型链 链(Chains)通常将大语言模型(LLM)与提示(Pro…

471
01-15

面向开发者的LLM入门课程-对话储存英文版提示: 英文版提示 1.对话缓存储存 from langchain.chains…

471
01-15

面向开发者的LLM入门课程-对话摘要缓存储存: 对话摘要缓存储存 对话摘要缓存储存,使用 LLM 对到…

471
01-15

面向开发者的LLM入门课程-对话字符缓存储存: 对话字符缓存储存 使用对话字符缓存记忆,内存将限制…

471
01-15

面向开发者的LLM入门课程-对话缓存窗口储存: 对话缓存窗口储存 随着对话变得越来越长,所需的内存…

471
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力原创内容

快速提升站内名气成为大牛

扫描二维码

手机访问本站