@@ -21,9 +21,9 @@ def generate_sql(question: str) -> Dict[str, Any]:
2121 schema = load_database_schema ()
2222 formatted_schema = format_schema_for_prompt (schema )
2323
24- system_prompt = f"""
24+ # We move the "Expert" rules to the system_instruction parameter
25+ system_instruction = f"""
2526You are an expert SQL assistant.
26-
2727You are given a PostgreSQL database schema.
2828Your task is to generate a SINGLE, READ-ONLY SQL query
2929that answers the user's question.
@@ -46,18 +46,12 @@ def generate_sql(question: str) -> Dict[str, Any]:
4646}}
4747"""
4848
49+ # Corrected method call for the google-genai SDK
4950 response = client .models .generate_content (
5051 model = settings .GEMINI_MODEL ,
51- contents = [
52- types .Content (
53- role = "user" ,
54- parts = [
55- types .Part (text = system_prompt ),
56- types .Part (text = f"\n USER QUESTION:\n { question } " )
57- ]
58- )
59- ],
60- generation_config = types .GenerationConfig (
52+ contents = f"USER QUESTION: { question } " ,
53+ config = types .GenerateContentConfig (
54+ system_instruction = system_instruction ,
6155 temperature = 0.1 ,
6256 response_mime_type = "application/json"
6357 )
@@ -68,9 +62,9 @@ def generate_sql(question: str) -> Dict[str, Any]:
6862 try :
6963 data = json .loads (raw_text )
7064 except json .JSONDecodeError as exc :
71- raise ValueError ("Gemini returned invalid JSON" ) from exc
65+ raise ValueError (f "Gemini returned invalid JSON: { raw_text } " ) from exc
7266
7367 if "sql" not in data or "explanation" not in data :
7468 raise ValueError ("Gemini response missing required fields" )
7569
76- return data
70+ return data
0 commit comments