@@ -7,11 +7,17 @@ const DATASET = 'bigcode/the-stack';
77const EMBEDDING_MODEL = 'Xenova/all-MiniLM-L6-v2' ;
88const HUGGING_FACE_API_URL = 'https://huggingface.co/api/datasets' ;
99
10- // Initialize Supabase client with the service role key for admin access
11- const supabase = createClient (
12- process . env . NEXT_PUBLIC_SUPABASE_URL ! ,
13- process . env . SUPABASE_SERVICE_ROLE_KEY !
14- ) ;
10+ // Initialize Supabase client with the service role key for admin access
11+ const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL
12+ const supabaseServiceKey = process . env . SUPABASE_SERVICE_ROLE_KEY
13+
14+ // Check if Supabase is configured
15+ let supabase : any = null
16+ if ( supabaseUrl && supabaseServiceKey ) {
17+ supabase = createClient ( supabaseUrl , supabaseServiceKey )
18+ } else {
19+ console . warn ( 'Supabase configuration is incomplete. Import dataset feature is disabled.' )
20+ }
1521
1622// Function to process and embed a single file's content
1723async function processAndEmbedFile ( content : string , embeddingPipeline : any ) {
@@ -80,8 +86,15 @@ async function importDataset(subset: string) {
8086}
8187
8288// The API Route Handler
83- export async function POST ( request : Request ) {
84- try {
89+ export async function POST ( request : Request ) {
90+ try {
91+ if ( ! supabase ) {
92+ return NextResponse . json (
93+ { error : 'Supabase is not configured. Import dataset feature is disabled.' } ,
94+ { status : 503 }
95+ )
96+ }
97+
8598 const { subset } = await request . json ( ) ;
8699
87100 if ( ! subset ) {
0 commit comments