Skip to content

Add LLM client, prompt builders, and prompt templates - #16

Open
qu4rkn3t wants to merge 1 commit into
cloud-bulldozer:mainfrom
qu4rkn3t:phase2/llm
Open

Add LLM client, prompt builders, and prompt templates#16
qu4rkn3t wants to merge 1 commit into
cloud-bulldozer:mainfrom
qu4rkn3t:phase2/llm

Conversation

@qu4rkn3t

@qu4rkn3t qu4rkn3t commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Type of change

  • Refactor
  • New feature
  • Bug fix
  • Optimization
  • Documentation Update

Description

Gemini LLM client built with google-genai SDK with support for structured output, token counting, and embeddings. Also includes the flash and frontier prompt builders, which handle context-window splitting when the commit set is too large for a single prompt. The design follows spec -> provider -> model.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Testing

Passed tests in Phase 2 tests

@qu4rkn3t
qu4rkn3t requested review from vishnuchalla and a lite review from Copilot August 5, 2026 13:21
@qu4rkn3t qu4rkn3t added the enhancement New feature or request label Aug 5, 2026
@qu4rkn3t qu4rkn3t self-assigned this Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the initial building blocks for Phase 2 “commit triage” LLM support: prompt templates for the flash/frontier stages, prompt assembly/splitting logic based on token budgets, and a Google (Gemini) LLM client abstraction intended to support token counting, structured output, and embeddings.

Changes:

  • Added markdown prompt templates for the “flash” and “frontier” LLM stages.
  • Implemented prompt construction utilities that assemble PR/commit/diff context and split prompts to fit within a token budget.
  • Added a Google GenAI (Gemini) LLM client abstraction for counting tokens, generating text/structured outputs, and producing embeddings.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
perf_keeper/commit_triage/templates/frontier.md Adds the frontier-stage prompt template and JSON response shape guidance.
perf_keeper/commit_triage/templates/flash.md Adds the flash-stage prompt template and JSON response shape guidance.
perf_keeper/commit_triage/prompts.py Implements regression header + PR/commit blocks and token-budget prompt splitting.
perf_keeper/commit_triage/llm.py Introduces the LLM client abstraction and a Google GenAI-backed implementation.
Suppressed comments (5)

perf_keeper/commit_triage/prompts.py:19

  • perf_keeper.commit_triage.models does not exist in the repo; the models referenced here (CommitModel/FileModel/PRModel/RegressionContext) already exist in perf_keeper/models.py. As written, this import will raise ModuleNotFoundError.
from perf_keeper.commit_triage.models import (
    CommitModel,
    FileModel,
    PRModel,
    RegressionContext,
)

perf_keeper/commit_triage/llm.py:27

  • perf_keeper.commit_triage.models is not present in the repo, and the imported symbols here (CommitRanking, FlashDecision, FlashResponse, FrontierResponse) are not defined anywhere else. This will raise ModuleNotFoundError (and also makes the __all__ entries invalid). Either add the missing models module or remove these imports/re-exports until the schemas exist.
from perf_keeper.commit_triage.models import (
    CommitRanking,
    FlashDecision,
    FlashResponse,
    FrontierResponse,
)

perf_keeper/commit_triage/llm.py:169

  • complete() calls generate_content() directly, so the retry/backoff logic in _request() is bypassed. This can make prompt generation flaky under rate limits or transient 5xx errors.
        response = await self._client.aio.models.generate_content(
            model=self.model.model_id,
            contents=prompt,
            config=types.GenerateContentConfig(
                temperature=self._temperature,

perf_keeper/commit_triage/llm.py:183

  • complete_structured() bypasses _request() and calls generate_content() directly, so structured generations won't be retried on 429/5xx. Using _request() here helps avoid intermittent empty/partial results under load.
        response = await self._client.aio.models.generate_content(
            model=self.model.model_id,
            contents=prompt,
            config=types.GenerateContentConfig(
                temperature=self._temperature,

perf_keeper/commit_triage/llm.py:200

  • embed() bypasses _request() and calls the embedding endpoint directly, so transient rate limits / server errors won't be retried.
        logger.debug("Embedding with %s", EMBEDDING_MODEL)
        response = await self._client.aio.models.embed_content(
            model=EMBEDDING_MODEL,
            contents=text,
        )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +9 to +12
from perf_keeper.commit_triage.config import (
CONTEXT_BUDGET_FRACTION,
HUNK_HEADER_RE,
)
Comment on lines +221 to +223
texts = [header, footer_template.replace("{commit_keys}", "")] + [
block + ", ".join(keys) for block, keys in pr_blocks
]
Comment on lines +14 to +21
from perf_keeper.commit_triage.config import (
CONTEXT_BUDGET_FRACTION,
DEFAULT_MAX_OUTPUT_TOKENS,
DEFAULT_TEMPERATURE,
EMBEDDING_MODEL,
FALLBACK_CONTEXT_WINDOW,
MAX_RETRIES,
)
Comment thread perf_keeper/commit_triage/llm.py Outdated
Comment on lines +151 to +154
response = await self._client.aio.models.count_tokens(
model=self.model.model_id,
contents=text,
)
Comment on lines +18 to +23
{
"commit_key": "<string>",
"triage_score": "<integer 0–100>",
"confidence": "<low | medium | high>",
"reasoning": "<string>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants