LLM Query¶
- class sycamore.transforms.llm_query.LLMTextQueryAgent(prompt: str, llm: LLM, output_property: str = 'llm_response', format_kwargs: dict[str, Any] | None = None, number_of_elements: int | None = None, llm_kwargs: dict = {}, per_element: bool = True, element_type: str | None = None, table_cont: bool | None = False)[source]¶
Bases:
object
LLMTextQueryAgent uses a specified LLM to execute LLM queries about a document or its child elements.
- Parameters:
prompt -- A prompt to be passed into the underlying LLM execution engine
llm -- The LLM Client to be used here. It is defined as an instance of the LLM class in Sycamore.
output_property -- (Optional, default="llm_response") The output property of the document or element to add results in.
format_kwargs -- (Optional, default="None") If passed in, details the formatting details that must be passed into the underlying Jinja Sandbox.
number_of_elements -- (Optional, default="None") When "per_element" is true, limits the number of elements to add an "output_property". Otherwise, the response is added to the entire document using a limited prefix subset of the elements.
llm_kwargs -- (Optional) LLM keyword argument for the underlying execution engine
per_element -- (Optional, default="{}") Keyword arguments to be passed into the underlying LLM execution engine.
element_type -- (Optional) Parameter to only execute the LLM query on a particular element type. If not specified, the query will be executed on all elements.
Example
prompt="Tell me the important numbers from this element" llm_query_agent = LLMTextQueryAgent(prompt=prompt) context = sycamore.init() pdf_docset = context.read.binary(paths, binary_format="pdf") .partition(partitioner=ArynPartitioner()) .llm_query(query_agent=llm_query_agent)