Skip to content

gemini_analyzer

GeminiAnalyzer

GeminiAnalyzer(api_key: str, instruction: str, pydantic_schema: Type[BaseModel] = None, model: str = 'gemini-2.0-flash', max_content_size: int = 10000, max_workers: int = 1)

Bases: LlmAnalyzerBase

An LlmAnalyzer that uses the Gemini API.

Parameters:

Name Type Description Default
api_key str

The API key for Gemini.

required
instruction str

The instruction to be used for the LLM.

required
pydantic_schema Type[BaseModel]

The pydantic schema to be used for validating the response.

None
model str

The model to be used for the Gemini API. Defaults to "gemini-2.0-flash".

'gemini-2.0-flash'
max_content_size int

The maximum size of the content to be analyzed. Defaults to 10000 characters.

10000
max_workers int

The maximum number of workers to be used for the analysis. Defaults to 1 due to aggressive rate limiting.

1

validate

validate(test_client: Client = None) -> None

Validates the API key and model by attempting to retrieve the model from the Gemini API.

Parameters:

Name Type Description Default
test_client Client

A test client instance for mocking. Defaults to None.

None

Raises:

Type Description
AssertionError

If the model is not found in the Gemini API.

query_llm async

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

Asynchronously queries the Gemini API with the given content using the configured system instruction.

Parameters:

Name Type Description Default
content str

The textual content to analyze.

required
instruction str

The system instruction to be used by the Gemini API.

required

Returns:

Name Type Description
str str

The generated response content in JSON format.