From a2e822d4ec84cd6917f3eaccd01d1cd148ed323c Mon Sep 17 00:00:00 2001 From: Saxon Fletcher Date: Wed, 19 Feb 2025 10:39:45 +1000 Subject: [PATCH] prompt updates --- .../PolicyTableRow/PolicyTableRowHeader.tsx | 2 +- apps/studio/pages/api/ai/sql/complete.ts | 13 ++++++++----- apps/studio/pages/api/ai/sql/tools.ts | 1 + apps/studio/pages/project/[ref]/auth/policies.tsx | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx index 77204da34d0..ccd2a5fd7ae 100644 --- a/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx +++ b/apps/studio/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRowHeader.tsx @@ -117,7 +117,7 @@ const PolicyTableRowHeader = ({ onClick={() => { setAiAssistantPanel({ open: true, - initialInput: `Create a new policy for the ${table.schema} schema on the ${table.name} table that ...`, + initialInput: `Create and name a new policy for the ${table.schema} schema on the ${table.name} table that ...`, }) }} tooltip={{ diff --git a/apps/studio/pages/api/ai/sql/complete.ts b/apps/studio/pages/api/ai/sql/complete.ts index 61127df22a4..50ef9b1910e 100644 --- a/apps/studio/pages/api/ai/sql/complete.ts +++ b/apps/studio/pages/api/ai/sql/complete.ts @@ -97,7 +97,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) # You write row level security policies. - Your purpose is to generate a policy with the constraints given by the user. + Your purpose is to generate a policy with the constraints given by the user using the getRlsKnowledge tool. - First, use getSchemaTables to retrieve more information about a schema or schemas that will contain policies, usually the public schema. - Then retrieve existing RLS policies and guidelines on how to write policies using the getRlsKnowledge tool . - Then write new policies or update existing policies based on the prompt @@ -127,10 +127,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) Instructions: 1. Only modify the selected text based on this prompt: ${prompt} - 2. Your response should be ONLY the modified selection text, nothing else. Remove selected text if needed. - 3. Do not wrap in code blocks or markdown - 4. You can respond with one word or multiple words - 5. Ensure the modified text flows naturally within the current line + 2. Get schema tables information using the getSchemaTables tool + 3. Get existing RLS policies and guidelines on how to write policies using the getRlsKnowledge tool + 4. Write new policies or update existing policies based on the prompt + 5. Your response should be ONLY the modified selection text, nothing else. Remove selected text if needed. + 6. Do not wrap in code blocks or markdown + 7. You can respond with one word or multiple words + 8. Ensure the modified text flows naturally within the current line 6. Avoid duplicating SQL keywords (SELECT, FROM, WHERE, etc) when considering the full statement 7. If there is no surrounding context (before or after), make sure your response is a complete valid SQL statement that can be run and resolves the prompt. diff --git a/apps/studio/pages/api/ai/sql/tools.ts b/apps/studio/pages/api/ai/sql/tools.ts index 85c23f8170a..4bea302964b 100644 --- a/apps/studio/pages/api/ai/sql/tools.ts +++ b/apps/studio/pages/api/ai/sql/tools.ts @@ -85,6 +85,7 @@ export const getTools = ({ { projectRef, connectionString, + schema: schemas[0] || '', }, undefined, headers diff --git a/apps/studio/pages/project/[ref]/auth/policies.tsx b/apps/studio/pages/project/[ref]/auth/policies.tsx index a18d08722d6..4d42fee486c 100644 --- a/apps/studio/pages/project/[ref]/auth/policies.tsx +++ b/apps/studio/pages/project/[ref]/auth/policies.tsx @@ -156,7 +156,7 @@ const AuthPoliciesPage: NextPageWithLayout = () => { if (isInlineEditorEnabled) { setEditorPanel({ open: true, - initialValue: `create policy "policy_name" + initialValue: `create policy "replace_with_policy_name" on ${schema}.${table} for select to authenticated @@ -165,7 +165,7 @@ const AuthPoliciesPage: NextPageWithLayout = () => { );`, label: `Create new RLS policy on "${table}"`, saveLabel: 'Create policy', - initialPrompt: `Create a new RLS policy for the "${table}" table in the ${schema} schema. The policy should...`, + initialPrompt: `Create and name a entirely new RLS policy for the "${table}" table in the ${schema} schema. The policy should...`, }) } else { setSelectedTable(table)