lasagnastack.llm.gemini¶
lasagnastack.llm.gemini
¶
GeminiClient
¶
GeminiClient(
api_key: str | None = None,
model: str | None = None,
reasoning_max_tokens: int = 4000,
reasoning_effort: str | None = None,
total_max_tokens: int | None = None,
)
Bases: LLMClient
LLM client backed by the Gemini Developer API.
Wraps google-genai with structured JSON output, tenacity retries, a
JSON-repair loop, and MLflow span tracing for every API call.
Initialise the Gemini client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Gemini Developer API key. Falls back to the
|
None
|
model
|
str | None
|
Model name to use for all calls (LiteLLM naming convention).
Falls back to the |
None
|
reasoning_max_tokens
|
int
|
Maximum thinking tokens per call, forwarded
as |
4000
|
reasoning_effort
|
str | None
|
Accepted for interface compatibility; not used by the Gemini native API. |
None
|
total_max_tokens
|
int | None
|
Accepted for interface compatibility; not used by the Gemini native API. |
None
|
Source code in src/lasagnastack/llm/gemini.py
session_stats
property
¶
Aggregated token and cost totals across all calls on this instance.
Returns:
| Type | Description |
|---|---|
dict[str, float | int]
|
A dict with keys |
dict[str, float | int]
|
|
generate
¶
generate(
prompt: str,
response_schema: type[BaseModel],
*,
temperature: float = 0.4,
) -> BaseModel
Send a text-only prompt; return a validated response_schema instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
The plain-text prompt to send. |
required |
response_schema
|
type[BaseModel]
|
Pydantic model class that defines the expected JSON structure of the response. |
required |
temperature
|
float
|
Sampling temperature passed to the model. |
0.4
|
Returns:
| Type | Description |
|---|---|
BaseModel
|
A validated instance of |
Source code in src/lasagnastack/llm/gemini.py
generate_with_video
¶
generate_with_video(
video_path: Path,
prompt: str,
response_schema: type[BaseModel],
*,
temperature: float = 0.4,
) -> BaseModel
Upload video_path to the Files API, generate, return validated response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
video_path
|
Path
|
Local path to the MP4 clip to analyse. |
required |
prompt
|
str
|
Text prompt sent alongside the video. |
required |
response_schema
|
type[BaseModel]
|
Pydantic model class for the expected JSON response. |
required |
temperature
|
float
|
Sampling temperature passed to the model. |
0.4
|
Returns:
| Type | Description |
|---|---|
BaseModel
|
A validated instance of |