fix: default to Gemini API if GEMINI_API_KEY is set and when GOOGLE_GENAI_USE_VERTEXAI is set to True (#566)
This commit is contained in:
parent
b3f52e215a
commit
3511e84dc3
|
@ -132,6 +132,7 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||||
|
|
||||||
const userAgent = await createUserAgent();
|
const userAgent = await createUserAgent();
|
||||||
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
const apiKeyForServer = geminiApiKey || googleApiKey || '';
|
||||||
|
const useVertexAI = hasGeminiApiKey ? false : undefined;
|
||||||
|
|
||||||
return createServerConfig(
|
return createServerConfig(
|
||||||
apiKeyForServer,
|
apiKeyForServer,
|
||||||
|
@ -149,6 +150,8 @@ export async function loadCliConfig(settings: Settings): Promise<Config> {
|
||||||
userAgent,
|
userAgent,
|
||||||
memoryContent,
|
memoryContent,
|
||||||
fileCount,
|
fileCount,
|
||||||
|
undefined, // alwaysSkipModificationConfirmation - not set by CLI args directly
|
||||||
|
useVertexAI,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ export class Config {
|
||||||
private userMemory: string = '', // Made mutable for refresh
|
private userMemory: string = '', // Made mutable for refresh
|
||||||
private geminiMdFileCount: number = 0,
|
private geminiMdFileCount: number = 0,
|
||||||
private alwaysSkipModificationConfirmation: boolean = false,
|
private alwaysSkipModificationConfirmation: boolean = false,
|
||||||
|
private readonly vertexai?: boolean,
|
||||||
) {
|
) {
|
||||||
// toolRegistry still needs initialization based on the instance
|
// toolRegistry still needs initialization based on the instance
|
||||||
this.toolRegistry = createToolRegistry(this);
|
this.toolRegistry = createToolRegistry(this);
|
||||||
|
@ -139,6 +140,10 @@ export class Config {
|
||||||
setAlwaysSkipModificationConfirmation(skip: boolean): void {
|
setAlwaysSkipModificationConfirmation(skip: boolean): void {
|
||||||
this.alwaysSkipModificationConfirmation = skip;
|
this.alwaysSkipModificationConfirmation = skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getVertexAI(): boolean | undefined {
|
||||||
|
return this.vertexai;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findEnvFile(startDir: string): string | null {
|
function findEnvFile(startDir: string): string | null {
|
||||||
|
@ -186,6 +191,7 @@ export function createServerConfig(
|
||||||
userMemory?: string,
|
userMemory?: string,
|
||||||
geminiMdFileCount?: number,
|
geminiMdFileCount?: number,
|
||||||
alwaysSkipModificationConfirmation?: boolean,
|
alwaysSkipModificationConfirmation?: boolean,
|
||||||
|
vertexai?: boolean,
|
||||||
): Config {
|
): Config {
|
||||||
return new Config(
|
return new Config(
|
||||||
apiKey,
|
apiKey,
|
||||||
|
@ -204,6 +210,7 @@ export function createServerConfig(
|
||||||
userMemory ?? '',
|
userMemory ?? '',
|
||||||
geminiMdFileCount ?? 0,
|
geminiMdFileCount ?? 0,
|
||||||
alwaysSkipModificationConfirmation ?? false,
|
alwaysSkipModificationConfirmation ?? false,
|
||||||
|
vertexai,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,11 @@ export class GeminiClient {
|
||||||
constructor(private config: Config) {
|
constructor(private config: Config) {
|
||||||
const userAgent = config.getUserAgent();
|
const userAgent = config.getUserAgent();
|
||||||
const apiKeyFromConfig = config.getApiKey();
|
const apiKeyFromConfig = config.getApiKey();
|
||||||
|
const vertexaiFlag = config.getVertexAI();
|
||||||
|
|
||||||
this.client = new GoogleGenAI({
|
this.client = new GoogleGenAI({
|
||||||
apiKey: apiKeyFromConfig === '' ? undefined : apiKeyFromConfig,
|
apiKey: apiKeyFromConfig === '' ? undefined : apiKeyFromConfig,
|
||||||
|
vertexai: vertexaiFlag,
|
||||||
httpOptions: {
|
httpOptions: {
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': userAgent,
|
'User-Agent': userAgent,
|
||||||
|
|
Loading…
Reference in New Issue