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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ codewiki --version

### 2. Configure Your Environment

CodeWiki supports multiple LLM providers: **OpenAI-compatible**, **Anthropic**, **AWS Bedrock**, and **Azure OpenAI**.
CodeWiki supports multiple LLM providers: **OpenAI-compatible**, **Anthropic**, **AWS Bedrock**, **Azure OpenAI**, and **Google Gemini**.

```bash
# Anthropic
Expand All @@ -68,6 +68,13 @@ codewiki config set \
--aws-region us-east-1 \
--main-model anthropic.claude-sonnet-4-v2:0 \
--cluster-model anthropic.claude-sonnet-4-v2:0

# Google Gemini
codewiki config set \
--provider gemini \
--api-key YOUR_GEMINI_API_KEY \
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The Gemini quick-start omits --base-url, but the CLI configuration model and config validate currently require base_url to be set (and will error with “Base URL not set” before reaching the Gemini connectivity test). Either update the docs to include a valid Gemini base URL (or explain that an existing base URL must remain set), or adjust configuration/validation logic to make base_url optional when provider=gemini.

Suggested change
--api-key YOUR_GEMINI_API_KEY \
--api-key YOUR_GEMINI_API_KEY \
--base-url https://generativelanguage.googleapis.com \

Copilot uses AI. Check for mistakes.
--main-model gemini-2.5-pro \
--cluster-model gemini-2.5-pro
```

### 3. Generate Documentation
Expand Down Expand Up @@ -351,7 +358,7 @@ CodeWiki employs a three-stage process for comprehensive documentation generatio

- **Python 3.12+**
- **Node.js** (for Mermaid diagram validation)
- **LLM API access** (Anthropic Claude, OpenAI, Azure OpenAI, AWS Bedrock)
- **LLM API access** (Anthropic Claude, OpenAI, Azure OpenAI, AWS Bedrock, Google Gemini)
- **Git** (for branch creation features)

---
Expand Down
7 changes: 6 additions & 1 deletion codewiki/cli/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def config_group():
)
@click.option(
"--provider",
type=click.Choice(['openai-compatible', 'anthropic', 'bedrock', 'azure-openai'], case_sensitive=False),
type=click.Choice(['openai-compatible', 'anthropic', 'bedrock', 'azure-openai', 'gemini'], case_sensitive=False),
help="LLM provider type (default: openai-compatible)"
)
@click.option(
Expand Down Expand Up @@ -565,6 +565,11 @@ def config_validate(quick: bool, verbose: bool):
azure_endpoint=config.base_url,
)
client.models.list()
elif provider == "gemini":
# Use Google Gemini SDK
from google import genai
gemini_client = genai.Client(api_key=api_key)
list(gemini_client.models.list())
Comment on lines +568 to +572
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Skip mandatory base URL for Gemini validation

The new Gemini connectivity branch is not reachable for the documented Gemini setup because this command still hard-fails earlier when config.base_url is empty (config_validate step 3 exits at lines 509-512). Since the README example added in this commit configures Gemini without --base-url, users can select --provider gemini but then fail validation (and related configured-state checks) before Gemini-specific API testing runs. Make base-URL validation provider-aware (or set a Gemini default URL) so Gemini configs can pass.

Useful? React with 👍 / 👎.

Comment on lines +568 to +572
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The Gemini connectivity test added here is gated by earlier validation that always requires config.base_url to be set and valid. This makes the Gemini provider UX inconsistent (Gemini doesn’t need a base URL, and the README example omits it) and means a fresh Gemini-only config will fail before reaching this branch. Consider skipping the base-URL-required check when provider == "gemini" (and avoid printing/validating it), or auto-populate a sensible default base URL when users select the Gemini provider.

Copilot uses AI. Check for mistakes.
elif "api.anthropic.com" in base_url_lower:
# Use Anthropic SDK for native Anthropic endpoints
import anthropic
Expand Down
48 changes: 46 additions & 2 deletions codewiki/src/be/llm_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Includes a compatibility layer for OpenAI-compatible API proxies that may
return slightly non-standard responses (e.g. choices[].index = None).

Supports multiple providers: openai-compatible, anthropic, bedrock, azure-openai.
Supports multiple providers: openai-compatible, anthropic, bedrock, azure-openai, gemini.
"""
import logging
from openai.types import chat
Expand Down Expand Up @@ -57,13 +57,17 @@ def _get_litellm_model_name(model_name: str, provider: str) -> str:

For Bedrock, prefixes the model name with 'bedrock/' if not already prefixed.
For Anthropic, prefixes with 'anthropic/' if not already prefixed.
For Gemini, prefixes with 'gemini/' if not already prefixed.
"""
if provider == "bedrock":
if not model_name.startswith("bedrock/"):
return f"bedrock/{model_name}"
elif provider == "anthropic":
if not model_name.startswith("anthropic/"):
return f"anthropic/{model_name}"
elif provider == "gemini":
if not model_name.startswith("gemini/"):
return f"gemini/{model_name}"
return model_name


Expand Down Expand Up @@ -154,8 +158,9 @@ def call_llm(
"""
Call LLM with the given prompt.

Supports openai-compatible, anthropic, and bedrock providers.
Supports openai-compatible, anthropic, bedrock, azure-openai, and gemini providers.
For bedrock/anthropic, uses litellm to translate the API call.
For gemini, uses the google-genai SDK directly.

Args:
prompt: The prompt to send
Expand All @@ -177,6 +182,9 @@ def call_llm(
if provider == "azure-openai":
return _call_llm_via_azure(prompt, config, model, temperature)

if provider == "gemini":
return _call_llm_via_gemini(prompt, config, model, temperature)

# Default: OpenAI-compatible
client = create_openai_client(config)

Expand Down Expand Up @@ -260,3 +268,39 @@ def _call_llm_via_azure(
max_tokens=config.max_tokens,
)
return response.choices[0].message.content


def _call_llm_via_gemini(
prompt: str,
config: Config,
model: str,
temperature: float = 0.0
) -> str:
"""
Call LLM via Google Gemini using the google-genai SDK.

Uses the google.genai client with the provided API key.
The model name may optionally include a 'gemini/' prefix, which is
stripped before passing to the SDK.
"""
from google import genai
from google.genai import types as genai_types

api_key = config.llm_api_key
# Strip the 'gemini/' litellm prefix if present
sdk_model = model[len("gemini/"):] if model.startswith("gemini/") else model

logger.debug("Calling Gemini model %s via google-genai SDK", sdk_model)

client = genai.Client(api_key=api_key)
response = client.models.generate_content(
model=sdk_model,
contents=prompt,
config=genai_types.GenerateContentConfig(
temperature=temperature,
max_output_tokens=config.max_tokens,
),
)
if response.text is None:
raise ValueError(f"Gemini model {sdk_model} returned an empty response")
return response.text
4 changes: 2 additions & 2 deletions codewiki/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Config:
cluster_model: str
fallback_model: str = FALLBACK_MODEL_1
# Provider configuration
provider: str = "openai-compatible" # openai-compatible, anthropic, bedrock, azure-openai
provider: str = "openai-compatible" # openai-compatible, anthropic, bedrock, azure-openai, gemini
aws_region: str = "us-east-1"
api_version: str = "2024-12-01-preview" # Azure OpenAI API version
azure_deployment: str = "" # Azure OpenAI deployment name
Expand Down Expand Up @@ -181,7 +181,7 @@ def from_cli(
main_model: Primary model
cluster_model: Clustering model
fallback_model: Fallback model
provider: LLM provider type (openai-compatible, anthropic, bedrock, azure-openai)
provider: LLM provider type (openai-compatible, anthropic, bedrock, azure-openai, gemini)
aws_region: AWS region for Bedrock provider
api_version: Azure OpenAI API version
azure_deployment: Azure OpenAI deployment name
Expand Down