Skip to content

API Reference parrot.clients.google.analysis

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.clients.google.analysis

View source

Alias AIMessage

Re-exported from parrot.models.AIMessage.

Alias AIMessageFactory

Re-exported from parrot.models.AIMessageFactory.

Alias CompletionUsage

Re-exported from parrot.models.CompletionUsage.

Alias DetectionBox

Re-exported from parrot.models.detections.DetectionBox.

Class GoogleAnalysis

Mixin class for Google Generative AI analysis capabilities.

Attributes:

Attribute Type Description
logger logging.Logger

Method GoogleAnalysis.analyze_sentiment

Perform sentiment analysis on text and return an AIMessage response.

analyze_sentiment(text: str, model: Union[GoogleModel, str] = GoogleModel.GEMINI_3_8_FLASH, temperature: Optional[float] = 0.1, user_id: Optional[str] = None, session_id: Optional[str] = None, use_structured: bool = False) -> AIMessage

Parameter Type Default Description
text str
model Union[GoogleModel, str] GoogleModel.GEMINI_3_8_FLASH
temperature Optional[float] 0.1
user_id Optional[str] None
session_id Optional[str] None
use_structured bool False

Returns: AIMessage

Method GoogleAnalysis.analyze_product_review

Analyze a product review and extract structured or unstructured information.

Returns an AIMessage. When use_structured=True, the structured output is available via ai_message.structured_output.

analyze_product_review(review_text: str, product_id: str, model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, temperature: Optional[float] = 0.1, user_id: Optional[str] = None, session_id: Optional[str] = None, use_structured: bool = True) -> AIMessage

Parameter Type Default Description
review_text str
product_id str
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH
temperature Optional[float] 0.1
user_id Optional[str] None
session_id Optional[str] None
use_structured bool True

Returns: AIMessage

Method GoogleAnalysis.video_understanding

Using a video (local or youtube) no analyze and extract information from videos.

video_understanding(prompt: str, model: Union[str, GoogleModel] = GoogleModel.GEMINI_FLASH_LATEST, prompt_instruction: Optional[str] = None, video: Optional[Union[str, Path]] = None, user_id: Optional[str] = None, session_id: Optional[str] = None, stateless: bool = True, history: Optional[Sequence[HistoryMessage]] = None, offsets: Optional[tuple[str, str]] = None, reference_images: Optional[List[Union[str, Path, Image.Image]]] = None, timeout: Optional[int] = 600, top_p: Optional[float] = None, top_k: Optional[int] = None, max_output_tokens: Optional[int] = None, candidate_count: Optional[int] = None, progress_log_interval: int = 10, as_image: bool = False, interval_sec: Optional[int] = None, structured_output: Union[type, StructuredOutputConfig, None] = None) -> AIMessage

Parameter Type Default Description
prompt str
model Union[str, GoogleModel] GoogleModel.GEMINI_FLASH_LATEST
prompt_instruction Optional[str] None
video Optional[Union[str, Path]] None
user_id Optional[str] None
session_id Optional[str] None
stateless bool True
history Optional[Sequence[HistoryMessage]] None
offsets Optional[tuple[str, str]] None
reference_images Optional[List[Union[str, Path, Image.Image]]] None
timeout Optional[int] 600
top_p Optional[float] None
top_k Optional[int] None
max_output_tokens Optional[int] None
candidate_count Optional[int] None
progress_log_interval int 10
as_image bool False
interval_sec Optional[int] None
structured_output Union[type, StructuredOutputConfig, None] None

Returns: AIMessage

Method GoogleAnalysis.image_understanding

Using single or multiple images to analyze and extract information, with optional object detection.

image_understanding(prompt: str, images: Union[str, Path, bytes, Image.Image, List[Union[str, Path, bytes, Image.Image]]], model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_FLASH_PREVIEW, prompt_instruction: Optional[str] = None, user_id: Optional[str] = None, session_id: Optional[str] = None, stateless: bool = True, timeout: Optional[int] = 600, temperature: Optional[float] = None, detect_objects: bool = False, response_schema: Optional[Any] = None, structured_output: Union[type, StructuredOutputConfig, None] = None) -> AIMessage

Parameter Type Default Description
prompt str
images Union[str, Path, bytes, Image.Image, List[Union[str, Path, bytes, Image.Image]]]
model Union[str, GoogleModel] GoogleModel.GEMINI_3_FLASH_PREVIEW
prompt_instruction Optional[str] None
user_id Optional[str] None
session_id Optional[str] None
stateless bool True
timeout Optional[int] 600
temperature Optional[float] None
detect_objects bool False
response_schema Optional[Any] None
structured_output Union[type, StructuredOutputConfig, None] None

Returns: AIMessage

Method GoogleAnalysis.document_understanding

Analyze and extract information from one or more documents.

Supports all Gemini-compatible document types: PDF, TXT, HTML, CSS, JS, PY, MD, CSV, XML, RTF, DOCX, XLSX, PPTX, etc.

Files are uploaded via the Google GenAI Files API. Files larger than 50 MB are rejected with a ValueError.

Note: The 50 MB limit is a user-configured guardrail, not a Gemini API restriction. The Files API supports files up to 2 GB, but this method enforces a smaller cap to prevent accidental upload of very large files.

document_understanding(prompt: str, documents: Union[str, Path, List[Union[str, Path]]], model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, prompt_instruction: Optional[str] = None, user_id: Optional[str] = None, session_id: Optional[str] = None, stateless: bool = True, history: Optional[Sequence[HistoryMessage]] = None, timeout: Optional[int] = 600, temperature: float = 0.0, structured_output: Optional[Union[type, StructuredOutputConfig]] = None, max_output_tokens: Optional[int] = None) -> AIMessage

Parameter Type Default Description
prompt str The question or instruction about the document(s).
documents Union[str, Path, List[Union[str, Path]]] Path(s) to local document file(s). Accepts a single path (str or Path) or a list of paths.
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH Gemini model to use.
prompt_instruction Optional[str] None Optional system instruction for the model.
user_id Optional[str] None Optional user ID for conversation memory (stateful mode).
session_id Optional[str] None Optional session ID for conversation memory (stateful mode).
stateless bool True If True, skip conversation memory (default True).
history Optional[Sequence[HistoryMessage]] None
timeout Optional[int] 600 Timeout in seconds for the API call (default 600).
temperature float 0.0 Sampling temperature. Defaults to 0.0 for deterministic document analysis.
structured_output Optional[Union[type, StructuredOutputConfig]] None Optional Pydantic model class or :class:StructuredOutputConfig for typed response parsing. When provided, AIMessage.structured_output is populated with the parsed object.
max_output_tokens Optional[int] None Optional maximum number of output tokens.

Returns: AIMessage — class:AIMessage with the model's response. If structured_output is provided, AIMessage.structured_output contains the parsed object.

Raises:

  • ValueError — If any file exceeds 50 MB or a document upload fails.
  • FileNotFoundError — If any document path does not exist.

Method GoogleAnalysis.transcribe_audio

Transcribe the speech in an audio clip (speech to text).

Small clips are sent inline. A larger file is uploaded through the Files API first, which only the Gemini Developer API offers: on Vertex AI such a file is refused.

transcribe_audio(audio: Union[str, Path, bytes], mime_type: Optional[str] = None, language: Optional[str] = None, model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, prompt: Optional[str] = None, timeout: Optional[int] = 120) -> AIMessage

Parameter Type Default Description
audio Union[str, Path, bytes] Path to a local audio file, or the raw audio bytes.
mime_type Optional[str] None MIME type of the audio. For a path it is inferred from the file extension when omitted; for raw bytes it defaults to audio/wav.
language Optional[str] None Optional BCP-47 language hint ("es", "en-US"). None lets the model detect the language.
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH Gemini model to use.
prompt Optional[str] None Optional instruction that replaces the default verbatim transcription prompt.
timeout Optional[int] 120 Timeout in seconds for the API call.

Returns: AIMessage — class:AIMessage whose output is the transcript ("" when nothing was said).

Raises:

  • FileNotFoundError — If audio is a path that does not exist.
  • ValueError — If language is not a language tag, the audio is empty, raw bytes exceed the inline request limit, or a file exceeds it on a Vertex AI client.

Method GoogleAnalysis.image_identification

Identify products using detected boxes, reference images, and Gemini Vision.

This method sends the full image, reference images, and individual crops of each detection to Gemini for precise identification, returning a structured list of IdentifiedProduct objects.

image_identification(prompt: str, image: Union[Path, bytes, Image.Image], detections: List[DetectionBox], shelf_regions: List[ShelfRegion], reference_images: Optional[Dict[str, Union[Path, bytes, Image.Image]]] = None, model: Union[str, GoogleModel] = GoogleModel.GEMINI_4_ARGON, temperature: float = 0.0, user_id: Optional[str] = None, session_id: Optional[str] = None) -> List[IdentifiedProduct]

Parameter Type Default Description
prompt str
image Union[Path, bytes, Image.Image] The main image of the retail display.
detections List[DetectionBox] A list of DetectionBox objects from the initial detection step.
shelf_regions List[ShelfRegion] A list of ShelfRegion objects defining shelf boundaries.
reference_images Optional[Dict[str, Union[Path, bytes, Image.Image]]] None Optional list of images showing ideal products.
model Union[str, GoogleModel] GoogleModel.GEMINI_4_ARGON The Gemini model to use, defaulting to Gemini 2.5 Pro for its advanced vision capabilities.
temperature float 0.0 The sampling temperature for the model's response.
user_id Optional[str] None
session_id Optional[str] None

Returns: List[IdentifiedProduct] — A list of IdentifiedProduct objects with detailed identification info.

Method GoogleAnalysis.summarize_text

Generates a summary for a given text in a stateless manner.

summarize_text(text: str, max_length: int = 1200, min_length: int = 100, model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, temperature: Optional[float] = None, user_id: Optional[str] = None, session_id: Optional[str] = None) -> AIMessage

Parameter Type Default Description
text str
max_length int 1200
min_length int 100
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH
temperature Optional[float] None
user_id Optional[str] None
session_id Optional[str] None

Returns: AIMessage

Method GoogleAnalysis.translate_text

Translates a given text from a source language to a target language.

translate_text(text: str, target_lang: str, source_lang: Optional[str] = None, model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, temperature: Optional[float] = 0.2, user_id: Optional[str] = None, session_id: Optional[str] = None) -> AIMessage

Parameter Type Default Description
text str
target_lang str
source_lang Optional[str] None
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH
temperature Optional[float] 0.2
user_id Optional[str] None
session_id Optional[str] None

Returns: AIMessage

Method GoogleAnalysis.extract_key_points

Extract num_points bullet-point key ideas from text (stateless).

extract_key_points(text: str, num_points: int = 5, model: Union[str, GoogleModel] = GoogleModel.GEMINI_3_8_FLASH, temperature: Optional[float] = 0.3, user_id: Optional[str] = None, session_id: Optional[str] = None) -> AIMessage

Parameter Type Default Description
text str
num_points int 5
model Union[str, GoogleModel] GoogleModel.GEMINI_3_8_FLASH
temperature Optional[float] 0.3
user_id Optional[str] None
session_id Optional[str] None

Returns: AIMessage

Method GoogleAnalysis.detect_objects

Detects objects and segmentation masks using Gemini 3 Flash. Based on provided sample code.

detect_objects(image: Union[str, Path, Image.Image], prompt: str, reference_images: Optional[List[Union[str, Path, Image.Image]]] = None, output_dir: Optional[Union[str, Path]] = None) -> List[Dict[str, Any]]

Parameter Type Default Description
image Union[str, Path, Image.Image]
prompt str
reference_images Optional[List[Union[str, Path, Image.Image]]] None
output_dir Optional[Union[str, Path]] None

Returns: List[Dict[str, Any]]

Alias GoogleModel

Re-exported from parrot.clients.google.models.GoogleModel.

Alias HistoryMessage

Re-exported from parrot.memory.render.HistoryMessage.

Alias IdentificationResponse

Re-exported from parrot.models.detections.IdentificationResponse.

Alias IdentifiedProduct

Re-exported from parrot.models.detections.IdentifiedProduct.

Alias InvokeError

Re-exported from parrot.exceptions.InvokeError.

Alias ProductReview

Re-exported from parrot.models.outputs.ProductReview.

Alias SentimentAnalysis

Re-exported from parrot.models.outputs.SentimentAnalysis.

Alias ShelfRegion

Re-exported from parrot.models.detections.ShelfRegion.

Alias StructuredOutputConfig

Re-exported from parrot.models.StructuredOutputConfig.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally