更新至 v0.1.1_20251209 版本

This commit is contained in:
2025-12-09 22:38:05 +08:00
parent 2c7cbac954
commit 4773a9239c
6 changed files with 190 additions and 23 deletions

View File

@@ -33,7 +33,14 @@ ${data.requirement}
export const generateSql = async (requestData: SqlGenerationRequest): Promise<string> => {
try {
const ai = new GoogleGenAI({ apiKey: process.env.API_KEY });
// Prioritize the user-provided key, fallback to the environment variable
const apiKey = requestData.apiKey || process.env.API_KEY;
if (!apiKey) {
throw new Error("未配置 API Key。请点击右上角设置按钮输入您的 Google Gemini API Key或联系管理员配置环境变量。");
}
const ai = new GoogleGenAI({ apiKey: apiKey });
// Using gemini-2.5-flash for speed and good reasoning capabilities on coding tasks
const response = await ai.models.generateContent({
@@ -51,8 +58,9 @@ export const generateSql = async (requestData: SqlGenerationRequest): Promise<st
sql = sql.replace(/^```sql\n/, '').replace(/^```\n/, '').replace(/\n```$/, '');
return sql.trim();
} catch (error) {
} catch (error: any) {
console.error("Error generating SQL:", error);
throw new Error("生成 SQL 失败,请检查 API Key 或网络连接。");
// Pass through the specific error message if possible
throw new Error(error.message || "生成 SQL 失败,请检查 API Key 或网络连接。");
}
};
};