Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ To ensure a positive and inclusive environment, please read our [code of conduct
You will need to install and configure the following dependencies on your machine to build [Supabase](https://supabase.com):

- [Git](https://git-scm.com/)
- [Node.js v20.x (LTS)](https://nodejs.org)
- [Node.js v22.x or higher](https://nodejs.org)
- [pnpm](https://pnpm.io/) version 9.x.x or higher
- [make](https://www.gnu.org/software/make/) or the equivalent to `build-essentials` for your OS
- [Docker](https://docs.docker.com/get-docker/) (to run studio locally)
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build:graphql-types:watch": "pnpm graphql-codegen --config scripts/codegen.ts --watch"
},
"dependencies": {
"@ai-sdk/amazon-bedrock": "^2.2.9",
"@ai-sdk/amazon-bedrock": "^2.2.10",
"@ai-sdk/openai": "^1.3.22",
"@ai-sdk/react": "^1.2.12",
"@aws-sdk/credential-providers": "^3.804.0",
Expand Down
30 changes: 24 additions & 6 deletions apps/studio/pages/api/ai/sql/generate-v4.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pgMeta from '@supabase/pg-meta'
import { streamText, tool, ToolSet } from 'ai'
import { convertToCoreMessages, CoreMessage, streamText, tool, ToolSet } from 'ai'
import { source } from 'common-tags'
import { NextApiRequest, NextApiResponse } from 'next'
import { z } from 'zod'
Expand Down Expand Up @@ -435,8 +435,8 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
...filteredLocalTools,
}

// Important: do not use dynamic content in the system prompt or Bedrock will not cache it
const system = source`
The current project is ${projectRef}.
You are a Supabase Postgres expert. Your goal is to generate SQL or Edge Function code based on user requests, using specific tools for rendering.

# Response Style:
Expand Down Expand Up @@ -581,16 +581,34 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse) {
\`\`\`

# General Instructions:

- **Available Schemas**: ${schemasString}
- **Understand Context**: Attempt to use \`list_tables\`, \`list_extensions\` first. If they are not available or return a privacy/permission error, state this and proceed with caution, relying on the user's description and general knowledge.
`

// Note: these must be of type `CoreMessage` to prevent AI SDK from stripping `providerOptions`
// https://github.com/vercel/ai/blob/81ef2511311e8af34d75e37fc8204a82e775e8c3/packages/ai/core/prompt/standardize-prompt.ts#L83-L88
const coreMessages: CoreMessage[] = [
{
role: 'system',
content: system,
providerOptions: {
bedrock: {
// Always cache the system prompt (must not contain dynamic content)
cachePoint: { type: 'default' },
},
},
},
{
role: 'assistant',
// Add any dynamic context here
content: `The user's current project is ${projectRef}. Their available schemas are: ${schemasString}`,
},
...convertToCoreMessages(messages),
]

const result = streamText({
model,
maxSteps: 5,
system,
messages,
messages: coreMessages,
tools,
})

Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading