面向开发者的LLM入门课程-基于文档的问答英文版提示: 英文版提示 1.直接使用向量储存查询 from langchain.document_loaders import CSVLoader from langchain.indexes ……
哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门课程-基于文档的问答英文版提示”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。
面向开发者的LLM入门课程-基于文档的问答英文版提示:
英文版提示
1.直接使用向量储存查询
from langchain.document_loaders import CSVLoader
from langchain.indexes import VectorstoreIndexCreatorfile = ‘../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))
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 DocArrayInMemorySearchembeddings = 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}
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.
使用检索问答链来回答问题:
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.
嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门课程-基于文档的问答英文版提示”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!
还没有评论呢,快来抢沙发~