小智头像图片
AI教程 2025年01月16日
0 收藏 0 点赞 235 浏览 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

相关推荐

AI写作-小说大纲在小说中的作用: 大纲主要讲两个部分: 一、大纲有什么用。 二、如何写大纲。 我上…

小智头像图片
142

AI写作-小说大纲的写法和新手常见的问题: 对于大纲的问题,相信大家深深浅浅的都有些了解。今天结…

小智头像图片
235

AI写作-小说的基础提纲结构: 很多的新作者在推出了大量的作品后,却是留给读者的是迷茫,包括作者…

小智头像图片
235

AI写作-小说大纲详解: 案例一:第 1-2 章(通过的大纲分章) 涵柔睁开眼睛,发现正被一个脑满肠肥的…

小智头像图片
235

AI写作-小说大纲格式与内容概述: 什么叫大纲?大纲是一本小说的根本。他为小说提供了精神主旨,主要…

小智头像图片
235

AI写作-如何利用日常生活写小说: 一、举例 1.身边之人是熟人,但是是关系平平的同事, 这种的大家…

小智头像图片
150

AI绘画-Liblibai简易上手教程​:prompt简易技巧: prompt简易技巧​ 认识prompt​ 好说,你就这么理…

小智头像图片
235

AI绘画-Liblibai简易上手教程​:简明操作流程: 简明操作流程​ 文生图​ 1.定主题:你需要生成一张…

小智头像图片
235
发表评论
暂无评论

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

助力原创内容

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

扫描二维码

手机访问本站

二维码
vip弹窗图片