更新至 v0.1.1_20251209 版本
This commit is contained in:
@@ -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 或网络连接。");
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user