国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Langchain 的 Conversation summary memory

這篇具有很好參考價(jià)值的文章主要介紹了Langchain 的 Conversation summary memory。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

現(xiàn)在讓我們看一下使用稍微復(fù)雜的內(nèi)存類型 - ConversationSummaryMemory 。這種類型的記憶會(huì)隨著時(shí)間的推移創(chuàng)建對(duì)話的摘要。這對(duì)于隨著時(shí)間的推移壓縮對(duì)話中的信息非常有用。對(duì)話摘要內(nèi)存對(duì)發(fā)生的對(duì)話進(jìn)行總結(jié),并將當(dāng)前摘要存儲(chǔ)在內(nèi)存中。然后可以使用該內(nèi)存將迄今為止的對(duì)話摘要注入提示/鏈中。此內(nèi)存對(duì)于較長(zhǎng)的對(duì)話最有用,因?yàn)樵谔崾局兄鹱直A暨^(guò)去的消息歷史記錄會(huì)占用太多令牌。

我們首先來(lái)探討一下這種存儲(chǔ)器的基本功能。

示例代碼,

from langchain.memory import ConversationSummaryMemory, ChatMessageHistory
from langchain.llms import OpenAI
memory = ConversationSummaryMemory(llm=OpenAI(temperature=0))
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.load_memory_variables({})

輸出結(jié)果,

    {'history': '\nThe human greets the AI, to which the AI responds.'}

我們還可以獲取歷史記錄作為消息列表(如果您將其與聊天模型一起使用,這非常有用)。

memory = ConversationSummaryMemory(llm=OpenAI(temperature=0), return_messages=True)
memory.save_context({"input": "hi"}, {"output": "whats up"})
memory.load_memory_variables({})

輸出結(jié)果,

    {'history': [SystemMessage(content='\nThe human greets the AI, to which the AI responds.', additional_kwargs={})]}

我們也可以直接使用 predict_new_summary 方法。

messages = memory.chat_memory.messages
previous_summary = ""
memory.predict_new_summary(messages, previous_summary)

輸出結(jié)果,

    '\nThe human greets the AI, to which the AI responds.'

Initializing with messages

如果您有此類之外的消息,您可以使用 ChatMessageHistory 輕松初始化該類。加載期間,將計(jì)算摘要。

示例代碼,

history = ChatMessageHistory()
history.add_user_message("hi")
history.add_ai_message("hi there!")
memory = ConversationSummaryMemory.from_messages(llm=OpenAI(temperature=0), chat_memory=history, return_messages=True)
memory.buffer

輸出結(jié)果,

    '\nThe human greets the AI, to which the AI responds with a friendly greeting.'

Using in a chain

讓我們看一下在鏈中使用它的示例,再次設(shè)置 verbose=True 以便我們可以看到提示。

示例代碼,

from langchain.llms import OpenAI
from langchain.chains import ConversationChain
llm = OpenAI(temperature=0)
conversation_with_summary = ConversationChain(
    llm=llm, 
    memory=ConversationSummaryMemory(llm=OpenAI()),
    verbose=True
)
conversation_with_summary.predict(input="Hi, what's up?")

輸出結(jié)果,

    
    
    > 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:
    
    Human: Hi, what's up?
    AI:
    
    > Finished chain.





    " Hi there! I'm doing great. I'm currently helping a customer with a technical issue. How about you?"

示例代碼,

conversation_with_summary.predict(input="Tell me more about it!")

輸出結(jié)果,

    
    
    > 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:
    
    The human greeted the AI and asked how it was doing. The AI replied that it was doing great and was currently helping a customer with a technical issue.
    Human: Tell me more about it!
    AI:
    
    > Finished chain.





    " Sure! The customer is having trouble with their computer not connecting to the internet. I'm helping them troubleshoot the issue and figure out what the problem is. So far, we've tried resetting the router and checking the network settings, but the issue still persists. We're currently looking into other possible solutions."

示例代碼,

conversation_with_summary.predict(input="Very cool -- what is the scope of the project?")

輸出結(jié)果,

    
    
    > 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:
    
    The human greeted the AI and asked how it was doing. The AI replied that it was doing great and was currently helping a customer with a technical issue where their computer was not connecting to the internet. The AI was troubleshooting the issue and had already tried resetting the router and checking the network settings, but the issue still persisted and they were looking into other possible solutions.
    Human: Very cool -- what is the scope of the project?
    AI:
    
    > Finished chain.





    " The scope of the project is to troubleshoot the customer's computer issue and find a solution that will allow them to connect to the internet. We are currently exploring different possibilities and have already tried resetting the router and checking the network settings, but the issue still persists."

完結(jié)!文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-610106.html

到了這里,關(guān)于Langchain 的 Conversation summary memory的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[將記憶添加到LangChain組件中]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月12日
    瀏覽(61)
  • LangChain(3)對(duì)話緩存方式 Conversational Memory

    LLM 默認(rèn)是無(wú)狀態(tài)的,即詢問(wèn)當(dāng)前的問(wèn)題與上下文無(wú)關(guān),當(dāng)我們需要將多輪對(duì)話信息給到LLM 時(shí),就需要使用緩存Memory。緩存方式有多種。

    2024年02月16日
    瀏覽(21)
  • LangChain入門(九)-使用Memory實(shí)現(xiàn)一個(gè)帶記憶的對(duì)話機(jī)器人

    LangChain入門(九)-使用Memory實(shí)現(xiàn)一個(gè)帶記憶的對(duì)話機(jī)器人

    目錄 一、說(shuō)明 二、案例 一、說(shuō)明 在第五章中我們使用的是通過(guò)自定義一個(gè)列表來(lái)存儲(chǔ)對(duì)話的方式來(lái)保存歷史的。 當(dāng)然,你也可以使用自帶的 memory 對(duì)象來(lái)實(shí)現(xiàn)這一點(diǎn)。 二、案例 結(jié)尾、掃一掃下方微信名片即可+博主徽信哦? ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓ ↓↓? ↓↓

    2024年02月16日
    瀏覽(23)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[聊天消息記錄](méi)

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月12日
    瀏覽(56)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[基礎(chǔ)知識(shí)]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月14日
    瀏覽(61)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[記憶的類型Ⅲ]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月13日
    瀏覽(56)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[記憶的類型Ⅰ]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月13日
    瀏覽(52)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[記憶的類型Ⅱ]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月13日
    瀏覽(55)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[記憶的存儲(chǔ)與應(yīng)用]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月12日
    瀏覽(124)
  • 自然語(yǔ)言處理從入門到應(yīng)用——LangChain:記憶(Memory)-[自定義對(duì)話記憶與自定義記憶類]

    分類目錄:《大模型從入門到應(yīng)用》總目錄 LangChain系列文章: 基礎(chǔ)知識(shí) 快速入門 安裝與環(huán)境配置 鏈(Chains)、代理(Agent:)和記憶(Memory) 快速開(kāi)發(fā)聊天模型 模型(Models) 基礎(chǔ)知識(shí) 大型語(yǔ)言模型(LLMs) 基礎(chǔ)知識(shí) LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(

    2024年02月13日
    瀏覽(54)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包