Skip to content

llm_analyzer_base

LlmAnalyzerBase

LlmAnalyzerBase(instruction: str, pydantic_schema: Type[BaseModel] = None, max_content_size: int = 10000, max_workers: int = 3)

Bases: IAsyncAnalyzer

Base class for LLM analyzers. This class should not be used directly. This class provides a common interface for LLM analyzers and handles the common logic for analyzing content using LLMs. query_llm() is an abstract method that requires the model to return a json string.

max_workers class-attribute instance-attribute

max_workers: int = 3

The maximum number of workers to be used for the analysis. This should be an integer that specifies the maximum number of concurrent requests.

instruction instance-attribute

instruction: str = instruction

The instruction to be used for the LLM. This should be a string that describes the task to be performed.

pydantic_schema class-attribute instance-attribute

pydantic_schema: Type[BaseModel] = pydantic_schema

The pydantic schema to be used for validating the response. This should be a subclass of pydantic.BaseModel.

max_content_size class-attribute instance-attribute

max_content_size: int = max_content_size

The maximum size of the content to be analyzed. This should be an integer that specifies the maximum number of characters.

query_llm abstractmethod async

query_llm(content: str, instruction: str) -> str

Queries the LLM API with the provided content and instruction.

Parameters:

Name Type Description Default
content str

The content to be analyzed.

required
instruction str

The instruction describing the task for the LLM.

required

Returns:

Name Type Description
str str

A JSON-formatted string response from the LLM.

async_analyze async

async_analyze(content: str) -> AnalysisResult

Analyzes the provided content by querying the LLM and validating the response.

Parameters:

Name Type Description Default
content str

The content to be analyzed. It must be a non-empty string. If the content exceeds the maximum allowed size, it will be truncated.

required

Returns:

Name Type Description
AnalysisResult AnalysisResult

An object indicating the success or failure of the analysis. On success, the output contains the validated response data; on failure, it contains an error message.