Skip to content

Instantly share code, notes, and snippets.

@rpappalax
Created January 30, 2026 15:29
Show Gist options
  • Select an option

  • Save rpappalax/d3a0b795ed6189e2d5c3c9f3c93cfec9 to your computer and use it in GitHub Desktop.

Select an option

Save rpappalax/d3a0b795ed6189e2d5c3c9f3c93cfec9 to your computer and use it in GitHub Desktop.
app/llm/gemini_client.py
from __future__ import annotations
from vertexai.preview.generative_models import GenerativeModel, Part
from app.common.config import Settings
from app.llm.vertex_init import init_vertex
def generate(
settings: Settings,
parts: list[Part] | Part,
*,
temperature: float = 0.3,
max_output_tokens: int = 1024,
) -> str:
init_vertex(settings)
model = GenerativeModel(settings.gemini_model)
resp = model.generate_content(
parts,
generation_config={
"temperature": temperature,
"max_output_tokens": max_output_tokens,
},
)
return getattr(resp, "text", "") or ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment