How to create a langchain doc from an str

2024-06-23 12:20
文章标签 create langchain doc str

本文主要是介绍How to create a langchain doc from an str,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题背景:

I've searched all over langchain documentation on their official website but I didn't find how to create a langchain doc from a str variable in python so I searched in their GitHub code and I found this :

在 langchain 的官方文档中,我并没有直接找到如何从 Python 中的字符串变量创建 langchain 文档的具体指导。所以,我在 GitHub 代码库中找到了相关的线索。

 doc=Document(page_content="text",metadata={"source": "local"})

PS: I added the metadata attribute
then I tried using that doc with my chain:
Memory and Chain:

PS: 我添加了元数据属性
然后我尝试使用那个文档与我的链进行交互:
内存和链:

memory = ConversationBufferMemory(memory_key="chat_history", input_key="human_input")
chain = load_qa_chain(llm, chain_type="stuff", memory=memory, prompt=prompt
)

the call method:

  chain({"input_documents": doc, "human_input": query})

prompt template:        提示模板

template = """You are a senior financial analyst analyzing the below document and having a conversation with a human.
{context}
{chat_history}
Human: {human_input}
senior financial analyst:"""prompt = PromptTemplate(input_variables=["chat_history", "human_input", "context"], template=template
)

but I am getting the following error:        但我遇到了以下错误:

AttributeError: 'tuple' object has no attribute 'page_content'

when I tried to check the type and the page content of the Document object before using it with the chain I got this

当我试图在使用链之前检查Document对象的类型和页面内容时,我得到了这个

print(type(doc))
<class 'langchain.schema.Document'>
print(doc.page_content)
"text"

问题解决:

This worked for me:        我使用这种方法有效果

from langchain.docstore.document import Documentdoc =  Document(page_content="text", metadata={"source": "local"})

这篇关于How to create a langchain doc from an str的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1087139

相关文章

LangChain转换链:让数据处理更精准

1. 转换链的概念 在开发AI Agent(智能体)时,我们经常需要对输入数据进行预处理,这样可以更好地利用LLM。LangChain提供了一个强大的工具——转换链(TransformChain),它可以帮我们轻松实现这一任务。 转换链(TransformChain)主要是将 给定的数据 按照某个函数进行转换,再将 转换后的结果 输出给LLM。 所以转换链的核心是:根据业务逻辑编写合适的转换函

brew install opencv@2 时报错 Error: Can't create update lock in /usr/local/var/homebrew/locks!

解决方案,报错里已经说明了: 我的解决方案: sudo chown -R "$USER":admin /usr/local   stackoverflow上的答案 I was able to solve the problem by using chown on the folder: sudo chown -R "$USER":admin /usr/local Also you'

认识LangChain

介绍 LangChain 是一个用于开发由大型语言模型(LLM)支持的应用程序的框架。LangChain使得构建LLM应用更简单,大致三个阶段: 开发阶段 Conceptual guide | 🦜️🔗 LangChainProviders | 🦜️🔗 LangChainTemplates | 🦜️🔗 LangChain使用LangChain的开源构建块和组件构建您的应用程序。使

[分布式网络通讯框架]----Zookeeper客户端基本操作----ls、get、create、set、delete

Zookeeper数据结构 zk客户端常用命令 进入客户端 在bin目录下输入./zkCli.sh 查看根目录下数据ls / 注意:要查看哪一个节点,必须把路径写全 查看节点数据信息 get /第一行代码数据,没有的话表示没有数据 创建节点create /sl 20 /sl为节点的路径,20为节点的数据 注意,不能跨越创建,也就是说,创建sl2的时候,必须确保sl

Transformers和Langchain中几个组件的区别

1.对于Transformers框架的介绍 1.1 介绍: transformers 是由 Hugging Face 开发的一个开源库,它提供了大量预训练模型,主要用于自然语言处理(NLP)任务。这个库提供的模型可以用于文本分类、信息抽取、问答、文本生成等多种任务。 1.2 应用场景: 文本分类:使用 BERT、RoBERTa 等模型进行情感分析、意图识别等。命名实体识别(NER):使用序列

VMWARE 安装失败 “FAILED TO CREATE THE REQUESTED REGISTRY KEY KEY

问题详情: 安装虚拟机VMWare Workstation8.0时出现“failed to create the requested registry key key installer error 1021” 解决问题: 1.在注册表(开始--运行[win+R]--输入regedit)中找到HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc. 将V

docx转doc工具(软件)

word中的docx转成doc格式软件下载: http://pan.baidu.com/s/1ntsi0yt <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize

基于LangChain框架搭建知识库

基于LangChain框架搭建知识库 说明流程1.数据加载2.数据清洗3.数据切分4.获取向量5.向量库保存到本地6.向量搜索7.汇总调用 说明 本文使用openai提供的embedding模型作为框架基础模型,知识库的搭建目的就是为了让大模型减少幻觉出现,实现起来也很简单,假如你要做一个大模型的客服问答系统,那么就把历史客服问答数据整理好,先做数据处理,在做数据向量化,最后保

Python: create object

# encoding: utf-8# 版权所有 2024 涂聚文有限公司# 许可信息查看:# 描述:# Author : geovindu,Geovin Du 涂聚文.# IDE : PyCharm 2023.1 python 3.11# Datetime : 2024/6/15 18:59# User : geovindu# Product :

AI 大模型企业应用实战(11)-langchain 的Document Loader机制

loader机制让大模型具备实时学习的能力: 0 Loader机制 案例环境准备: import osos.environ["OPENAI_API_KEY"] = "sk-javaedge"os.environ["OPENAI_PROXY"] = "https://api.chatanywhere.tech"import osfrom dotenv import load_doten