AI教程 2025年01月16日
0 收藏 0 点赞 153 浏览 4390 个字
摘要 :

面向开发者的LLM入门课程-基于文档的问答英文版提示: 英文版提示 1.直接使用向量储存查询 from langchain.document_loaders import CSVLoader from langchain.indexes ……

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

面向开发者的LLM入门课程-基于文档的问答英文版提示

面向开发者的LLM入门课程-基于文档的问答英文版提示:

英文版提示

1.直接使用向量储存查询

from langchain.document_loaders import CSVLoader
from langchain.indexes import VectorstoreIndexCreator

file = ‘../data/OutdoorClothingCatalog_1000.csv’
loader = CSVLoader(file_path=file)

index =
VectorstoreIndexCreator(vectorstore_cls=DocArrayInMemorySearch).from_loaders([loa
der])

query =”Please list all your shirts with sun protection
in a table in markdown and summarize each one.”

response = index.query(query)

display(Markdown(response))

面向开发者的LLM入门课程-基于文档的问答英文版提示

All four shirts provide UPF 50+ sun protection, blocking 98% of the sun’s harmful rays. The Men’s Tropical Plaid Short-Sleeve Shirt is made of 100% polyester and is wrinkle-resistant

2.结合表征模型和向量存储

from langchain.document_loaders import CSVLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import DocArrayInMemorySearch

embeddings = OpenAIEmbeddings()
embed = embeddings.embed_query(“Hi my name is Harrison”)

print(“n�33[32m向量表征的长度: �33[0m n”, len(embed))
print(“n�33[32m向量表征前5个元素: �33[0m n”, embed[:5])

file = ‘../data/OutdoorClothingCatalog_1000.csv’
loader = CSVLoader(file_path=file)
docs = loader.load()
embeddings = OpenAIEmbeddings()
db = DocArrayInMemorySearch.from_documents(docs, embeddings)

query = “Please suggest a shirt with sunblocking”
docs = db.similarity_search(query)
print(“n�33[32m返回文档的个数: �33[0m n”, len(docs))
print(“n�33[32m第一个文档: �33[0m n”, docs[0])

# 使用查询结果构造提示来回答问题
llm = ChatOpenAI(model_name=”gpt-3.5-turbo-0301″,temperature = 0.0)

qdocs = “”.join([docs[i].page_content for i in range(len(docs))])

response = llm.call_as_llm(f”{qdocs} Question: Please list all your
shirts with sun protection in a table in markdown and summarize each one.”)

print(“n�33[32m使用查询结果构造提示来回答问题: �33[0m n”, docs[0])
display(Markdown(response))

# 使用检索问答链来回答问题
retriever = db.as_retriever()

qa_stuff = RetrievalQA.from_chain_type(
llm=llm,
chain_type=”stuff”,
retriever=retriever,
verbose=True
)

query = “Please list all your shirts with sun protection in a table
in markdown and summarize each one.”

response = qa_stuff.run(query)

print(“n�33[32m 使用检索问答链来回答问题: �33[0m n”)
display(Markdown(response))

向量表征的长度:
1536

向量表征前5个元素:
[-0.021913960932078383, 0.006774206755842609, -0.018190348816400977,
-0.039148249368104494, -0.014089343366938917]

返回文档的个数:
4

第一个文档:
page_content=’: 255nname: Sun Shield Shirt byndescription: “Block the sun, not
the fun – our high-performance sun shirt is guaranteed to protect from harmful UV
rays. nnSize & Fit: Slightly Fitted: Softly shapes the body. Falls at
hip.nnFabric & Care: 78% nylon, 22% Lycra Xtra Life fiber. UPF 50+ rated – the
highest rated sun protection possible. Handwash, line dry.nnAdditional
Features: Wicks moisture for quick-drying comfort. Fits comfortably over your
favorite swimsuit. Abrasion resistant for season after season of wear.
Imported.nnSun Protection That Won’t Wear OffnOur high-performance fabric
provides SPF 50+ sun protection, blocking 98% of the sun’s harmful rays. This
fabric is recommended by The Skin Cancer Foundation as an effective UV
protectant.’ metadata={‘source’: ‘../data/OutdoorClothingCatalog_1000.csv’,
‘row’: 255}

使用查询结果构造提示来回答问题:
page_content=’: 255nname: Sun Shield Shirt byndescription: “Block the sun, not
the fun – our high-performance sun shirt is guaranteed to protect from harmful UV
rays. nnSize & Fit: Slightly Fitted: Softly shapes the body. Falls at
hip.nnFabric & Care: 78% nylon, 22% Lycra Xtra Life fiber. UPF 50+ rated – the
highest rated sun protection possible. Handwash, line dry.nnAdditional
Features: Wicks moisture for quick-drying comfort. Fits comfortably over your
favorite swimsuit. Abrasion resistant for season after season of wear.
Imported.nnSun Protection That Won’t Wear OffnOur high-performance fabric
provides SPF 50+ sun protection, blocking 98% of the sun’s harmful rays. This
fabric is recommended by The Skin Cancer Foundation as an effective UV
protectant.’ metadata={‘source’: ‘../data/OutdoorClothingCatalog_1000.csv’,
‘row’: 255}

面向开发者的LLM入门课程-基于文档的问答英文版提示

All of these shirts provide UPF 50+ sun protection, blocking 98% of the sun’s harmful rays. They also have additional features such as moisture-wicking, wrinkle-free fabric, and front/back cape venting for added comfort.

> Entering new RetrievalQA chain…
> Finished chain.
使用检索问答链来回答问题:

面向开发者的LLM入门课程-基于文档的问答英文版提示
面向开发者的LLM入门课程-基于文档的问答英文版提示

All of the shirts listed above provide sun protection with a UPF rating of 50+ and block 98% of the sun’s harmful rays. The Men’s Tropical Plaid Short-Sleeve Shirt is made of 100% polyester and has front and back cape venting and two front bellows pockets. The Men’s Plaid Tropic Shirt, ShortSleeve is made with 52% polyester and 48% nylon and has front and back cape venting and two front bellows pockets. The Men’s TropicVibe Shirt, Short-Sleeve is made with 71% Nylon, 29% Polyester and has front and back cape venting and two front bellows pockets. The Sun Shield Shirt is made with 78% nylon, 22% Lycra Xtra Life fiber and is abrasion-resistant. It fits comfortably over your favorite swimsuit.

面向开发者的LLM入门课程-创建LLM应用
面向开发者的LLM入门课程-创建LLM应用:评估 评估是检验语言模型问答质量的关键环节。评估可以检验语言模型在不同文档上的问答效果,...

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

微信扫一扫

支付宝扫一扫

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

相关推荐
01-16

面向开发者的LLM入门课程-创建LLM应用: 评估 评估是检验语言模型问答质量的关键环节。评估可以检…

162
01-16

面向开发者的LLM入门课程-基于文档的问答英文版提示: 英文版提示 1.直接使用向量储存查询 from la…

153
01-16

面向开发者的LLM入门课程-结合表征模型和向量存储: 结合表征模型和向量存储 由于语言模型的上下文…

153
01-16

面向开发者的LLM入门课程-直接使用向量储存查询: 基于文档的问答 使用大语言模型构建一个能够回答…

153
01-16

面向开发者的LLM入门课程-模型链英文版提示: 英文版提示 1.大语言模型链 from langchain.chat_mod…

153
01-15

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

153
01-15

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

153
01-15

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

153
发表评论
暂无评论

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

助力原创内容

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

扫描二维码

手机访问本站