compass.plugin.one_shot.components.SchemaBasedTextCollector#
- class SchemaBasedTextCollector(*args, **kwargs)[source]#
Bases:
SchemaOutputLLMCaller,BaseTextCollector,ABCText extractor based on a chain of prompts
- Parameters:
llm_service (
Service) – LLM service used for queries.usage_tracker (
UsageTracker, optional) – Optional tracker instance to monitor token usage during LLM calls. By default,None.**kwargs –
Keyword arguments to be passed to the underlying service processing function (i.e.
llm_service.call(**kwargs)). Should not contain the following keys:usage_sub_label
messages
These arguments are provided by this caller object.
Methods
call(sys_msg, content, response_format[, ...])Call LLM for structured data retrieval
check_chunk(chunk_parser, ind)Check a chunk at a given ind to see if it contains ordinance
Attributes
Validation output schema
Identifier for text collected by this class
Extraction schema
Combined extraction text from the individual chunks
- async check_chunk(chunk_parser, ind)[source]#
Check a chunk at a given ind to see if it contains ordinance
- Parameters:
chunk_parser (
ParseChunksWithMemory) – Instance that contains aparse_from_indmethod.ind (
int) – Index of the chunk to check.
- Returns:
bool– Boolean flag indicating whether or not the text in the chunk contains large wind energy conversion system ordinance text.
- async call(sys_msg, content, response_format, usage_sub_label=LLMUsageCategory.DEFAULT)#
Call LLM for structured data retrieval
- Parameters:
sys_msg (
str) – The LLM system message. If this text does not contain the instruction text “Return your answer as a dictionary in JSON format”, it will be added.content (
str) – LLM call content (typically some text to extract info from).usage_sub_label (
str, optional) – Label to store token usage under. By default,"default".response_format (
dict) –Dictionary specifying the expected response format. This will be passed to the underlying LLM service (e.g. OpenAI) and should be formatted according to that service’s specifications for structured output. For example, for OpenAI GPT models, this should be a dictionary with the following keys:
type: Should be set to “json_schema” to indicate that the expected output is structured JSON.
json_schema: A dictionary specifying the expected JSON schema of the output. This should include the following keys:
name: A string name for this response format (e.g. “extracted_features”).
strict: A boolean indicating whether the LLM should strictly adhere to the provided schema (i.e. not include any keys not specified in the schema). If True, the LLM will be instructed to only include keys specified in the schema field. If False, the LLM may include additional keys not specified in the schema field.
schema: A dictionary specifying the expected JSON schema of the output. This should be formatted according to JSON Schema specifications, and should define the expected structure of the output JSON object. For example, it may specify that the output should be an object with certain required properties, and the expected data types of those properties.
- Returns:
dict– Dictionary containing the LLM-extracted features. Dictionary may be empty if there was an error during the LLM call.