diff --git a/.gitignore b/.gitignore index 7feb5f6..4b2ecdf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,11 @@ gemini_config.json .env .env.* +AGENTS.md +CLAUDE.md # Python __pycache__/ *.py[cod] .venv/ venv/ - diff --git a/AGENTS.md b/AGENTS.md deleted file mode 100644 index 885d55d..0000000 --- a/AGENTS.md +++ /dev/null @@ -1,39 +0,0 @@ -# Repository Guidelines - -## Project Structure & Module Organization -- `google_api.py` is the core module: Gemini client logic, image/tensor helpers, config read/write, and ComfyUI node classes. -- `__init__.py` exposes `NODE_CLASS_MAPPINGS` and `NODE_DISPLAY_NAME_MAPPINGS` for ComfyUI node registration. -- `test_google_api.py` contains manual/integration-style test functions and usage examples. -- `.vscode/settings.json` stores local editor defaults (Conda-based Python environment). - -## Build, Test, and Development Commands -- Create and activate an environment: - - `python -m venv .venv` - - `.venv\Scripts\activate` -- Install dependencies used by this plugin/tests: - - `python -m pip install requests pillow torch numpy pytest` -- Run focused checks: - - `python -m pytest -q test_google_api.py -k config_manager` (local config flow) - - `python -m compileall .` (quick syntax smoke check) -- Run end-to-end examples (requires valid API key and network): - - `python test_google_api.py` - -## Coding Style & Naming Conventions -- Follow Python conventions with 4-space indentation and clear type hints. -- Use `snake_case` for functions/variables, `PascalCase` for classes, and `UPPER_CASE` for constants. -- Keep API transport logic in `GoogleGeminiClient`; keep node classes focused on ComfyUI inputs/outputs. -- When adding nodes, update both registration maps in `__init__.py` (and mirrored maps in `google_api.py` if retained). - -## Testing Guidelines -- Prefer isolated tests for helpers (`pil2tensor`, `tensor2pil`, config functions) before network-dependent flows. -- Separate or clearly label tests that call live Gemini endpoints. -- Do not commit real keys; keep local secrets in `gemini_config.json` only. - -## Commit & Pull Request Guidelines -- Git history is not available in this snapshot; use concise, imperative commit subjects (Conventional style is recommended), e.g. `fix: handle empty API response`. -- Keep commits focused and scoped to one change. -- PRs should include: summary, touched files, validation steps/outputs, and screenshots or workflow examples for node behavior changes. - -## Security & Configuration Tips -- Treat `gemini_config.json` as sensitive local config; exclude it from version control. -- Avoid hardcoding API keys or provider-specific endpoints in test/demo code. diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 29af844..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,60 +0,0 @@ -# CLAUDE.md - -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. - -## Project Overview - -A ComfyUI custom node plugin that wraps the Google Gemini API for image analysis, generation, and editing. Communicates with Gemini via raw REST requests (no official SDK), using a configurable Gemini-compatible endpoint. - -## Development Commands - -```bash -# Environment setup -python -m venv .venv && .venv\Scripts\activate -pip install requests pillow torch numpy pytest - -# Syntax check -python -m compileall . - -# Run integration tests (requires valid API key in gemini_config.json) -python test_google_api.py -``` - -## Architecture - -### Core module: `google_api.py` - -All logic lives in one file, organized into four layers: - -1. **Tensor/PIL utilities** — `pil2tensor()`, `tensor2pil()` for ComfyUI ↔ PIL conversion. -2. **Config persistence** — `get_config()` / `save_config()` read/write `gemini_config.json` (stored next to `__init__.py`). Config holds `api_key`, `base_url`, and a `key_base_url_map` dict that remembers which base_url was used with each API key. -3. **`GoogleGeminiClient`** — HTTP client that builds URLs, resolves base_url (runtime param → key_base_url_map → config default → `DEFAULT_BASE_URL`), and calls `generateContent`. Uses `Authorization: Bearer` header plus `?key=` query param. -4. **ComfyUI node classes** — Each node creates its own `GoogleGeminiClient` instance in `__init__` and calls `apply_runtime_config()` when the user supplies `api_key`/`base_url` at runtime. - -### Node classes - -| Class | Purpose | Key method | -|---|---|---| -| `GoogleGeminiImageAnalysis` | Vision analysis (up to 4 images) | `analyze()` | -| `GoogleGeminiImageGeneration` | Text-to-image generation | `generate()` | -| `GoogleGeminiImageEditing` | Image editing with prompt (up to 4 input images) | `edit()` | -| `GoogleGeminiConfigManager` | Set/get/clear API key and base_url | `manage()` | - -### Node registration - -`__init__.py` imports node classes and exposes `NODE_CLASS_MAPPINGS` / `NODE_DISPLAY_NAME_MAPPINGS`. Duplicate registration maps also exist at the bottom of `google_api.py`. - -## Key Patterns - -- Every node accepts optional `api_key` and `base_url` string inputs that override the saved config. -- `apply_runtime_config()` persists the key↔url pair on first use, so subsequent runs remember the mapping. -- `normalize_base_url()` strips whitespace and trailing slashes for consistent storage/comparison. -- Image nodes use `responseModalities: ["TEXT", "IMAGE"]` in generation config; analysis node only returns text. -- All node methods return tuples matching their `RETURN_TYPES`; errors are returned as string values (not raised). - -## Conventions - -- Chinese comments and print statements throughout; maintain this style. -- 4-space indentation, type hints on function signatures. -- `snake_case` for functions/variables, `PascalCase` for classes, `UPPER_CASE` for constants. -- When adding a new node, update both `NODE_CLASS_MAPPINGS` / `NODE_DISPLAY_NAME_MAPPINGS` in `__init__.py` and at the bottom of `google_api.py`.