Skip to content

How to use document loader in chain? #457

Answered by eyurtsev
magick93 asked this question in Q&A
Discussion options

You must be logged in to vote

Document loaders aren't runnables at the moment, but you can always wrap non runnables in a Runnable Lambda.

from langchain_core.runnables import RunnableLambda

asycc def get_text_to_analyze(url: str) -> str:
    loader = WebBaseLoader(..)
    documents = loader.aload()
    as_text = format_to_text(documents)
    return as_text


chain = RunnableLambda(get_text_to_analyze) | ... rest of extraction chain

Follow good security practices if you expose such chain as an endpoint on a server.

Since it allows an end user to extract things from a URL, a malicious user could also direct the server to access internal network resources that are supposed to be only accessible by the server (and not b…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@magick93
Comment options

Answer selected by eyurtsev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants