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

自然語言處理從入門到應用——LangChain:模型(Models)-[聊天模型(Chat Models):使用少量示例和響應流式傳輸]

這篇具有很好參考價值的文章主要介紹了自然語言處理從入門到應用——LangChain:模型(Models)-[聊天模型(Chat Models):使用少量示例和響應流式傳輸]。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

分類目錄:《大模型從入門到應用》總目錄

LangChain系列文章:

  • 基礎知識
  • 快速入門
    • 安裝與環(huán)境配置
    • 鏈(Chains)、代理(Agent:)和記憶(Memory)
    • 快速開發(fā)聊天模型
  • 模型(Models)
    • 基礎知識
    • 大型語言模型(LLMs)
      • 基礎知識
      • LLM的異步API、自定義LLM包裝器、虛假LLM和人類輸入LLM(Human Input LLM)
      • 緩存LLM的調用結果
      • 加載與保存LLM類、流式傳輸LLM與Chat Model響應和跟蹤tokens使用情況
    • 聊天模型(Chat Models)
      • 基礎知識
      • 使用少量示例和響應流式傳輸
    • 文本嵌入模型
      • Aleph Alpha、Amazon Bedrock、Azure OpenAI、Cohere等
      • Embaas、Fake Embeddings、Google Vertex AI PaLM等
  • 提示(Prompts)
    • 基礎知識
    • 提示模板
      • 基礎知識
      • 連接到特征存儲
      • 創(chuàng)建自定義提示模板和含有Few-Shot示例的提示模板
      • 部分填充的提示模板和提示合成
      • 序列化提示信息
    • 示例選擇器(Example Selectors)
    • 輸出解析器(Output Parsers)
  • 記憶(Memory)
    • 基礎知識
    • 記憶的類型
      • 會話緩存記憶、會話緩存窗口記憶和實體記憶
      • 對話知識圖譜記憶、對話摘要記憶和會話摘要緩沖記憶
      • 對話令牌緩沖存儲器和基于向量存儲的記憶
    • 將記憶添加到LangChain組件中
    • 自定義對話記憶與自定義記憶類
    • 聊天消息記錄
    • 記憶的存儲與應用
  • 索引(Indexes)
    • 基礎知識
    • 文檔加載器(Document Loaders)
    • 文本分割器(Text Splitters)
    • 向量存儲器(Vectorstores)
    • 檢索器(Retrievers)
  • 鏈(Chains)
    • 基礎知識
    • 通用功能
      • 自定義Chain和Chain的異步API
      • LLMChain和RouterChain
      • SequentialChain和TransformationChain
      • 鏈的保存(序列化)與加載(反序列化)
    • 鏈與索引
      • 文檔分析和基于文檔的聊天
      • 問答的基礎知識
      • 圖問答(Graph QA)和帶來源的問答(Q&A with Sources)
      • 檢索式問答
      • 文本摘要(Summarization)、HyDE和向量數(shù)據(jù)庫的文本生成
  • 代理(Agents)
    • 基礎知識
    • 代理類型
    • 自定義代理(Custom Agent)
    • 自定義MRKL代理
    • 帶有ChatModel的LLM聊天自定義代理和自定義多操作代理(Custom MultiAction Agent)
    • 工具
      • 基礎知識
      • 自定義工具(Custom Tools)
      • 多輸入工具和工具輸入模式
      • 人工確認工具驗證和Tools作為OpenAI函數(shù)
    • 工具包(Toolkit)
    • 代理執(zhí)行器(Agent Executor)
      • 結合使用Agent和VectorStore
      • 使用Agents的異步API和創(chuàng)建ChatGPT克隆
      • 處理解析錯誤、訪問中間步驟和限制最大迭代次數(shù)
      • 為代理程序設置超時時間和限制最大迭代次數(shù)和為代理程序和其工具添加共享內存
    • 計劃與執(zhí)行
  • 回調函數(shù)(Callbacks)

使用少量示例

本部分的內容介紹了如何在聊天模型(Chat Models)中使用少量示例。關于如何最好地進行少量示例提示尚未形成明確的共識。因此,我們尚未固定任何關于此的抽象概念,而是使用現(xiàn)有的抽象概念。

交替的人工智能/人類消息

進行少量示例提示的第一種方式是使用交替的人工智能/人類消息。以下是一個示例:

from langchain.chat_models import ChatOpenAI
from langchain import PromptTemplate, LLMChain
from langchain.prompts.chat import (
    ChatPromptTemplate,
    SystemMessagePromptTemplate,
    AIMessagePromptTemplate,
    HumanMessagePromptTemplate,
)
from langchain.schema import (
    AIMessage,
    HumanMessage,
    SystemMessage
)

chat = ChatOpenAI(temperature=0)

template="You are a helpful assistant that translates english to pirate."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
example_human = HumanMessagePromptTemplate.from_template("Hi")
example_ai = AIMessagePromptTemplate.from_template("Argh me mateys")
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)

chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, example_human, example_ai, human_message_prompt])

chain = LLMChain(llm=chat, prompt=chat_prompt)

# 從格式化的消息中獲取聊天完成結果
chain.run("I love programming.")

輸出:

"I be lovin' programmin', me hearty!"
系統(tǒng)消息

OpenAI提供了一個可選的name參數(shù),我們也建議與系統(tǒng)消息一起使用以進行少量示例提示。以下是如何使用此功能的示例:

template="You are a helpful assistant that translates english to pirate."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
example_human = SystemMessagePromptTemplate.from_template("Hi", additional_kwargs={"name": "example_user"})
example_ai = SystemMessagePromptTemplate.from_template("Argh me mateys", additional_kwargs={"name": "example_assistant"})
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)

chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, example_human, example_ai, human_message_prompt])
chain = LLMChain(llm=chat, prompt=chat_prompt)

# 從格式化的消息中獲取聊天完成結果
chain.run("I love programming.")

輸出:

"I be lovin' programmin', me hearty!"

響應流式傳輸

本部分介紹了如何在聊天模型中使用流式傳輸:

from langchain.chat_models import ChatOpenAI
from langchain.schema import (
    HumanMessage,
)
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
chat = ChatOpenAI(streaming=True, callbacks=[StreamingStdOutCallbackHandler()], temperature=0)
resp = chat([HumanMessage(content="Write me a song about sparkling water.")])

輸出:

Verse 1:
Bubbles rising to the top
A refreshing drink that never stops
Clear and crisp, it's pure delight
A taste that's sure to excite

Chorus:
Sparkling water, oh so fine
A drink that's always on my mind
With every sip, I feel alive
Sparkling water, you're my vibe

Verse 2:
No sugar, no calories, just pure bliss
A drink that's hard to resist
It's the perfect way to quench my thirst
A drink that always comes first

Chorus:
Sparkling water, oh so fine
A drink that's always on my mind
With every sip, I feel alive
Sparkling water, you're my vibe

Bridge:
From the mountains to the sea
Sparkling water, you're the key
To a healthy life, a happy soul
A drink that makes me feel whole

Chorus:
Sparkling water, oh so fine
A drink that's always on my mind
With every sip, I feel alive
Sparkling water, you're my vibe

Outro:
Sparkling water, you're the one
A drink that's always so much fun
I'll never let you go, my friend
Sparkling

參考文獻:
[1] LangChain ????? 中文網,跟著LangChain一起學LLM/GPT開發(fā):https://www.langchain.com.cn/
[2] LangChain中文網 - LangChain 是一個用于開發(fā)由語言模型驅動的應用程序的框架:http://www.cnlangchain.com/文章來源地址http://www.zghlxwxcb.cn/news/detail-605908.html

到了這里,關于自然語言處理從入門到應用——LangChain:模型(Models)-[聊天模型(Chat Models):使用少量示例和響應流式傳輸]的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領取紅包

二維碼2

領紅包