自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

使用LangChain和DeepInfra構(gòu)建客戶支持聊天機器人的操作指南

譯文
人工智能 機器人
本文介紹了如何使用DeepInfra和LangChain構(gòu)建一個用于客戶支持的AI聊天機器人。

譯者 | 布加迪

審校 | 重樓

可能在日常的網(wǎng)上互動中遇到過聊天機器人,但有沒有考慮底層為這些數(shù)字助手提供支持的技術(shù)?聊天機器人尤其在客戶支持領(lǐng)域)已經(jīng)成為現(xiàn)代企業(yè)的一個力工具,在提高效率的同時改進了客戶服務(wù)。今天,我們將深入研究LangChainDeepInfra如何使這聊天機器人變得響應(yīng)迅即、更高效。

聊天機器人的基本組成部分

不妨先了解基礎(chǔ)知識——聊天機器人的核心組件有哪些?在開發(fā)一個響應(yīng)迅即又高效的聊天機器人時,三個要素必不可少模型、提示模板(Prompt Template)和記憶。

模型代表了聊天機器人背后的AI大腦,負(fù)責(zé)理解和響應(yīng)用戶輸入。提示模板引導(dǎo)聊天機器人的響應(yīng),確保它們的回復(fù)緊扣對話主題。最后,記憶保持交互狀態(tài),使聊天機器人能夠記住過去的對話,利用它們來理解當(dāng)前對話的上下文。

操作指南

現(xiàn)在開始動手吧。我們將逐步介紹使用LangChainDeepInfra構(gòu)建客戶支持聊天機器人的過程。我們假設(shè)這個聊天機器人在一家在線服裝店“工作”,可以幫助顧客為他們挑選衣服。

  • 獲取DeepInfra API密鑰

DeepInfra擁有其簡單的API和可擴展的生產(chǎn)基礎(chǔ)設(shè)施,使您可以輕松運行主流的AI模型。首先,您需要使用該鏈接獲取DeepInfra API密鑰,以便服務(wù)進行交互。一旦有了密鑰,就可以在環(huán)境中設(shè)置API令牌,如下所示

from getpass import getpass
import os
# Set the DeepInfra API token
DEEPINFRA_API_TOKEN = getpass()
os.environ["DEEPINFRA_API_TOKEN"] = DEEPINFRA_API_TOKEN
  • 建立LangChain和DeepInfra環(huán)境

接下來,您需要創(chuàng)建LangChain和DeepInfra環(huán)境。導(dǎo)入必要的組件DeepInfra模型創(chuàng)建實例。比如說,您可以使用像“databricks/dolly-v2-12b這樣的模型

from langchain import ConversationChain, LLMChain, PromptTemplate
from langchain.memory import ConversationBufferWindowMemory
from langchain.llms import DeepInfra
# Create the DeepInfra instance
llm = DeepInfra(model_id="databricks/dolly-v2-12b")
llm.model_kwargs = {'temperature': 0.7, 'repetition_penalty': 1.2, 'max_new_tokens': 250, 'top_p': 0.9}
  • 注意:為聊天機器人選擇和部署合適的模型

您可以為LLM使用許多不同的模型。這個例子展示了如何使用databricks/dolly-v2-12b模型,但在DeepInfra上還有許多其他模型可供使用。由于選擇眾多,您可能希望使用像AIModels這樣的工具,希望找到可與LangChain結(jié)合使用的合適的LLM。您可以隨意搜索、過濾和篩選AI模型,以便找到最適合您項目的模型。查看DeepInfra頁面,即可找到可供選擇的模型。

  • 創(chuàng)建提示模板以指導(dǎo)聊天機器人的響應(yīng)

現(xiàn)在,是時候定義提示模板來指導(dǎo)聊天機器人的響應(yīng)了。這將確保聊天機器人的響應(yīng)與上下文和用戶的輸入保持一致。我嘗試了幾個不同的模板,要得到一個完美的模板并非易事。設(shè)計正確提示的過程名為提示工程。最終,我能夠重復(fù)使用我在Pinecone網(wǎng)站上找到的一個模板。

template = """Given the following user prompt and conversation log, formulate a question that would be the most relevant to provide the user with an answer from a knowledge base.
 You should follow the following rules when generating and answer:
 - Always prioritize the user prompt over the conversation log.
 - Ignore any conversation log that is not directly related to the user prompt.
 - Only attempt to answer if a question was posed.
 - The question should be a single sentence.
 - You should remove any punctuation from the question.
 - You should remove any words that are not relevant to the question.
 - If you are unable to formulate a question, respond with the same USER PROMPT you got.

Conversation log: {history}
USER PROMPT: {human_input}
Your response:
"""

prompt = PromptTemplate(
 input_variables=["history", "human_input"], 
 template=template
)
  • 初始化聊天機器人,并設(shè)置記憶

準(zhǔn)備好模型和提示模板后,下一步是初始化聊天機器人并設(shè)置記憶,保持交互的狀態(tài)。

# Now using DeepInfra with the LLMChain
llm_chain = LLMChain(
llm=llm,
prompt=prompt,
verbose=True,
memory=ConversationBufferWindowMemory(k=2),
)
  • 運行聊天機器人并與之交互

最后,您現(xiàn)在可以與聊天機器人進行交互了。不妨看一個例子

output = llm_chain.predict(human_input="Hello! What clothes do you recommend I buy to rebuild my summer wardrobe")
print(output)

因而生成的響應(yīng)推薦一些衣服:

In the context of summer wardrobe recommendations, you should buy your clothes from the following list:
- V-neck T-shirts
- Tank Tops
- Solid Color Swim Shorts
- Swim Shorts
- Skirts
- Cardigans
- Sandals

天機器人中的記憶概念

記憶在聊天機器人中起著至關(guān)重要的作用。它有助于維持聊天機器人交互中的上下文和歷史記錄,從而使聊天機器人能夠回憶過去的對話,并理解當(dāng)前對話的上下文。這種能力對于創(chuàng)造更人性化的交互從而改善用戶體驗至關(guān)重要。記憶方面的話題有很多文章值得深入研究,建議您看看這篇指南,了解更多的信息。

更多參考資料和示例

為了進一步理解,我建議查看Langchain網(wǎng)站上的ChatGPT Clone筆記本、Conversation Memory筆記本和Conversation Agent筆記本等資源。這些資源更深入地介紹了記憶概念,記憶關(guān)鍵概念和記憶示例提供了實用指導(dǎo)。

您還應(yīng)該查看AIModels.fyi上的其他Langchain指南。

DeepInfra還為平臺提供了完備的文檔,甚至還有一個博客,您可以獲取詳細(xì)的帖子、指南和文章。

結(jié)論

使用LangChain和DeepInfra構(gòu)建面向客戶支持的聊天機器人最初可能看起來很復(fù)雜,但一旦您了解了基本組件和步驟,整個過程就會變得簡單得多。利用這些技術(shù)可以顯著改進客戶服務(wù),提高業(yè)務(wù)效率,并提高總體客戶滿意度。將來,這些技術(shù)會變得真正大有潛力,預(yù)計它們會繼續(xù)發(fā)展并影響客戶服務(wù)領(lǐng)域。

原文標(biāo)題:Building a Customer Support Chatbot with LangChain and DeepInfra: A Step-by-Step Guide,作者:Mike Young


責(zé)任編輯:華軒 來源: 51CTO
相關(guān)推薦

2022-07-05 06:42:01

聊天機器人人工智能

2024-11-01 14:52:24

2024-09-30 13:11:09

2019-01-25 16:30:34

機器人機器學(xué)習(xí)人工智能

2024-09-02 08:17:53

RAG聊天機器人人工智能

2019-06-04 08:00:00

機器人聊天機器人人工智能

2019-07-03 10:02:47

聊天機器人平臺機器人

2017-08-21 13:31:44

AI聊天機器人facebook

2019-03-22 09:00:00

AI人工智能聊天機器人

2023-11-25 17:08:47

ChatbotLLAMALangChain

2017-03-28 12:21:21

機器人定義

2016-02-16 14:46:33

聊天機器人機器學(xué)習(xí)自然語言

2020-02-02 09:19:14

聊天機器人機器人智能

2020-08-14 16:18:30

人工智能

2023-04-05 19:32:28

2021-11-30 10:56:43

ChatterBot機器人人工智能

2023-06-29 15:04:21

微軟ChatGPT

2023-12-18 19:05:34

2022-08-04 07:03:41

AnswersInfobip無代碼

2017-12-15 08:58:40

測試工具地圖API文檔
點贊
收藏

51CTO技術(shù)棧公眾號