English 中文(简体)
• 如何从地块中形成环链条?
原标题: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 :

  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:

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

电话方法:

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

即时模板:

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 

当我试图在使用文件链条之前检查文件物体的类型和页数时,我就这样做。

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


最佳回答

我也有一个类似的问题,我注意到APIC申请名单,因此试图这样做。

    doc = Document(page_content=input,
            metatdata={
                "source": "userinput"
            }
        )
    #db.add_documents(doc)
    db.add_documents([doc])
问题回答

这为我工作:

from langchain.docstore.document import Document

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

首先,有些情况。 从我迄今学到的内容来看,文件是Document 反对清单。 如您操作type(doc[0]),请上langchain.schema.document.。 http://www.un.org/Depts/DGACM/index_french.htm www.un.org/Depts/DGACM/index_french.htm 顺便提一下(登机引述我的话):这是审判和错误的许多内容,正如你提到的那样,没有文件),是“先发”的<代码。 包含上述两项关键内容,并在其<代码>metadata:中包含一个关键词:{source:},但仅接受方言。 可通过创建<条码>>><>>>>>>>> > > 代码创建多个“网页”文件标。 类似物体:

首先,您必须有一个图表清单:text_list,以及一份元数据词表:text_list。 <>你必须确保两份名单的长度相同。

from langchain.docstore.document import Document

document =  []

for item in range(len(text_string)):
    page = Document(page_content=doc_text_splits[item],
    metadata = metadata_string[item])
    doc.append(page)

此外,还可使用从LangChain分离的任何物体创建Document:

from langchain.text_splitter import CharacterTextSplitter

doc_creator = CharacterTextSplitter(parameters)

document = doc_creator.create_documents(texts = text_list, metadatas = metadata_list)

参看以下法典,

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

这是我能够取得的最佳结果。

def str_to_doc(text,name):
   folder_name =  docs 
   if not os.path.exists(folder_name):
       os.makedirs(folder_name)
   file_name = name+ .txt 
   path = os.path.join(folder_name, file_name)
   with open(path, "w") as file:
        file.write(text)
   loader = TextLoader(path)
   return loader.load()






相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签