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
31 changes: 31 additions & 0 deletions README.ja-JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ export OCR_USE_ANTHROPIC=true

また、Claude Codeの環境変数(`ANTHROPIC_BASE_URL`、`ANTHROPIC_AUTH_TOKEN`、`ANTHROPIC_MODEL`)とも互換性があり、`~/.zshrc` / `~/.bashrc`からこれらのexportをパースします。

### Google Vertex AIでClaudeを使用

OCRはGoogle Application Default Credentials(ADC)を使ってVertex AI上のClaudeを呼び出せます。Anthropic APIキーやカスタムLLM URLは不要です:

```bash
export OCR_USE_VERTEX=true
export OCR_LLM_MODEL=claude-sonnet-4-6
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global

gcloud auth application-default login
ocr llm test
```

OCR専用の別名として`OCR_VERTEX_PROJECT_ID`と`OCR_VERTEX_REGION`もサポートしています。プロジェクトIDは`GOOGLE_CLOUD_PROJECT`にもフォールバックします。選択したGCPプロジェクトではVertex AI APIが有効で、対象Claudeモデルへのアクセス権が必要です。

同じ設定は既存の`llm`設定にも保存できます:

```bash
ocr config set llm.use_anthropic_vertex true
ocr config set llm.vertex_project_id your-gcp-project
ocr config set llm.vertex_region global
ocr config set llm.model claude-sonnet-4-6
```

> **CC-Switchユーザー向けの注意**: [CC-Switch](https://github.com/farion1231/cc-switch)を[ルーティングサービス](https://www.ccswitch.io/en/docs?section=proxy&item=service)有効で使用している場合、追加設定なしで`llm.url`をCC-Switchのプロキシアドレスに向けることができます:
> - **Claude**プロバイダーの場合: `llm.url`を`http://127.0.0.1:15721`に設定
> - **Codex**プロバイダーの場合: `llm.url`を`http://127.0.0.1:15721/v1`に設定
Expand Down Expand Up @@ -462,6 +487,9 @@ OCRは4層の優先度チェーンを使ってレビュールールを解決し
| `llm.auth_header` | string | Anthropicのみ:`x-api-key` \| `authorization` |
| `llm.model` | string | `claude-opus-4-6` |
| `llm.use_anthropic` | boolean | `true` \| `false` |
| `llm.use_anthropic_vertex` | boolean | Google Vertex AIでClaudeを使用 |
| `llm.vertex_project_id` | string | Google CloudプロジェクトID |
| `llm.vertex_region` | string | Vertex AIリージョン |
| `language` | string | 任意の言語名、例:`English`、`Chinese`(デフォルト:`English`) |
| `telemetry.enabled` | boolean | `true` \| `false` |
| `telemetry.exporter` | string | `console` \| `otlp` |
Expand All @@ -479,6 +507,9 @@ OCRは4層の優先度チェーンを使ってレビュールールを解決し
| `OCR_LLM_AUTH_HEADER` | Anthropic認証ヘッダー(`x-api-key`または`authorization`) |
| `OCR_LLM_MODEL` | モデル名 |
| `OCR_USE_ANTHROPIC` | `true` = Anthropic、`false` = OpenAI |
| `OCR_USE_VERTEX` | Vertex AIモードを有効化 |
| `OCR_VERTEX_PROJECT_ID` | Google CloudプロジェクトID。`ANTHROPIC_VERTEX_PROJECT_ID`と`GOOGLE_CLOUD_PROJECT`もサポート |
| `OCR_VERTEX_REGION` | Vertex AIリージョン。`CLOUD_ML_REGION`もサポート |


## テレメトリー
Expand Down
31 changes: 31 additions & 0 deletions README.ko-KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ export OCR_USE_ANTHROPIC=true

Claude Code 환경 변수(`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_MODEL`)와도 호환되며, `~/.zshrc` / `~/.bashrc`의 export도 파싱합니다.

### Google Vertex AI에서 Claude 사용

OCR은 Google Application Default Credentials(ADC)를 사용해 Vertex AI의 Claude를 호출할 수 있습니다. Anthropic API key나 custom LLM URL은 필요하지 않습니다.

```bash
export OCR_USE_VERTEX=true
export OCR_LLM_MODEL=claude-sonnet-4-6
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global

gcloud auth application-default login
ocr llm test
```

OCR 전용 alias인 `OCR_VERTEX_PROJECT_ID`와 `OCR_VERTEX_REGION`도 지원합니다. project ID는 `GOOGLE_CLOUD_PROJECT`로도 fallback됩니다. 선택한 GCP project는 Vertex AI API가 활성화되어 있어야 하며 대상 Claude model에 접근할 수 있어야 합니다.

같은 설정은 기존 `llm` 설정에도 저장할 수 있습니다.

```bash
ocr config set llm.use_anthropic_vertex true
ocr config set llm.vertex_project_id your-gcp-project
ocr config set llm.vertex_region global
ocr config set llm.model claude-sonnet-4-6
```

> **CC-Switch 사용자 참고**: [CC-Switch](https://github.com/farion1231/cc-switch)를 [routing service](https://www.ccswitch.io/en/docs?section=proxy&item=service)와 함께 사용한다면, 추가 설정 없이 `llm.url`을 CC-Switch proxy 주소로 지정할 수 있습니다.
> - **Claude** provider: `llm.url`을 `http://127.0.0.1:15721`로 설정
> - **Codex** provider: `llm.url`을 `http://127.0.0.1:15721/v1`로 설정
Expand Down Expand Up @@ -420,6 +445,9 @@ Config file: `~/.opencodereview/config.json`
| `llm.auth_header` | string | Anthropic only: `x-api-key` \| `authorization` |
| `llm.model` | string | `claude-opus-4-6` |
| `llm.use_anthropic` | boolean | `true` \| `false` |
| `llm.use_anthropic_vertex` | boolean | Google Vertex AI에서 Claude 사용 |
| `llm.vertex_project_id` | string | Google Cloud project ID |
| `llm.vertex_region` | string | Vertex AI region |
| `language` | string | 임의의 언어 이름, 예: `English`, `Chinese` (기본값: `English`) |
| `telemetry.enabled` | boolean | `true` \| `false` |
| `telemetry.exporter` | string | `console` \| `otlp` |
Expand All @@ -437,6 +465,9 @@ Config file: `~/.opencodereview/config.json`
| `OCR_LLM_AUTH_HEADER` | Anthropic auth header (`x-api-key` 또는 `authorization`) |
| `OCR_LLM_MODEL` | Model name |
| `OCR_USE_ANTHROPIC` | `true` = Anthropic, `false` = OpenAI |
| `OCR_USE_VERTEX` | Vertex AI 모드 활성화 |
| `OCR_VERTEX_PROJECT_ID` | Google Cloud project ID. `ANTHROPIC_VERTEX_PROJECT_ID`와 `GOOGLE_CLOUD_PROJECT`도 지원 |
| `OCR_VERTEX_REGION` | Vertex AI region. `CLOUD_ML_REGION`도 지원 |

## Telemetry

Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ export OCR_USE_ANTHROPIC=true

It is also compatible with Claude Code environment variables (`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_MODEL`) and parses `~/.zshrc` / `~/.bashrc` for those exports.

### Claude on Google Vertex AI

OCR can use Claude through Vertex AI with Google Application Default Credentials (ADC). No Anthropic API key or custom LLM URL is required:

```bash
export OCR_USE_VERTEX=true
export OCR_LLM_MODEL=claude-sonnet-4-6
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global

gcloud auth application-default login
ocr llm test
```

`OCR_VERTEX_PROJECT_ID` and `OCR_VERTEX_REGION` are supported as OCR-specific aliases. `GOOGLE_CLOUD_PROJECT` is also accepted as a project ID fallback. The selected GCP project must have the Vertex AI API enabled and access to the requested Claude model.

The same setup can be stored in the legacy `llm` configuration:

```bash
ocr config set llm.use_anthropic_vertex true
ocr config set llm.vertex_project_id your-gcp-project
ocr config set llm.vertex_region global
ocr config set llm.model claude-sonnet-4-6
```

> **Note for CC-Switch Users**: If you are using [CC-Switch](https://github.com/farion1231/cc-switch) with [routing service](https://www.ccswitch.io/en/docs?section=proxy&item=service) enabled, you can point `llm.url` to the CC-Switch proxy address without additional configuration:
> - For **Claude** provider: set `llm.url` to `http://127.0.0.1:15721`
> - For **Codex** provider: set `llm.url` to `http://127.0.0.1:15721/v1`
Expand Down Expand Up @@ -464,6 +489,9 @@ Config file: `~/.opencodereview/config.json`
| `llm.auth_header` | string | Anthropic only: `x-api-key` \| `authorization` |
| `llm.model` | string | `claude-opus-4-6` |
| `llm.use_anthropic` | boolean | `true` \| `false` |
| `llm.use_anthropic_vertex` | boolean | Use Claude through Google Vertex AI |
| `llm.vertex_project_id` | string | Google Cloud project ID |
| `llm.vertex_region` | string | Vertex AI region |
| `language` | string | Any language name, e.g. `English`, `Chinese` (default: `English`) |
| `telemetry.enabled` | boolean | `true` \| `false` |
| `telemetry.exporter` | string | `console` \| `otlp` |
Expand All @@ -481,6 +509,9 @@ Environment variables take precedence over the config file.
| `OCR_LLM_AUTH_HEADER` | Anthropic auth header (`x-api-key` or `authorization`) |
| `OCR_LLM_MODEL` | Model name |
| `OCR_USE_ANTHROPIC` | `true` = Anthropic, `false` = OpenAI |
| `OCR_USE_VERTEX` | Enable Vertex AI mode |
| `OCR_VERTEX_PROJECT_ID` | Google Cloud project ID; aliases `ANTHROPIC_VERTEX_PROJECT_ID` and `GOOGLE_CLOUD_PROJECT` are supported |
| `OCR_VERTEX_REGION` | Vertex AI region; `CLOUD_ML_REGION` is also supported |


## Telemetry
Expand Down
31 changes: 31 additions & 0 deletions README.ru-RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ export OCR_USE_ANTHROPIC=true

Инструмент также совместим с переменными окружения Claude Code (`ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `ANTHROPIC_MODEL`) и разбирает `~/.zshrc` / `~/.bashrc` в поисках соответствующих export'ов.

### Claude через Google Vertex AI

OCR может вызывать Claude через Vertex AI с помощью Google Application Default Credentials (ADC). Ключ Anthropic API и пользовательский LLM URL не требуются:

```bash
export OCR_USE_VERTEX=true
export OCR_LLM_MODEL=claude-sonnet-4-6
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global

gcloud auth application-default login
ocr llm test
```

Также поддерживаются OCR-алиасы `OCR_VERTEX_PROJECT_ID` и `OCR_VERTEX_REGION`. Для project ID также используется fallback на `GOOGLE_CLOUD_PROJECT`. В выбранном GCP-проекте должен быть включён Vertex AI API и доступ к нужной модели Claude.

Эту же настройку можно сохранить в существующей секции `llm`:

```bash
ocr config set llm.use_anthropic_vertex true
ocr config set llm.vertex_project_id your-gcp-project
ocr config set llm.vertex_region global
ocr config set llm.model claude-sonnet-4-6
```

> **Примечание для пользователей CC-Switch**: если вы используете [CC-Switch](https://github.com/farion1231/cc-switch) с включённым [routing service](https://www.ccswitch.io/en/docs?section=proxy&item=service), можно указать в `llm.url` адрес прокси CC-Switch без дополнительной настройки:
> - для провайдера **Claude**: установите `llm.url` в `http://127.0.0.1:15721`
> - для провайдера **Codex**: установите `llm.url` в `http://127.0.0.1:15721/v1`
Expand Down Expand Up @@ -464,6 +489,9 @@ OCR разрешает правила ревью по цепочке приор
| `llm.auth_header` | string | Только для Anthropic: `x-api-key` \| `authorization` |
| `llm.model` | string | `claude-opus-4-6` |
| `llm.use_anthropic` | boolean | `true` \| `false` |
| `llm.use_anthropic_vertex` | boolean | Использовать Claude через Google Vertex AI |
| `llm.vertex_project_id` | string | ID проекта Google Cloud |
| `llm.vertex_region` | string | Регион Vertex AI |
| `language` | string | Любое название языка, например `English`, `Chinese` (по умолчанию: `English`) |
| `telemetry.enabled` | boolean | `true` \| `false` |
| `telemetry.exporter` | string | `console` \| `otlp` |
Expand All @@ -481,6 +509,9 @@ OCR разрешает правила ревью по цепочке приор
| `OCR_LLM_AUTH_HEADER` | Заголовок авторизации Anthropic (`x-api-key` или `authorization`) |
| `OCR_LLM_MODEL` | Имя модели |
| `OCR_USE_ANTHROPIC` | `true` = Anthropic, `false` = OpenAI |
| `OCR_USE_VERTEX` | Включить режим Vertex AI |
| `OCR_VERTEX_PROJECT_ID` | ID проекта Google Cloud; также поддерживаются `ANTHROPIC_VERTEX_PROJECT_ID` и `GOOGLE_CLOUD_PROJECT` |
| `OCR_VERTEX_REGION` | Регион Vertex AI; также поддерживается `CLOUD_ML_REGION` |


## Телеметрия
Expand Down
31 changes: 31 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ export OCR_USE_ANTHROPIC=true

同时兼容了 Claude Code 环境变量(`ANTHROPIC_BASE_URL`、`ANTHROPIC_AUTH_TOKEN`、`ANTHROPIC_MODEL`),并解析 `~/.zshrc` / `~/.bashrc` 中的相关导出。

### 通过 Google Vertex AI 使用 Claude

OCR 可以通过 Google 应用默认凭据(ADC)调用 Vertex AI 上的 Claude,不需要 Anthropic API Key 或自定义 LLM URL:

```bash
export OCR_USE_VERTEX=true
export OCR_LLM_MODEL=claude-sonnet-4-6
export ANTHROPIC_VERTEX_PROJECT_ID=your-gcp-project
export CLOUD_ML_REGION=global

gcloud auth application-default login
ocr llm test
```

也可以使用 OCR 专用别名 `OCR_VERTEX_PROJECT_ID` 和 `OCR_VERTEX_REGION`。项目 ID 还会回退读取 `GOOGLE_CLOUD_PROJECT`。所选 GCP 项目必须启用 Vertex AI API,并具有目标 Claude 模型的访问权限。

同样可以写入已有的 `llm` 配置:

```bash
ocr config set llm.use_anthropic_vertex true
ocr config set llm.vertex_project_id your-gcp-project
ocr config set llm.vertex_region global
ocr config set llm.model claude-sonnet-4-6
```

> **CC-Switch 用户特别提醒**:如果你使用 [CC-Switch](https://github.com/farion1231/cc-switch) 并开启了[路由服务](https://www.ccswitch.io/zh/docs?section=proxy&item=service),可以将 `llm.url` 配置成 CC-Switch 启动的代理地址,无需额外配置:
> - 如果路由的是 **Claude** 供应商:设置 `llm.url` 为 `http://127.0.0.1:15721`
> - 如果路由的是 **Codex** 供应商:设置 `llm.url` 为 `http://127.0.0.1:15721/v1`
Expand Down Expand Up @@ -452,6 +477,9 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
| `llm.auth_header` | string | 仅 Anthropic:`x-api-key` \| `authorization` |
| `llm.model` | string | `claude-opus-4-6` |
| `llm.use_anthropic` | boolean | `true` \| `false` |
| `llm.use_anthropic_vertex` | boolean | 通过 Google Vertex AI 使用 Claude |
| `llm.vertex_project_id` | string | Google Cloud 项目 ID |
| `llm.vertex_region` | string | Vertex AI 区域 |
| `language` | string | 任意语言名称,例如 `English`、`Chinese`(默认:`English`) |
| `telemetry.enabled` | boolean | `true` \| `false` |
| `telemetry.exporter` | string | `console` \| `otlp` |
Expand All @@ -469,6 +497,9 @@ OCR 通过四层优先级链解析评审规则。每层采用首次匹配原则
| `OCR_LLM_AUTH_HEADER` | Anthropic 认证头(`x-api-key` 或 `authorization`) |
| `OCR_LLM_MODEL` | 模型名称 |
| `OCR_USE_ANTHROPIC` | `true` = Anthropic,`false` = OpenAI |
| `OCR_USE_VERTEX` | 启用 Vertex AI 模式 |
| `OCR_VERTEX_PROJECT_ID` | Google Cloud 项目 ID;也支持 `ANTHROPIC_VERTEX_PROJECT_ID` 和 `GOOGLE_CLOUD_PROJECT` |
| `OCR_VERTEX_REGION` | Vertex AI 区域;也支持 `CLOUD_ML_REGION` |


## 遥测
Expand Down
27 changes: 20 additions & 7 deletions cmd/opencodereview/config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ type Config struct {
}

type LlmConfig struct {
URL string `json:"url,omitempty"`
AuthToken string `json:"auth_token,omitempty"`
AuthHeader string `json:"auth_header,omitempty"`
Model string `json:"model,omitempty"`
UseAnthropic *bool `json:"use_anthropic,omitempty"` // nil = default true; false = OpenAI protocol
ExtraBody map[string]any `json:"extra_body,omitempty"`
URL string `json:"url,omitempty"`
AuthToken string `json:"auth_token,omitempty"`
AuthHeader string `json:"auth_header,omitempty"`
Model string `json:"model,omitempty"`
UseAnthropic *bool `json:"use_anthropic,omitempty"` // nil = default true; false = OpenAI protocol
UseAnthropicVertex bool `json:"use_anthropic_vertex,omitempty"`
VertexProjectID string `json:"vertex_project_id,omitempty"`
VertexRegion string `json:"vertex_region,omitempty"`
ExtraBody map[string]any `json:"extra_body,omitempty"`
}

// TelemetryConfig holds telemetry-specific settings.
Expand Down Expand Up @@ -218,6 +221,16 @@ func setConfigValue(cfg *Config, key, value string) error {
return fmt.Errorf("invalid boolean for llm.use_anthropic: %w", err)
}
cfg.Llm.UseAnthropic = &b
case "llm.use_anthropic_vertex", "llm.UseAnthropicVertex":
b, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("invalid boolean for llm.use_anthropic_vertex: %w", err)
}
cfg.Llm.UseAnthropicVertex = b
case "llm.vertex_project_id", "llm.VertexProjectID":
cfg.Llm.VertexProjectID = value
case "llm.vertex_region", "llm.VertexRegion":
cfg.Llm.VertexRegion = value
case "language", "Language":
cfg.Language = value
case "telemetry.enabled", "telemetry.Enabled":
Expand Down Expand Up @@ -247,7 +260,7 @@ func setConfigValue(cfg *Config, key, value string) error {
}
cfg.Llm.ExtraBody = m
default:
return fmt.Errorf("unknown config key: %s\nSupported keys: provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, llm.url, llm.auth_token, llm.auth_header, llm.model, llm.use_anthropic, llm.extra_body, language, telemetry.enabled, telemetry.exporter, telemetry.otlp_endpoint, telemetry.content_logging\nProvider fields: api_key, url, protocol, model, models, auth_header, extra_body", key)
return fmt.Errorf("unknown config key: %s\nSupported keys: provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, llm.url, llm.auth_token, llm.auth_header, llm.model, llm.use_anthropic, llm.use_anthropic_vertex, llm.vertex_project_id, llm.vertex_region, llm.extra_body, language, telemetry.enabled, telemetry.exporter, telemetry.otlp_endpoint, telemetry.content_logging\nProvider fields: api_key, url, protocol, model, models, auth_header, extra_body", key)
}
return nil
}
Expand Down
18 changes: 18 additions & 0 deletions cmd/opencodereview/config_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ func TestSetConfigValueProviderEntryExtraBody(t *testing.T) {
}
}

func TestSetConfigValueLegacyVertexFields(t *testing.T) {
cfg := &Config{}

if err := setConfigValue(cfg, "llm.use_anthropic_vertex", "true"); err != nil {
t.Fatalf("set use_anthropic_vertex: %v", err)
}
if err := setConfigValue(cfg, "llm.vertex_project_id", "test-project"); err != nil {
t.Fatalf("set vertex_project_id: %v", err)
}
if err := setConfigValue(cfg, "llm.vertex_region", "global"); err != nil {
t.Fatalf("set vertex_region: %v", err)
}

if !cfg.Llm.UseAnthropicVertex || cfg.Llm.VertexProjectID != "test-project" || cfg.Llm.VertexRegion != "global" {
t.Errorf("Llm Vertex config = %#v", cfg.Llm)
}
}

func TestSetConfigValueModelWithCustomProvider(t *testing.T) {
cfg := &Config{
Provider: "my-gateway",
Expand Down
2 changes: 1 addition & 1 deletion cmd/opencodereview/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,6 @@ Examples:
ocr config set language English
ocr config set telemetry.enabled true

Supported keys: provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, llm.url, llm.auth_token, llm.auth_header, llm.model, llm.use_anthropic, llm.extra_body, language, telemetry.enabled, telemetry.exporter, telemetry.otlp_endpoint, telemetry.content_logging
Supported keys: provider, model, providers.<name>.<field>, custom_providers.<name>.<field>, llm.url, llm.auth_token, llm.auth_header, llm.model, llm.use_anthropic, llm.use_anthropic_vertex, llm.vertex_project_id, llm.vertex_region, llm.extra_body, language, telemetry.enabled, telemetry.exporter, telemetry.otlp_endpoint, telemetry.content_logging
Provider fields: api_key, url, protocol, model, models, auth_header, extra_body`)
}
5 changes: 4 additions & 1 deletion cmd/opencodereview/llm_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func runLLMTest() error {
timeout = time.Duration(task.Timeout) * time.Second
}

llmClient := llm.NewLLMClient(ep)
llmClient, err := llm.NewLLMClient(context.Background(), ep)
if err != nil {
return fmt.Errorf("create LLM client: %w", err)
}

messages := make([]llm.Message, 0, len(task.Messages))
for _, m := range task.Messages {
Expand Down
5 changes: 4 additions & 1 deletion cmd/opencodereview/review_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func runReview(args []string) error {
return fmt.Errorf("resolve LLM endpoint: %w", err)
}

llmClient := llm.NewLLMClient(ep)
llmClient, err := llm.NewLLMClient(context.Background(), ep)
if err != nil {
return fmt.Errorf("create LLM client: %w", err)
}
model := ep.Model

gitRunner := gitcmd.New(opts.maxGitProcs)
Expand Down
Loading