mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
* try a really long context window to maximize caching
* update examples
* attempt to update packages and useChat
* update endpoints
* update zod
* zod
* update to v5
* message update
* Revert "zod"
This reverts commit ec39bac6b6.
* revert zod
* zod i
* fix complete endpoints
* remove async
* change to content
* type cleanup
* Revert the package bumps to rebuild them.
* Bump zod to 2.25.76 in all packages.
* Bump openai in all packages.
* Bump ai and ai-related packages.
* Remove unneeded files.
* Fix the rest of the migration stuff.
* Prettier fixes.
* testing new gptoss models
* sonnet as pro
* back to 3.7
* revert test
* add policy list tool
* fix
* refactor
* ai sdk 5 fixes
* refactor complete endpoint
* edge function prompt
* remove example
* use limited model for completions
* remove duplicate
* Update bedrock.ts
Co-authored-by: divit <27228526+delgado3d@users.noreply.github.com>
* add default check
* only add prefix if more then one region
* temp use api
* refactor to use openai api
* test
* remove unused import
* Prettier lint
* Fix test
* revert back to bedrock
* Tiny style fix for spacing of code blocks from edit message button
* try generate text normally
* prompt adjust
* add list style to prompt
* prompt adjust
* prompt adjust emphasise display query
* update prompts
* prompt adjust
* remove package
* prompt adjust
---------
Co-authored-by: Jordi Enric <jordi.err@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: divit <27228526+delgado3d@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { openai } from '@ai-sdk/openai'
|
|
import { LanguageModel } from 'ai'
|
|
import { checkAwsCredentials, createRoutedBedrock } from './bedrock'
|
|
|
|
const BEDROCK_PRO_MODEL = 'anthropic.claude-3-7-sonnet-20250219-v1:0'
|
|
const BEDROCK_NORMAL_MODEL = 'openai.gpt-oss-120b-1:0'
|
|
const OPENAI_MODEL = 'gpt-4.1-2025-04-14'
|
|
|
|
export type ModelSuccess = {
|
|
model: LanguageModel
|
|
supportsCachePoint: boolean
|
|
error?: never
|
|
}
|
|
|
|
export type ModelError = {
|
|
model?: never
|
|
supportsCachePoint?: never
|
|
error: Error
|
|
}
|
|
|
|
export type ModelResponse = ModelSuccess | ModelError
|
|
|
|
export const ModelErrorMessage =
|
|
'No valid AI model available. Please set up a local AWS profile to use Bedrock, or pass an OPENAI_API_KEY to use OpenAI.'
|
|
|
|
/**
|
|
* Retrieves the appropriate AI model based on available credentials.
|
|
*
|
|
* An optional routing key can be provided to distribute requests across
|
|
* different Bedrock regions.
|
|
*/
|
|
export async function getModel(routingKey?: string, isLimited?: boolean): Promise<ModelResponse> {
|
|
// Default behaviour here is to be throttled (e.g if this env var is not available, isThrottled should be true, unless specified 'false')
|
|
const isThrottled = process.env.IS_THROTTLED !== 'false'
|
|
|
|
const hasAwsCredentials = await checkAwsCredentials()
|
|
|
|
const hasAwsBedrockRoleArn = !!process.env.AWS_BEDROCK_ROLE_ARN
|
|
const hasOpenAIKey = !!process.env.OPENAI_API_KEY
|
|
|
|
if (hasAwsBedrockRoleArn && hasAwsCredentials) {
|
|
const bedrockModel = isThrottled || isLimited ? BEDROCK_NORMAL_MODEL : BEDROCK_PRO_MODEL
|
|
const bedrock = createRoutedBedrock(routingKey)
|
|
const { model, supportsCachePoint } = await bedrock(bedrockModel)
|
|
|
|
return { model, supportsCachePoint }
|
|
}
|
|
|
|
// [Joshen] Only for local/self-hosted, hosted should always only use bedrock
|
|
if (hasOpenAIKey) {
|
|
return { model: openai(OPENAI_MODEL), supportsCachePoint: false }
|
|
}
|
|
|
|
return { error: new Error(ModelErrorMessage) }
|
|
}
|