LangChain.ScrapeChain (langchainex v0.1.0)
Use this when you want to extract formatted data from natural-language text, ScrapeChain is basically a special form of QueryChain. ScrapeChain is a wrapper around a special type of Chain that requires 'inputSchema' and 'inputText' in its inputVariables and combines it with an outputParser. Once you define that chain, you can have the chain 'scrape' a text and return the formatted output in virtually any form.
Link to this section Summary
Functions
Creates a new ScrapeChain struct with the given chain, inputSchema, and outputParser, you set up a scrapeChain with an inputSchema and an outputParser, then you can call it with whatever text you want.
default passthrough parser. 'result' will be a string so it is up to you to transform it into a native elixir structure or whatever you want.
Executes the ScrapeChain with a specific inputText and inputSchema and returns the parsed result: inputVariables = %{
Link to this section Functions
new(chain, inputSchema, outputParser \\ &LangChain.ScrapeChain.noParse/1)
Creates a new ScrapeChain struct with the given chain, inputSchema, and outputParser, you set up a scrapeChain with an inputSchema and an outputParser, then you can call it with whatever text you want.
example
Example:
create a chat to extract data:
chat = Chat.addPromptTemplates(%Chat{}, [ %{
role: "user",
prompt: %PromptTemplate{
template: "Schema: """
<%= inputSchema %>
"""
Text: """
<%= inputText %>
"" Extract the data from Text according to Schema and return it in <%= outputFormat %> format.
Format any datetime fields using ISO8601 standard.
"
}
} ])
create a ChainLink with the chat and parser function
chain_link = %ChainLink{ name: "schema_extractor", input: chat, outputParser: &schema_parser/2 }
chain = %Chain{links: [chain_link]} input_schema = "{ name: String, age: Number, birthdate: Date }" schema_chain = LangChain.ScrapeChain.new(chain, input_schema)
noParse(result)
default passthrough parser. 'result' will be a string so it is up to you to transform it into a native elixir structure or whatever you want.
scrape(scrape_chain, inputVariables)
Executes the ScrapeChain with a specific inputText and inputSchema and returns the parsed result: inputVariables = %{
inputText: "John Doe is 30 years old.",
inputSchema: "{ name: String, age: Number, birthdate: Date }"
}