Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2024-05-21 - [Blender Modal Redraws]
**Learning:** Blender `modal` operators run frequently (e.g. every 0.3s). Calling `area.tag_redraw()` unconditionally in the loop forces constant viewport rendering, even when no state has changed, causing unnecessary CPU/GPU load.
**Action:** Only call `tag_redraw()` when the operator actually processes data or updates the UI state (e.g., via a `refresh_needed` flag).

## 2024-05-23 - [API Client Overhead]
**Learning:** Instantiating `google.genai.Client` is not cheap (measured ~100ms per call). When making multiple sequential or parallel API calls, re-creating the client inside the loop adds significant cumulative overhead (~500ms for 5 calls).
**Action:** Initialize API clients once at the start of the workflow (e.g. in the operator or main function) and pass the instance to helper functions via dependency injection.
10 changes: 6 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def get_client(api_key):
return genai.Client(api_key=api_key)


def refine_prompt(api_key, prompt):
def refine_prompt(api_key, prompt, client=None):
"""Use Gemini to refine a prompt for 3D model generation."""
client = get_client(api_key)
if client is None:
client = get_client(api_key)
Comment on lines +19 to +22

Choose a reason for hiding this comment

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

medium

The function signature can be improved to better reflect its dependencies. Currently, api_key is a required positional argument, but it's only used if client is not provided. This can be confusing for callers. Consider making api_key an optional keyword argument and reordering arguments for clarity. You should also raise an error if neither client nor api_key is provided. This makes the API contract clearer.

This change will require updating the call sites in operators.py.

def refine_prompt(prompt, client=None, api_key=None):
    """Use Gemini to refine a prompt for 3D model generation."""
    if client is None:
        if not api_key:
            raise ValueError("Either 'client' or 'api_key' must be provided.")
        client = get_client(api_key)


instruction = (
f"Refine this prompt for generating a high-quality 3D model reference image. "
Expand All @@ -36,15 +37,16 @@ def refine_prompt(api_key, prompt):
return response.text.strip()


def generate_image(api_key, prompt, output_path, input_image_path=None):
def generate_image(api_key, prompt, output_path, input_image_path=None, client=None):
"""
Generate an image using Gemini.
If input_image_path is provided, use it as reference for the generation.
"""
from google.genai import types
from PIL import Image

client = get_client(api_key)
if client is None:
client = get_client(api_key)
Comment on lines +40 to +49

Choose a reason for hiding this comment

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

medium

Similar to refine_prompt, the signature for generate_image can be improved. api_key is required but only used as a fallback. Making it an optional keyword argument, reordering arguments, and validating that either client or api_key is present would create a clearer API.

This change will require updating the call sites in operators.py.

def generate_image(prompt, output_path, input_image_path=None, client=None, api_key=None):
    """
    Generate an image using Gemini.
    If input_image_path is provided, use it as reference for the generation.
    """
    from google.genai import types
    from PIL import Image

    if client is None:
        if not api_key:
            raise ValueError("Either 'client' or 'api_key' must be provided.")
        client = get_client(api_key)


config = types.GenerateContentConfig(
response_modalities=["Image"],
Expand Down
Loading