v4.3.19-4: Google(Gemini) LLM provider 추가
- LLMProvider.ts/factory.ts: 'google' ProviderID 추가, 기존 openai_compat 어댑터를 Gemini의 OpenAI 호환 엔드포인트로 재사용(새 어댑터 클래스 없음). api_key는 resolveEnvKey가 아닌 getConfig().resolveSecret()로 해석 — vault: 참조를 실제로 못 푸는 기존 openai/anthropic 케이스의 버그를 google 케이스에서는 피해감 - config.ts: llm.providers.google 기본값 추가(기본모델 gemini-3.6-flash), SECRET_FIELD_MAP에 api_key 자동 vault 이관 등록 - 설정 화면(index.html/settings-provider.js): LLM 제공자 드롭다운에 Google 옵션 + API키/모델 선택 UI, anthropic 패턴 그대로 재사용 - openai-compat-adapter.ts: 기본 max_tokens 512→4000 — 사고형 모델 (gemini-3.6-flash)이 내부 사고 토큰에 예산을 다 써서 빈 응답 반환하는 버그 실측 후 수정(llama_cpp/lm_studio/openai/google 전부 공유하는 값) - 5문항 벤치마크로 gemini-3.6-flash/3.5-flash-lite/3.1-flash-lite 비교, secondary 후보로 3.5-flash-lite 확정(정직함 동률 최상위+5배 빠름+저가) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f5ae095837
commit
5f83803ed4
6 files changed
+57
-6
No files matched your search
@@ -113,6 +113,11 @@ export const DEFAULT_CONFIG: SmallClawConfig = {
|
||||
openai_codex: {
|
||||
model: process.env.CODEX_MODEL ?? 'gpt-5.3-codex',
|
||||
},
|
||||
google: {
|
||||
endpoint: 'https://generativelanguage.googleapis.com/v1beta/openai',
|
||||
api_key: process.env.GOOGLE_API_KEY ? `env:GOOGLE_API_KEY` : '',
|
||||
model: process.env.GOOGLE_MODEL ?? 'gemini-3.6-flash',
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
models: {
|
||||
@@ -315,6 +320,7 @@ const SECRET_FIELD_MAP: Array<[string[], string]> = [
|
||||
[['search', 'google_api_key'], 'search.google_api_key'],
|
||||
[['search', 'brave_api_key'], 'search.brave_api_key'],
|
||||
[['llm', 'providers', 'openai', 'api_key'], 'llm.openai.api_key'],
|
||||
[['llm', 'providers', 'google', 'api_key'], 'llm.google.api_key'],
|
||||
[['llm', 'providers', 'lm_studio', 'api_key'], 'llm.lm_studio.api_key'],
|
||||
[['hooks', 'token'], 'hooks.token'],
|
||||
[['ppt', 'unsplash_key'], 'ppt.unsplash_key'],
|
||||
|
||||
@@ -105,4 +105,4 @@ export interface LLMProvider {
|
||||
readonly id: ProviderID;
|
||||
}
|
||||
|
||||
export type ProviderID = 'ollama' | 'llama_cpp' | 'lm_studio' | 'openai' | 'openai_codex' | 'anthropic';
|
||||
export type ProviderID = 'ollama' | 'llama_cpp' | 'lm_studio' | 'openai' | 'openai_codex' | 'anthropic' | 'google';
|
||||
@@ -143,6 +143,21 @@ function buildProvider(id: ProviderID, providers: any): LLMProvider {
|
||||
});
|
||||
}
|
||||
|
||||
case 'google': {
|
||||
// Gemini's OpenAI-compatible endpoint — same adapter as openai/lm_studio,
|
||||
// just a different base URL. resolveEnvKey only unwraps "env:" prefixes,
|
||||
// not "vault:" ones (see tools/web.ts's google_api_key for the working
|
||||
// vault pattern), so resolve through config's own secret resolver here.
|
||||
const cfg = providers.google || {};
|
||||
const apiKey = getConfig().resolveSecret(cfg.api_key);
|
||||
if (!apiKey) throw new Error('Google (Gemini) API key not configured. Add it in Settings -> Models.');
|
||||
return new OpenAICompatAdapter({
|
||||
endpoint: cfg.endpoint || 'https://generativelanguage.googleapis.com/v1beta/openai',
|
||||
apiKey,
|
||||
providerId: 'google',
|
||||
});
|
||||
}
|
||||
|
||||
case 'openai_codex': {
|
||||
const configDir = getConfigDir();
|
||||
return new OpenAICodexAdapter(configDir);
|
||||
|
||||
@@ -93,7 +93,11 @@ export class OpenAICompatAdapter implements LLMProvider {
|
||||
model,
|
||||
messages: finalMessages,
|
||||
temperature: options?.temperature ?? 0.25,
|
||||
max_tokens: options?.max_tokens ?? 512,
|
||||
// 512 was too low for reasoning models (Gemini 3.6 Flash burns budget on internal
|
||||
// "thinking"/drafting tokens before the visible answer — verified empirically: 512
|
||||
// produced truncated garbage like "Drafting the Response..." with no real content,
|
||||
// 4000 fixed it). Callers that need a tighter cap should still pass max_tokens explicitly.
|
||||
max_tokens: options?.max_tokens ?? 4000,
|
||||
stream: false,
|
||||
};
|
||||
if (Array.isArray(options?.tools) && options!.tools!.length) {
|
||||
@@ -122,7 +126,11 @@ export class OpenAICompatAdapter implements LLMProvider {
|
||||
model,
|
||||
messages,
|
||||
temperature: options?.temperature ?? 0.3,
|
||||
max_tokens: options?.max_tokens ?? 512,
|
||||
// 512 was too low for reasoning models (Gemini 3.6 Flash burns budget on internal
|
||||
// "thinking"/drafting tokens before the visible answer — verified empirically: 512
|
||||
// produced truncated garbage like "Drafting the Response..." with no real content,
|
||||
// 4000 fixed it). Callers that need a tighter cap should still pass max_tokens explicitly.
|
||||
max_tokens: options?.max_tokens ?? 4000,
|
||||
stream: false,
|
||||
};
|
||||
if (options?.format === 'json') {
|
||||
|
||||
@@ -1016,6 +1016,7 @@
|
||||
<option value="openai">OpenAI — API 키</option>
|
||||
<option value="openai_codex">OpenAI — GPT Plus / Codex (OAuth)</option>
|
||||
<option value="anthropic">Anthropic — Claude API 키</option>
|
||||
<option value="google">Google — Gemini API 키</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -1106,6 +1107,24 @@
|
||||
<div id="provider-status-msg-anthropic" style="font-size:11px;color:var(--muted);margin-top:6px"></div>
|
||||
</div>
|
||||
|
||||
<!-- Google (Gemini) -->
|
||||
<div id="prov-fields-google" style="display:none">
|
||||
<div class="right-section-title" style="margin-bottom:8px">Google Gemini API 키</div>
|
||||
<label style="display:block;font-size:12px;color:var(--muted);margin-bottom:6px">API 키</label>
|
||||
<input id="settings-google-key" type="password" placeholder="AIzaSy... 또는 AQ...." style="width:100%;border:1px solid var(--line);border-radius:10px;padding:8px;font-size:12px;font-family:'IBM Plex Mono',monospace" />
|
||||
<label style="display:block;font-size:12px;color:var(--muted);margin:10px 0 6px">모델</label>
|
||||
<select id="settings-google-model" class="settings-input" style="font-size:13px">
|
||||
<option value="gemini-3.6-flash">gemini-3.6-flash (권장)</option>
|
||||
<option value="gemini-3.5-flash-lite">gemini-3.5-flash-lite (경제적, $0.30/$2.50 per 1M)</option>
|
||||
<option value="gemini-3.1-flash-lite">gemini-3.1-flash-lite (최저가, $0.25/$1.50 per 1M)</option>
|
||||
</select>
|
||||
<div style="display:flex;gap:8px;margin-top:8px">
|
||||
<button class="btn btn-sm" onclick="testProviderConnection()" style="background:#fff;border:1px solid var(--line);color:var(--text)">연결 테스트</button>
|
||||
</div>
|
||||
<div id="provider-status-msg-google" style="font-size:11px;color:var(--muted);margin-top:6px"></div>
|
||||
<div style="font-size:11px;color:var(--muted);margin-top:12px;line-height:1.6">키는 <a href="https://aistudio.google.com/" target="_blank" rel="noopener">Google AI Studio</a>에서 발급받으세요.</div>
|
||||
</div>
|
||||
|
||||
<!-- OpenAI Codex OAuth -->
|
||||
<div id="prov-fields-openai_codex" style="display:none">
|
||||
<div class="right-section-title" style="margin-bottom:8px">OpenAI — GPT Plus / Codex</div>
|
||||
|
||||
@@ -291,7 +291,7 @@ function toggleCredVis(inputId, btn) {
|
||||
|
||||
// --- Provider-aware Model Settings ------------------------------------------
|
||||
|
||||
const PROVIDER_IDS = ['ollama', 'llama_cpp', 'lm_studio', 'openai', 'openai_codex', 'anthropic'];
|
||||
const PROVIDER_IDS = ['ollama', 'llama_cpp', 'lm_studio', 'openai', 'openai_codex', 'anthropic', 'google'];
|
||||
|
||||
function onProviderChange() {
|
||||
const provider = document.getElementById('settings-llm-provider').value;
|
||||
@@ -333,6 +333,8 @@ async function loadModelSettings() {
|
||||
v('settings-openai-key', pc.openai?.api_key);
|
||||
v('settings-anthropic-key', pc.anthropic?.api_key);
|
||||
if (pc.anthropic?.model) { const s = document.getElementById('settings-anthropic-model'); if (s) s.value = pc.anthropic.model; }
|
||||
v('settings-google-key', pc.google?.api_key);
|
||||
if (pc.google?.model) { const s = document.getElementById('settings-google-model'); if (s) s.value = pc.google.model; }
|
||||
|
||||
// Set primary model from saved config before refreshing the list
|
||||
// Fallback to data.models_primary (models.primary) when provider's model field is empty
|
||||
@@ -387,7 +389,7 @@ async function refreshProviderModels(forcedValue) {
|
||||
|
||||
async function testProviderConnection() {
|
||||
const provider = document.getElementById('settings-llm-provider').value;
|
||||
const statusIds = { ollama: 'provider-status-msg', llama_cpp: 'provider-status-msg-llamacpp', lm_studio: 'provider-status-msg-lmstudio', openai: 'provider-status-msg-openai', openai_codex: 'codex-oauth-status', anthropic: 'provider-status-msg-anthropic' };
|
||||
const statusIds = { ollama: 'provider-status-msg', llama_cpp: 'provider-status-msg-llamacpp', lm_studio: 'provider-status-msg-lmstudio', openai: 'provider-status-msg-openai', openai_codex: 'codex-oauth-status', anthropic: 'provider-status-msg-anthropic', google: 'provider-status-msg-google' };
|
||||
const msgId = statusIds[provider] || 'provider-status-msg';
|
||||
const msg = document.getElementById(msgId);
|
||||
if (msg) msg.textContent = '테스트 중…';
|
||||
@@ -453,6 +455,7 @@ function buildProviderPayload() {
|
||||
providers.openai = { api_key: document.getElementById('settings-openai-key')?.value || '', model: document.getElementById('settings-openai-model')?.value || 'gpt-4o' };
|
||||
providers.openai_codex = { model: document.getElementById('settings-codex-model')?.value || 'gpt-5.3-codex' };
|
||||
providers.anthropic = { api_key: document.getElementById('settings-anthropic-key')?.value || '', model: document.getElementById('settings-anthropic-model')?.value || 'claude-sonnet-4-6' };
|
||||
providers.google = { api_key: document.getElementById('settings-google-key')?.value || '', model: document.getElementById('settings-google-model')?.value || 'gemini-3.6-flash' };
|
||||
return { provider, providers };
|
||||
}
|
||||
|
||||
@@ -822,7 +825,7 @@ async function removeUser(username) {
|
||||
|
||||
const PROVIDER_LABELS = {
|
||||
ollama: 'Ollama', llama_cpp: 'llama.cpp', lm_studio: 'LM Studio',
|
||||
openai: 'OpenAI', openai_codex: 'ChatGPT'
|
||||
openai: 'OpenAI', openai_codex: 'ChatGPT', anthropic: 'Anthropic', google: 'Google'
|
||||
};
|
||||
async function checkStatus() {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user