minor: Make GOOGLE_API_KEY optional

This commit is contained in:
2026-07-06 12:30:08 +05:30
parent 41f72b19e0
commit 0c3a2043b3
3 changed files with 9 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import { z } from "zod";
const LLMConfigSchema = z.object({
GOOGLE_API_KEY: z.string().min(1, "GOOGLE_API_KEY is required"),
GOOGLE_API_KEY: z.string().optional(),
});
export const llmConfig = LLMConfigSchema.parse(process.env);

View File

@@ -1,14 +1,19 @@
import { z } from "zod";
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
import { ILLMProvider, LLMRequest, LLMResponse } from "../llm.js";
import { llmConfig } from "../config.js";
export class GeminiProvider implements ILLMProvider {
providerName = "Gemini";
private model: ChatGoogleGenerativeAI;
constructor(apiKey: string) {
constructor(apiKey?: string) {
const key = apiKey || llmConfig.GOOGLE_API_KEY;
if (!key) {
throw new Error("GOOGLE_API_KEY is required to initialize GeminiProvider");
}
this.model = new ChatGoogleGenerativeAI({
apiKey,
apiKey: key,
model: "gemini-2.5-flash",
});
}