使用LangChain構(gòu)建問答聊天機(jī)器人案例實(shí)戰(zhàn)文章來源:http://www.zghlxwxcb.cn/news/detail-619430.html
LangChain開發(fā)全流程剖析
接下來,我們再回到“get_prompt()”方法。在這個(gè)方法中,有系統(tǒng)提示詞(system prompts)和用戶提示詞(user prompts),這是從相應(yīng)的文件中讀取的,從“system.prompt”文件中讀取系統(tǒng)提示詞(system_template),從“user.prompt”文件中讀取用戶提示詞(human_template)。在第7行中,我們定義了兩個(gè)輸入變量:“query”和“df_info”。然后,將這些提示詞信息和輸入變量封裝在一個(gè)“ChatPromptTemplate”對象中,會(huì)調(diào)用“SystemMessagePromptTemplate.from_template()”方法和“HumanMessagePromptTemplate.from_template()”方法,并返回該對象。
其中,from_template方法是BaseStringMessagePromptTemplate的一個(gè)類方法,這個(gè)方法接受一個(gè)字符串模板“template”和一個(gè)字符串“template_format”,還有其他的關(guān)鍵字參數(shù)。這個(gè)方法返回一個(gè)“MessagePromptTemplateT”類型的對象。我們使用“PromptTemplate.from_template()”方法從字符串模板中創(chuàng)建一個(gè)PromptTemplate對象。然后,使用這個(gè)對象作為參數(shù)來創(chuàng)建一個(gè)“MessagePromptTemplateT”類型的對象。這個(gè)對象將包含從模板中解析出來的內(nèi)容,這個(gè)源碼本身非常簡單。Gavin大咖微信:NLP_Matrix_Space
chat.py的from_template方法的代碼實(shí)現(xiàn):文章來源地址http://www.zghlxwxcb.cn/news/detail-619430.html
到了這里,關(guān)于使用LangChain構(gòu)建問答聊天機(jī)器人案例實(shí)戰(zhàn)(三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!